From 62da7e435a901fa097524cb6a33f74b28575a5b1 Mon Sep 17 00:00:00 2001 From: zhanghc Date: Tue, 28 Feb 2006 07:07:55 +0000 Subject: [PATCH] BUG: 9461 FILES: utils/lfs.c 1, Add filesystem summary report into 'lfs df'; 2, Fixed a bug: Function: path2mnt Description: next getmntent call will destroy the memory pointed by mnt->mnt_dir(struct mntent) gotten by previous call. BUG: 5972 FILES: include/linux/obd.h; mds/handler.c; mds/mds_open.c; mds/lproc_mds.c 1, Add proc entry(/proc/fs/lustre/mds/mds1/atime_diff) to control atime updating interval in MDS OTHER: Add changelog of BUG9461 in ChangeLog Modified Files: Tag: b_release_1_4_6 ChangeLog include/linux/obd.h mds/handler.c mds/lproc_mds.c mds/mds_open.c utils/lfs.c --- lustre/ChangeLog | 7 ++++ lustre/include/linux/obd.h | 1 + lustre/mds/handler.c | 1 + lustre/mds/lproc_mds.c | 35 +++++++++++++++++++ lustre/mds/mds_open.c | 2 +- lustre/utils/lfs.c | 87 +++++++++++++++++++++++++++++++++++++++------- 6 files changed, 119 insertions(+), 14 deletions(-) diff --git a/lustre/ChangeLog b/lustre/ChangeLog index 441cb5c..169f2a7 100644 --- a/lustre/ChangeLog +++ b/lustre/ChangeLog @@ -12,6 +12,13 @@ Severity : enhancement +Bugzilla : 9461 +Description: Implement 'lfs df' to report actual free space on per-OST basis +Details : Add sub-command 'df' on 'lfs' to report the disk space usage of + MDS/OSDs. Usage: lfs df [-i][-h]. Command Options: '-i' to report + usage of objects; '-h' to report in human readable format. + +Severity : enhancement Bugzilla : 7981/8208 Description: Introduced Lustre Networking (LNET) Details : LNET is new networking infrastructure for Lustre, it includes diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h index b5b84c6..20d8fdb 100644 --- a/lustre/include/linux/obd.h +++ b/lustre/include/linux/obd.h @@ -378,6 +378,7 @@ struct mds_obd { __u64 mds_last_transno; __u64 mds_mount_count; __u64 mds_io_epoch; + unsigned long mds_atime_diff; struct semaphore mds_epoch_sem; struct ll_fid mds_rootfid; struct mds_server_data *mds_server_data; diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index db7d854..fa8ee80 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -1819,6 +1819,7 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf) spin_lock_init(&mds->mds_transno_lock); mds->mds_max_mdsize = sizeof(struct lov_mds_md); mds->mds_max_cookiesize = sizeof(struct llog_cookie); + mds->mds_atime_diff = MAX_ATIME_DIFF; sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid); obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER); diff --git a/lustre/mds/lproc_mds.c b/lustre/mds/lproc_mds.c index 137aa2c..92d5ae8 100644 --- a/lustre/mds/lproc_mds.c +++ b/lustre/mds/lproc_mds.c @@ -341,6 +341,40 @@ static int lprocfs_mds_wr_itune(struct file *file, const char *buffer, } #endif +static int lprocfs_wr_atime_diff(struct file *file, const char *buffer, + unsigned long count, void *data) +{ + struct obd_device *obd = data; + struct mds_obd *mds = &obd->u.mds; + char kernbuf[20], *end; + unsigned long diff = 0; + + if (count > (sizeof(kernbuf) - 1)) + return -EINVAL; + + if (copy_from_user(kernbuf, buffer, count)) + return -EFAULT; + + kernbuf[count] = '\0'; + + diff = simple_strtoul(kernbuf, &end, 0); + if (kernbuf == end) + return -EINVAL; + + mds->mds_atime_diff = diff; + return count; +} + +static int lprocfs_rd_atime_diff(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + struct obd_device *obd = data; + struct mds_obd *mds = &obd->u.mds; + + *eof = 1; + return snprintf(page, count, "%u\n", mds->mds_atime_diff); +} + struct lprocfs_vars lprocfs_mds_obd_vars[] = { { "uuid", lprocfs_rd_uuid, 0, 0 }, { "blocksize", lprocfs_rd_blksize, 0, 0 }, @@ -368,6 +402,7 @@ struct lprocfs_vars lprocfs_mds_obd_vars[] = { lprocfs_wr_group_upcall, 0}, { "group_flush", 0, lprocfs_wr_group_flush, 0}, { "group_info", 0, lprocfs_wr_group_info, 0 }, + { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 }, { 0 } }; diff --git a/lustre/mds/mds_open.c b/lustre/mds/mds_open.c index 29545a3..732112a 100644 --- a/lustre/mds/mds_open.c +++ b/lustre/mds/mds_open.c @@ -1294,7 +1294,7 @@ int mds_mfd_close(struct ptlrpc_request *req, int offset,struct obd_device *obd, * */ LTIME_S(iattr.ia_atime) = request_body->atime; if ((LTIME_S(iattr.ia_atime) > - LTIME_S(inode->i_atime) + MAX_ATIME_DIFF) || + LTIME_S(inode->i_atime) + mds->mds_atime_diff) || (iattr.ia_valid != 0 && LTIME_S(iattr.ia_atime) > LTIME_S(inode->i_atime))) iattr.ia_valid |= ATTR_ATIME; diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 4bdbcb6..7e5b73c 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -350,14 +350,14 @@ static int lfs_osts(int argc, char **argv) #define CSF "%9s" #define CDF "%9llu" #define HSF "%8s" -#define HDF "%8llu" +#define HDF "%6.1f" #define RSF "%5s" #define RDF "%5d" static int path2mnt(char *path, FILE *fp, char *mntdir, int dir_len) { char rpath[PATH_MAX] = {'\0'}; - struct mntent *mnt, out_mnt = {0}; + struct mntent *mnt; int rc, len, out_len = 0; if (!realpath(path, rpath)) { @@ -375,17 +375,17 @@ static int path2mnt(char *path, FILE *fp, char *mntdir, int dir_len) if (len > out_len && !strncmp(rpath, mnt->mnt_dir, len)) { out_len = len; - memcpy(&out_mnt, mnt, sizeof(out_mnt)); + memset(mntdir, 0, dir_len); + strncpy(mntdir, mnt->mnt_dir, dir_len); } } mnt = getmntent(fp); } - if (out_len > 0) { - strncpy(mntdir, out_mnt.mnt_dir, dir_len); + if (out_len > 0) return 0; - } - + + fprintf(stderr, "error: lfs df: %s isn't mounted on lustre\n", path); return -EINVAL; } @@ -427,21 +427,26 @@ static int showdf(char *mntdir, struct obd_statfs *stat, if (cooked) { int i; - i = COOK(total); + double total_d, used_d, avail_d; + + total_d = (double)total; + i = COOK(total_d); if (i > 0) - sprintf(tbuf, HDF"%c", total, suffix[i - 1]); + sprintf(tbuf, HDF"%c", total_d, suffix[i - 1]); else sprintf(tbuf, CDF, total); - i = COOK(used); + used_d = (double)used; + i = COOK(used_d); if (i > 0) - sprintf(ubuf, HDF"%c", used, suffix[i - 1]); + sprintf(ubuf, HDF"%c", used_d, suffix[i - 1]); else sprintf(ubuf, CDF, used); - i = COOK(avail); + avail_d = (double)avail; + i = COOK(avail_d); if (i > 0) - sprintf(abuf, HDF"%c", avail, suffix[i - 1]); + sprintf(abuf, HDF"%c", avail_d, suffix[i - 1]); else sprintf(abuf, CDF, avail); } else { @@ -479,6 +484,9 @@ static int mntdf(char *mntdir, int ishow, int cooked) struct obd_statfs stat_buf; struct obd_uuid uuid_buf; __u32 index; + __u64 avail_sum, used_sum, total_sum; + char tbuf[10], ubuf[10], abuf[10], rbuf[10]; + double ratio_sum; int rc; if (ishow) @@ -490,6 +498,7 @@ static int mntdf(char *mntdir, int ishow, int cooked) "UUID", "1K-blocks", "Used", "Available", "Use%", "Mounted on"); + avail_sum = total_sum = 0; for (index = 0; ; index++) { memset(&stat_buf, 0, sizeof(struct obd_statfs)); memset(&uuid_buf, 0, sizeof(struct obd_uuid)); @@ -508,6 +517,10 @@ static int mntdf(char *mntdir, int ishow, int cooked) uuid_buf.uuid, strerror(-rc), rc); return rc; } + if (!rc && ishow) { + avail_sum += stat_buf.os_ffree; + total_sum += stat_buf.os_files; + } } for (index = 0;;index++) { @@ -528,7 +541,55 @@ static int mntdf(char *mntdir, int ishow, int cooked) strerror(-rc), rc); return rc; } + if (!rc && !ishow) { + __u64 avail, total; + avail = stat_buf.os_bavail * stat_buf.os_bsize; + avail /= 1024; + total = stat_buf.os_blocks * stat_buf.os_bsize; + total /= 1024; + + avail_sum += avail; + total_sum += total; + } } + + used_sum = total_sum - avail_sum; + ratio_sum = (double)(total_sum - avail_sum) / (double)total_sum; + sprintf(rbuf, RDF, (int)(ratio_sum * 100)); + if (cooked) { + int i; + char *suffix = "KMGTPEZY"; + double total_sum_d, used_sum_d, avail_sum_d; + + total_sum_d = (double)total_sum; + i = COOK(total_sum_d); + if (i > 0) + sprintf(tbuf, HDF"%c", total_sum_d, suffix[i - 1]); + else + sprintf(tbuf, CDF, total_sum); + + used_sum_d = (double)used_sum; + i = COOK(used_sum_d); + if (i > 0) + sprintf(ubuf, HDF"%c", used_sum_d, suffix[i - 1]); + else + sprintf(ubuf, CDF, used_sum); + + avail_sum_d = (double)avail_sum; + i = COOK(avail_sum_d); + if (i > 0) + sprintf(abuf, HDF"%c", avail_sum_d, suffix[i - 1]); + else + sprintf(abuf, CDF, avail_sum); + } else { + sprintf(tbuf, CDF, total_sum); + sprintf(ubuf, CDF, used_sum); + sprintf(abuf, CDF, avail_sum); + } + + printf("\n"UUF" "CSF" "CSF" "CSF" "RSF" %-s\n", + "filesystem summary:", tbuf, ubuf, abuf, rbuf, mntdir); + return 0; } -- 1.8.3.1