Fix up "lfs df" code to not print an error message on each OBD.
run_test 103 "==============acl test ============="
test_104() {
- tfile=$DIR/lfs_df_test
- touch $tfile
+ touch $DIR/$tfile
lfs df || error "lfs df failed"
lfs df -ih || error "lfs df -ih failed"
lfs df $DIR || error "lfs df $DIR failed"
lfs df -ih $DIR || error "lfs df -ih $DIR failed"
- lfs df $tfile || error "lfs df $tfile failed"
- lfs df -ih $tfile || error "lfs df -ih $tfile failed"
+ lfs df $DIR/$tfile || error "lfs df $DIR/$tfile failed"
+ lfs df -ih $DIR/$tfile || error "lfs df -ih $DIR/$tfile failed"
OSC=`lctl dl | awk '/OSC.*MNT/ {print $4}' | head -n 1`
lctl --device %$OSC deactivate
lfs df || error "lfs df with deactivated OSC failed"
lctl --device %$OSC recover
lfs df || error "lfs df with reactivated OSC failed"
- rm -f $tfile
}
run_test 104 "lfs>df [-ih] [path] test ============"
"join two lustre files into one - join A, B, will be like cat B >> A & del B\n"
"usage: join <filename_A> <filename_B>\n"},
{"osts", lfs_osts, 0, "osts"},
- {"df", lfs_df, 0,
+ {"df", lfs_df, 0,
"report filesystem disk space usage or inodes usage"
"of each MDS/OSD.\n"
"Usage: df [-i] [-h] [path]"},
fp = setmntent(MOUNTED, "r");
if (fp == NULL) {
- fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
+ fprintf(stderr, "%s: setmntent(%s): %s:", argv[0], MOUNTED,
strerror (errno));
} else {
mnt = getmntent(fp);
rc = llapi_find(mnt->mnt_dir, obduuid, 0, 0, 0);
if (rc)
fprintf(stderr,
- "error: lfs osts failed on %s\n",
- mnt->mnt_dir);
+ "error: %s: failed on %s\n",
+ argv[0], mnt->mnt_dir);
}
mnt = getmntent(fp);
}
if (!realpath(path, rpath)) {
rc = -errno;
- fprintf(stderr, "ERROR: invalid path( %s )\n", path);
+ fprintf(stderr, "error: lfs df: invalid path '%s': %s\n",
+ path, strerror(-rc));
return rc;
}
-
+
len = 0;
mnt = getmntent(fp);
while (feof(fp) == 0 && ferror(fp) == 0) {
}
mnt = getmntent(fp);
}
-
+
if (out_len > 0) {
strncpy(mntdir, out_mnt.mnt_dir, dir_len);
return 0;
}
-
+
return -EINVAL;
}
static int showdf(char *mntdir, struct obd_statfs *stat,
- struct obd_uuid *uuid, int ishow, int cooked,
+ struct obd_uuid *uuid, int ishow, int cooked,
char *type, int index, int rc)
{
__u64 avail, used, total;
double ratio = 0;
int obd_type;
char *suffix = "KMGTPEZY";
- char tbuf[10], ubuf[10], abuf[10], rbuf[10];
-
+ char tbuf[10], ubuf[10], abuf[10], rbuf[10];
+
if (!uuid || !stat || !type)
return -EINVAL;
if (!strncmp(type, "MDT", 3)) {
} else if(!strncmp(type, "OST", 3)){
obd_type = 1;
} else {
- fprintf(stderr, "Invalid type( %s )\n", type);
+ fprintf(stderr, "error: lfs df: invalid type '%s'\n", type);
return -EINVAL;
}
-
+
if (rc == 0) {
if (ishow) {
avail = stat->os_ffree;
used = used * stat->os_bsize / 1024;
total = stat->os_blocks * stat->os_bsize / 1024;
}
-
+
if (total > 0)
ratio = (double)used / (double)total;
sprintf(ubuf, HDF"%c", used, suffix[i - 1]);
else
sprintf(ubuf, CDF, used);
-
+
i = COOK(avail);
if (i > 0)
sprintf(abuf, HDF"%c", avail, suffix[i - 1]);
sprintf(ubuf, CDF, used);
sprintf(abuf, CDF, avail);
}
-
+
sprintf(rbuf, RDF, (int)(ratio * 100));
- if (obd_type == 0)
+ if (obd_type == 0)
printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s[MDT:%d]\n",
(char *)uuid, tbuf, ubuf, abuf, rbuf,
mntdir, index);
printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s[OST:%d]\n",
(char *)uuid, tbuf, ubuf, abuf, rbuf,
mntdir, index);
-
+
return 0;
}
switch (rc) {
case -ENODATA:
- printf(UUF":%s\n", (char *)uuid, "inactive OST");
+ printf(UUF": inactive OST\n", (char *)uuid);
break;
default:
- printf(UUF":%s\n", (char *)uuid, strerror(-rc));
+ printf(UUF": %s\n", (char *)uuid, strerror(-rc));
break;
}
- return 0;
+ return 0;
}
static int mntdf(char *mntdir, int ishow, int cooked)
struct obd_uuid uuid_buf;
__u32 index;
int rc;
-
+
if (ishow)
printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n",
- "UUID", "Inodes", "IUsed", "IFree",
+ "UUID", "Inodes", "IUsed", "IFree",
"IUse%", "Mounted on");
else
printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n",
- "UUID", "1K-blocks", "Used", "Available",
+ "UUID", "1K-blocks", "Used", "Available",
"Use%", "Mounted on");
-
- for (index = 0;;index++) {
+
+ for (index = 0; ; index++) {
memset(&stat_buf, 0, sizeof(struct obd_statfs));
memset(&uuid_buf, 0, sizeof(struct obd_uuid));
rc = llapi_obd_statfs(mntdir, LL_STATFS_MDC, index,
&stat_buf, &uuid_buf);
if (rc == -ENODEV)
break;
-
+
if (rc == -ENOTCONN || rc == -ETIMEDOUT || rc == -EIO ||
rc == -ENODATA || rc == 0) {
showdf(mntdir, &stat_buf, &uuid_buf, ishow, cooked,
"MDT", index, rc);
} else {
- fprintf(stderr,
- "ERROR: llapi_obd_statfs failed( %s %d )\n",
- strerror(-rc), rc);
+ fprintf(stderr,
+ "error: llapi_obd_statfs(%s): %s (%d)\n",
+ uuid_buf.uuid, strerror(-rc), rc);
return rc;
}
}
&stat_buf, &uuid_buf);
if (rc == -ENODEV)
break;
-
+
if (rc == -ENOTCONN || rc == -ETIMEDOUT || rc == -EIO ||
rc == -ENODATA || rc == 0) {
showdf(mntdir, &stat_buf, &uuid_buf, ishow, cooked,
"OST", index, rc);
} else {
- fprintf(stderr,
- "ERROR: llapi_obd_statfs failed( %s %d)\n",
+ fprintf(stderr,
+ "error: llapi_obd_statfs failed: %s (%d)\n",
strerror(-rc), rc);
return rc;
}
}
return 0;
}
-
+
static int lfs_df(int argc, char **argv)
{
FILE *fp;
char mntdir[PATH_MAX] = {'\0'};
int ishow = 0, cooked = 0;
int c, rc = 0;
-
+
optind = 0;
while ((c = getopt(argc, argv, "ih")) != -1) {
switch (c) {
fp = setmntent(MOUNTED, "r");
if (fp == NULL) {
rc = -errno;
- fprintf(stderr, "ERROR: open %s failed( %s )\n",
- MOUNTED, strerror(errno));
+ fprintf(stderr, "error: %s: open %s failed( %s )\n",
+ argv[0], MOUNTED, strerror(errno));
return rc;
- }
+ }
if (path) {
rc = path2mnt(path, fp, mntdir, sizeof(mntdir));
if (rc) {
endmntent(fp);
return rc;
}
-
+
rc = mntdf(mntdir, ishow, cooked);
printf("\n");
endmntent(fp);
}
endmntent(fp);
}
-
+
return rc;
}
printf("%s\n%15s", mnt, "");
else
printf("%15s", mnt);
-
+
if (bover)
diff2str(dqb->dqb_btime, timebuf, now);
-
+
sprintf(numbuf[0], "%llu", toqb(dqb->dqb_curspace));
sprintf(numbuf[1], "%llu", dqb->dqb_bsoftlimit);
sprintf(numbuf[2], "%llu", dqb->dqb_bhardlimit);
printf(" %7s%c %6s %7s %7s",
numbuf[0], bover ? '*' : ' ', numbuf[1],
numbuf[2], bover > 1 ? timebuf : "");
-
+
if (iover)
diff2str(dqb->dqb_itime, timebuf, now);
-
+
sprintf(numbuf[0], "%llu", dqb->dqb_curinodes);
sprintf(numbuf[1], "%llu", dqb->dqb_isoftlimit);
sprintf(numbuf[2], "%llu", dqb->dqb_ihardlimit);
{
param->lumlen = lov_mds_md_size(MAX_LOV_UUID_COUNT);
if ((param->lmd = malloc(sizeof(lstat_t) + param->lumlen)) == NULL) {
- err_msg("unable to allocate %d bytes of memory for ioctl",
+ err_msg("error: allocation of %d bytes for ioctl",
sizeof(lstat_t) + param->lumlen);
return ENOMEM;
}
obdgens = malloc(size_round(max_ost_count * sizeof(*obdgens)));
if (!obdgens) {
- err_msg("no memory for %d generation #'s", max_ost_count);
+ err_msg("error: %d generation #'s", max_ost_count);
return(-ENOMEM);
}
desc.ld_tgt_count = max_ost_count;
if (obd_ioctl_pack(&data, &buf, OBD_MAX_IOCTL_BUFFER)) {
- fprintf(stderr, "internal buffer error packing\n");
+ fprintf(stderr, "error: %s: internal packing error\n",
+ __FUNCTION__);
rc = EINVAL;
goto out;
}
rc = ioctl(fd, OBD_IOC_LOV_GET_CONFIG, buf);
if (rc) {
- err_msg("error getting LOV config");
+ err_msg("error: %s: getting LOV config", __FUNCTION__);
rc = errno;
goto out;
}
if (obd_ioctl_unpack(&data, buf, OBD_MAX_IOCTL_BUFFER)) {
- fprintf(stderr, "invalid reply from ioctl");
- rc = EINVAL;
+ rc = errno = EINVAL;
+ err_msg("error: %s: internal ioctl unpack", __FUNCTION__);
goto out;
}
/* Get the lov name */
rc = ioctl(dirfd(dir), OBD_IOC_GETNAME, (void *)uuid);
if (rc) {
- fprintf(stderr, "error: can't get lov name: %s\n",
- strerror(rc = errno));
+ rc = errno;
+ if (rc == -ENOTTY)
+ fprintf(stderr, "error: %s does not appear to be in "
+ "a Lustre filesystem\n", dname);
+ else
+ err_msg("error: can't get lov name: %s");
return rc;
}
uuid);
fp = fopen(buf, "r");
if (fp == NULL) {
- fprintf(stderr, "error: %s opening %s\n",
- strerror(rc = errno), buf);
+ err_msg("error: opening '%s'", buf);
return rc;
}
fclose(fp);
if (param->obduuid && (param->obdindex == OBD_NOT_FOUND)) {
- printf("unknown obduuid: %s\n", param->obduuid->uuid);
- rc = EINVAL;
+ fprintf(stderr, "error: %s: unknown obduuid: %s\n",
+ __FUNCTION__, param->obduuid->uuid);
+ rc = EINVAL;
}
return (rc);
if (rc) {
if (errno == ENODATA) {
if (!param->obduuid && !param->quiet)
- fprintf(stderr,
- "%s/%s has no stripe info\n",
+ fprintf(stderr, "%s/%s has no stripe info\n",
dname, fname);
rc = 0;
- } else if (errno == EISDIR) {
- fprintf(stderr, "process_file on directory %s/%s!\n",
+ } else if (errno == ENOTTY) {
+ fprintf(stderr, "error: %s/%s is not a Lustre fs?\n",
dname, fname);
+ } else if (errno == EISDIR) {
+ err_msg("error: %s: directory %s/%s",
+ __FUNCTION__, dname, fname);
/* add fname to directory list; */
rc = errno;
} else {
- err_msg("IOC_MDC_GETSTRIPE ioctl failed for '%s/%s'",
+ err_msg("error: IOC_MDC_GETSTRIPE failed for '%s/%s'",
dname, fname);
rc = errno;
}
if (rc) {
if (errno == ENODATA) {
if (!param->obduuid && param->verbose)
- printf("%s/%s has no stripe info\n", dname, "");
+ printf("%s has no stripe info\n", dname);
rc = 0;
+ } else if (errno == ENOTTY) {
+ fprintf(stderr, "error: %s: %s not on a Lustre fs?\n",
+ __FUNCTION__, dname);
} else {
- err_msg("GETSTRIPE failed for %s", dname);
+ err_msg("error: %s: LL_IOC_LOV_GETSTRIPE failed for %s",
+ __FUNCTION__, dname);
}
} else {
llapi_lov_dump_user_lmm(param, dname, "");
switch (dirp->d_type) {
case DT_UNKNOWN:
- err_msg("\"%s\" is UNKNOWN type %d", dirp->d_name,
- dirp->d_type);
+ fprintf(stderr, "error: %s: '%s' is UNKNOWN type %d",
+ __FUNCTION__, dirp->d_name, dirp->d_type);
/* If we cared we could stat the file to determine
* type and continue on here, but we don't since we
* know d_type should be valid for lustre and this
strcat(path, dirp->d_name);
subdir = opendir(path);
if (subdir == NULL) {
- err_msg("\"%.40s\" opendir failed", path);
+ err_msg("error: %s: opendir '%.40s'",
+ __FUNCTION__, path);
return errno;
}
rc = process_dir(subdir, path, param);
fname = strrchr(path, '/');
if (fname != NULL && fname[1] == '\0') {
/* Trailing '/', it must be a dir */
- *fname = '\0';
+ if (strlen(path) > 1)
+ *fname = '\0';
+
dir = opendir(path);
if (dir == NULL) {
- err_msg("\"%.40s\" opendir failed", path);
+ err_msg("error: %s: '%.40s' opendir",__FUNCTION__,path);
rc = errno;
} else {
rc = process_dir(dir, path, param);
*fname = '\0';
fname++;
dname = path;
+ if (dname[0] == '\0')
+ dname = "/";
}
dir = opendir(dname);
if (dir == NULL) {
- err_msg("\"%.40s\" opendir failed", dname);
+ err_msg("error: %s: '%.40s' open failed",
+ __FUNCTION__, dname);
rc = errno;
} else {
if (!param->got_uuids)
data.ioc_plen2 = sizeof(struct obd_uuid);
if (obd_ioctl_pack(&data, &rawbuf, sizeof(raw))) {
- rc = -EINVAL;
- fprintf(stderr, "error packing ioctl data: %s\n", strerror(rc));
+ fprintf(stderr, "llapi_obd_statfs: error packing ioctl data\n");
return rc;
}
if (fd < 0) {
rc = -errno;
- fprintf(stderr,"error opening '%s': %s\n",path,strerror(errno));
+ err_msg("error: %s: opening '%s'", __FUNCTION__, path);
return rc;
}
- rc = ioctl(fd, LL_IOC_OBD_STATFS, (void*)rawbuf);
- if (rc) {
+ rc = ioctl(fd, LL_IOC_OBD_STATFS, (void *)rawbuf);
+ if (rc)
rc = -errno;
- fprintf(stderr, "error statfs '%s': %s\n", uuid_buf->uuid,
- strerror(errno));
- }
close(fd);
return rc;
rc = llapi_ping(obd_type_name, obd_name);
if (rc) {
- fprintf(stderr, "error: check %s: %s\n",
- obd_name, strerror(rc = errno));
+ err_msg("error: check '%s'", obd_name);
} else {
printf("%s active.\n", obd_name);
}
* invoke syscall directly. */
rc = syscall(SYS_chown, pathname, st->st_uid, st->st_gid);
if (rc)
- fprintf(stderr, "chown %s (%u,%u) fail: %s\n",
- pathname, st->st_uid, st->st_gid, strerror(errno));
+ err_msg("error: chown %s (%u,%u)",
+ pathname, st->st_uid, st->st_gid);
return rc;
}
}
int
-print_options(struct lustre_mount_data *lmd, const char *options)
+print_options(FILE *out, struct lustre_mount_data *lmd, const char *options)
{
int i;
for (i = 0; i < lmd->lmd_nid_count; i++) {
- printf("mds nid %d: %s\n", i,
- libcfs_nid2str(lmd->lmd_nid[i]));
+ fprintf(out, "mds nid %d: %s\n", i,
+ libcfs_nid2str(lmd->lmd_nid[i]));
}
- printf("mds name: %s\n", lmd->lmd_mds);
- printf("profile: %s\n", lmd->lmd_profile);
- printf("options: %s\n", options);
+ fprintf(out, "mds name: %s\n", lmd->lmd_mds);
+ fprintf(out, "profile: %s\n", lmd->lmd_profile);
+ fprintf(out, "options: %s\n", options);
return 0;
}
int i = 0;
char *tmp = 0;
lnet_nid_t nid;
-
+
while ((tmp = strsep(&nids, ",:"))) {
nid = libcfs_str2nid(tmp);
if (nid == LNET_NID_ANY) {
- fprintf(stderr, "%s: Can't parse NID '%s'\n",
+ fprintf(stderr, "%s: Can't parse NID '%s'\n",
progname, tmp);
continue;
}
lmd->lmd_nid[lmd->lmd_nid_count++] = nid;
if (lmd->lmd_nid_count >= MAX_FAILOVER_NIDS) {
- fprintf(stderr, "%s: Too many: ignoring nids after %s\n",
+ fprintf(stderr, "%s: Too many target NIDs: "
+ "ignoring nids after %s\n",
progname, tmp);
break;
}
}
if (verbose)
- print_options(&lmd, options);
+ print_options(stdout, &lmd, options);
rc = access(target, F_OK);
if (rc) {
if (rc) {
fprintf(stderr, "%s: mount(%s, %s) failed: %s\n", progname,
source, target, strerror(errno));
+ print_options(stderr, &lmd, options);
if (errno == ENODEV)
fprintf(stderr, "Are the lustre modules loaded?\n"
"Check /etc/modules.conf and /proc/filesystems\n");