From e15dd6d0c94e47eb5dda96d09884cd01c264c326 Mon Sep 17 00:00:00 2001 From: adilger Date: Sat, 18 Feb 2006 00:49:07 +0000 Subject: [PATCH] Branch b_release_1_4_6 Fix up "lfs df" code to not print an error message on each OBD. --- lustre/tests/sanity.sh | 8 ++-- lustre/utils/lfs.c | 89 +++++++++++++++++++++++---------------------- lustre/utils/liblustreapi.c | 86 ++++++++++++++++++++++++------------------- lustre/utils/llmount.c | 22 ++++++----- 4 files changed, 109 insertions(+), 96 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index b2b01b1..e573857 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -2912,21 +2912,19 @@ test_103 () { 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 ============" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 6bfe989..4bdbcb6 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -100,7 +100,7 @@ command_t cmdlist[] = { "join two lustre files into one - join A, B, will be like cat B >> A & del B\n" "usage: join \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]"}, @@ -317,7 +317,7 @@ static int lfs_osts(int argc, char **argv) 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); @@ -326,8 +326,8 @@ static int lfs_osts(int argc, char **argv) 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); } @@ -362,10 +362,11 @@ static int path2mnt(char *path, FILE *fp, char *mntdir, int dir_len) 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) { @@ -379,25 +380,25 @@ static int path2mnt(char *path, FILE *fp, char *mntdir, int dir_len) } 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)) { @@ -405,10 +406,10 @@ static int showdf(char *mntdir, struct obd_statfs *stat, } 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; @@ -420,7 +421,7 @@ static int showdf(char *mntdir, struct obd_statfs *stat, used = used * stat->os_bsize / 1024; total = stat->os_blocks * stat->os_bsize / 1024; } - + if (total > 0) ratio = (double)used / (double)total; @@ -437,7 +438,7 @@ static int showdf(char *mntdir, struct obd_statfs *stat, 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]); @@ -448,9 +449,9 @@ static int showdf(char *mntdir, struct obd_statfs *stat, 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); @@ -458,19 +459,19 @@ static int showdf(char *mntdir, struct obd_statfs *stat, 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) @@ -479,32 +480,32 @@ 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; } } @@ -516,21 +517,21 @@ static int mntdf(char *mntdir, int ishow, int cooked) &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; @@ -539,7 +540,7 @@ static int lfs_df(int argc, char **argv) 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) { @@ -559,17 +560,17 @@ static int lfs_df(int argc, char **argv) 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); @@ -586,7 +587,7 @@ static int lfs_df(int argc, char **argv) } endmntent(fp); } - + return rc; } @@ -1165,20 +1166,20 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int ost_only) 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); diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 56c371a..5c4c68a 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -174,7 +174,7 @@ static int prepare_find(struct find_param *param) { 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; } @@ -209,7 +209,7 @@ int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count) 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); } @@ -223,21 +223,22 @@ int llapi_lov_get_uuids(int fd, struct obd_uuid *uuidp, int *ost_count) 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; } @@ -261,8 +262,12 @@ static int setup_obd_uuids(DIR *dir, char *dname, struct find_param *param) /* 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; } @@ -271,8 +276,7 @@ static int setup_obd_uuids(DIR *dir, char *dname, struct find_param *param) 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; } @@ -298,8 +302,9 @@ static int setup_obd_uuids(DIR *dir, char *dname, struct find_param *param) 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); @@ -505,17 +510,19 @@ static int find_process_file(DIR *dir, char *dname, char *fname, 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; } @@ -567,10 +574,14 @@ static int process_dir(DIR *dir, char *dname, struct find_param *param) 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, ""); @@ -586,8 +597,8 @@ static int process_dir(DIR *dir, char *dname, struct find_param *param) 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 @@ -601,7 +612,8 @@ static int process_dir(DIR *dir, char *dname, struct find_param *param) 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); @@ -627,10 +639,12 @@ static int process_path(char *path, struct find_param *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); @@ -649,10 +663,13 @@ static int process_path(char *path, struct find_param *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) @@ -716,8 +733,7 @@ int llapi_obd_statfs(char *path, __u32 type, __u32 index, 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; } @@ -727,15 +743,12 @@ int llapi_obd_statfs(char *path, __u32 type, __u32 index, 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; @@ -822,8 +835,7 @@ static void do_target_check(char *obd_type_name, char *obd_name, 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); } @@ -973,8 +985,8 @@ static int quotachown_process_file(DIR *dir, char *dname, char *fname, * 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; } diff --git a/lustre/utils/llmount.c b/lustre/utils/llmount.c index ae4beb3..fc75f21 100644 --- a/lustre/utils/llmount.c +++ b/lustre/utils/llmount.c @@ -131,16 +131,16 @@ init_options(struct lustre_mount_data *lmd) } 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; } @@ -150,17 +150,18 @@ static int parse_nids(struct lustre_mount_data *lmd, char *nids) 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; } @@ -417,7 +418,7 @@ int main(int argc, char *const argv[]) } if (verbose) - print_options(&lmd, options); + print_options(stdout, &lmd, options); rc = access(target, F_OK); if (rc) { @@ -432,6 +433,7 @@ int main(int argc, char *const argv[]) 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"); -- 1.8.3.1