Whamcloud - gitweb
BUG: 9461
authorzhanghc <zhanghc>
Tue, 28 Feb 2006 07:07:55 +0000 (07:07 +0000)
committerzhanghc <zhanghc>
Tue, 28 Feb 2006 07:07:55 +0000 (07:07 +0000)
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
lustre/include/linux/obd.h
lustre/mds/handler.c
lustre/mds/lproc_mds.c
lustre/mds/mds_open.c
lustre/utils/lfs.c

index 441cb5c..169f2a7 100644 (file)
 
 
 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
index b5b84c6..20d8fdb 100644 (file)
@@ -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;
index db7d854..fa8ee80 100644 (file)
@@ -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);
index 137aa2c..92d5ae8 100644 (file)
@@ -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 }
 };
 
index 29545a3..732112a 100644 (file)
@@ -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;
index 4bdbcb6..7e5b73c 100644 (file)
@@ -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;
 }