fssnapsup.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2000-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Routines to support fssnap subcommand of switchout. See switchout.c for
* the real fssnap command.
*/
#include <stdio.h>
#include <kstat.h>
#include <libintl.h>
#include <sys/fssnap_if.h>
#include <string.h>
#include <errno.h>
static void fssnap_display_info(ulong_t, int *, int);
#define MAX_INFO_DESCRIPTORS (10)
static char *infosubopts[] = {
#define INFO_SNAPSHOT (0)
"snapnumber",
#define INFO_BLKDEV (1)
"blockdevname",
#define INFO_CHARDEV (2)
"rawdevname",
#define INFO_MNTPT (3)
"mountpoint",
#define INFO_STATE (4)
"state",
#define INFO_BACKPATH (5)
"backing-store",
#define INFO_BACKSIZE (6)
"backing-store-len",
#define INFO_MAXSIZE (7)
"maxsize",
#define INFO_CREATETIME (8)
"createtime",
#define INFO_CHUNKSIZE (9)
"chunksize",
};
/* labels are truncated to this many characters when displayed */
#define MAX_LABEL_LEN (30)
/*
* fssnap_show_status() - display file system snapshot status
*
* displays snapshot information. If mountpoint is set, information is
* only displayed for the snapshot (if one exists) on that file system.
* If mountpoint is NULL, information is displayed for all snapshots.
*
* If opts is defined, it is parsed as a list of suboptions (via
* getsubopt()) corresponding to the options list defined above. These
* options determine what data should be displayed and in what order. An
* option may appear more than once.
*
* The labels parameter is a boolean that determines whether labels
* (internationalized) are displayed before each data element. If it is
* 0, labels are not displayed, otherwise they are. The labels parameter
* is ignored if brief is nonzero.
*
* The brief parameter is also a boolean and specifies a mode where only
* the snapshot number and mount point are displayed, regardless of the
* value of labels. This could be used for listing all active snapshots.
*
* Based on these parameters, an order list is created that tells
* fssnap_display_info() what info to display and in what order.
*
* Note that when labels are not specified, the assumption is that the
* output is made for script readable consumption. For this reason, text
* is not I18N'd and numbers are left as bytes instead of converted to KB.
*/
void
{
char *suboptions, *v, *n;
int i = 0;
kslib = kstat_open();
/*
* First check and see if they gave us a mount point or a device
*/
if (mountpoint) {
n++;
if (isdigit(*n)) {
errno = 0;
if (errno == 0) {
usenum++;
}
}
}
}
if (opts) {
i = 0;
gettext("cannot allocate order list.\n"));
return;
}
suboptions = opts;
while (*suboptions != '\0') {
/*
* -1 means invalid option, MAX_INFO_DESCRIPTORS is
* the end.
*/
if (i >= orderlen) {
sizeof (int) * (orderlen *= 2));
gettext("cannot reallocate order "
"list.\n"));
return;
}
}
}
order[i] = MAX_INFO_DESCRIPTORS;
} else {
gettext("cannot allocate order list.\n"));
return;
}
for (i = 0; i <= MAX_INFO_DESCRIPTORS; i++)
order[i] = i;
}
/* check if fssnap module is loaded */
return;
}
/* Loop up to the maximum number of snapshots */
/* if this snapshot is not allocated, skip to the next */
continue;
continue;
if (mountpoint != NULL) {
continue;
}
if (brief)
else
}
}
static void
{
int i;
/* load num kstat */
kslib = kstat_open();
return;
return;
for (i = 0; order[i] != MAX_INFO_DESCRIPTORS; i++) {
switch (order[i]) {
case INFO_SNAPSHOT:
if (labels)
else
break;
case INFO_BLKDEV:
if (labels)
snapnum);
else
snapnum);
break;
case INFO_CHARDEV:
if (labels)
snapnum);
else
snapnum);
break;
case INFO_MNTPT:
gettext("cannot read mount point kstat\n"));
continue;
}
continue;
}
if (labels)
gettext("Mount point"),
else
break;
case INFO_STATE:
/* state */
gettext("cannot read state kstat\n"));
continue;
}
if (labels) {
gettext("Device state"));
break;
break;
break;
break;
break;
}
} else {
case 0: printf("creating\n");
break;
break;
break;
break;
default: printf("unknown\n");
break;
}
}
break;
case INFO_BACKPATH:
/* backing file kstat */
gettext("cannot read backing file name "
"kstat from kernel\n"));
continue;
}
if (labels)
gettext("Backing store path"),
else
break;
case INFO_BACKSIZE:
gettext("cannot read backing file size "
"kstat from kernel\n"));
continue;
}
if (labels)
gettext("Backing store size"),
size / 1024LL);
else
break;
case INFO_MAXSIZE:
gettext("cannot read backing file maxsize "
"kstat from kernel\n"));
continue;
}
if (labels) {
gettext("Maximum backing store size"));
else
printf("%llu KB\n",
} else {
}
break;
case INFO_CREATETIME:
{
/* snapshot creation time */
char buf[256];
char *p;
gettext("cannot read snapshot create time "
"kstat from kernel\n"));
continue;
}
if (labels) {
gettext("Snapshot create time"));
/* get the localized time */
"%c\n", tm) == 0)
/* Wouldn't fit in buf, fall back */
else
p = buf;
} else {
/*
* for script-readable options we want
* the locale-independent time only.
*/
}
/* p should already have a \n appended */
printf("%s", p);
break;
}
case INFO_CHUNKSIZE:
gettext("cannot read chunksize kstat\n"));
continue;
}
if (labels)
gettext("Copy-on-write granularity"),
else
break;
case -1:
/*
* Print a place holder for unknown options so that
* the user can determine which option was not
* understood and the number outputted is the same
* number they requested.
*/
printf("?\n");
break;
default:
break;
}
}
}