Whamcloud - gitweb
Change internal statfs calls to pass struct obd_statfs as a parameter
authoradilger <adilger>
Sat, 7 Sep 2002 07:52:46 +0000 (07:52 +0000)
committeradilger <adilger>
Sat, 7 Sep 2002 07:52:46 +0000 (07:52 +0000)
instead of the Linux struct statfs.  This allows us to have 64-bit
clean statfs data all the way to the VFS, and avoids problems like
block count overflows in intermediate math in LOV and such.

We still need to resolve the VFS interface to statfs, as it limits the
output to 16TB on 32-bit platforms (4G x 4kb blocks).  The likely
answer is to shift the blocksize up, and the blocks counts down until
we fit in under 4G total blocks.  For MCR this will be around a blocksize
of 64kB which is nice to specify as the block size anyways.

13 files changed:
lustre/include/linux/lustre_lib.h
lustre/include/linux/lustre_mds.h
lustre/include/linux/obd.h
lustre/include/linux/obd_class.h
lustre/lib/ll_pack.c
lustre/llite/super.c
lustre/lov/lov_obd.c
lustre/mdc/mdc_request.c
lustre/mds/handler.c
lustre/obdfilter/Makefile.am
lustre/obdfilter/filter.c
lustre/osc/osc_request.c
lustre/ost/ost_handler.c

index c56d13e..3d0e5f1 100644 (file)
@@ -129,8 +129,14 @@ static inline void ldlm_object2handle(void *object, struct lustre_handle *handle
 
 struct obd_statfs;
 struct statfs;
-void obd_statfs_pack(struct obd_statfs *osfs, struct statfs *sfs);
-void obd_statfs_unpack(struct obd_statfs *osfs, struct statfs *sfs);
+void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs);
+void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs);
+void obd_statfs_pack(struct obd_statfs *tgt, struct obd_statfs *src);
+static inline void
+obd_statfs_unpack(struct obd_statfs *tgt, struct obd_statfs *src)
+{
+        obd_statfs_pack(tgt, src);
+}
 
 #include <linux/portals_lib.h>
 
index b494315..d979c07 100644 (file)
@@ -158,8 +158,8 @@ int mdc_getstatus(struct lustre_handle *conn,
 int mdc_getattr(struct lustre_handle *conn,
                 obd_id ino, int type, unsigned long valid, size_t ea_size,
                 struct ptlrpc_request **request);
-int mdc_statfs(struct lustre_handle *conn,
-               struct statfs *sfs, struct ptlrpc_request **request);
+int mdc_statfs(struct lustre_handle *conn, struct obd_statfs *osfs,
+               struct ptlrpc_request **request);
 int mdc_setattr(struct lustre_handle *conn,
                 struct inode *, struct iattr *iattr, struct ptlrpc_request **);
 int mdc_open(struct lustre_handle *conn, obd_id ino, int type, int flags,
index 4df2b5e..93cc6a3 100644 (file)
@@ -263,7 +263,7 @@ struct obd_ops {
         int (*o_disconnect)(struct lustre_handle *conn);
 
 
-        int (*o_statfs)(struct lustre_handle *conn, struct statfs *statfs);
+        int (*o_statfs)(struct lustre_handle *conn, struct obd_statfs *osfs);
         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
                              obd_id *ids);
         int (*o_create)(struct lustre_handle *conn,  struct obdo *oa,
index 08a9415..b880f8a 100644 (file)
@@ -288,14 +288,14 @@ static inline int obd_disconnect(struct lustre_handle *conn)
         RETURN(rc);
 }
 
-static inline int obd_statfs(struct lustre_handle *conn, struct statfs *buf)
+static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
 {
         int rc;
         struct obd_export *export;
         OBD_CHECK_SETUP(conn, export);
         OBD_CHECK_OP(export->exp_obd,statfs);
 
-        rc = OBP(export->exp_obd, statfs)(conn, buf);
+        rc = OBP(export->exp_obd, statfs)(conn, osfs);
         RETURN(rc);
 }
 
index 599818e..a71f564 100644 (file)
 #include <linux/lustre_net.h>
 #include <linux/obd_support.h>
 
-void obd_statfs_pack(struct obd_statfs *osfs, struct statfs *sfs)
+void obd_statfs_pack(struct obd_statfs *tgt, struct obd_statfs *src)
 {
-        if (osfs == NULL || sfs == NULL)
-                LBUG();
+        tgt->os_type = HTON__u64(src->os_type);
+        tgt->os_blocks = HTON__u64(src->os_blocks);
+        tgt->os_bfree = HTON__u64(src->os_bfree);
+        tgt->os_bavail = HTON__u64(src->os_bavail);
+        tgt->os_files = HTON__u64(src->os_files);
+        tgt->os_ffree = HTON__u64(src->os_ffree);
+        tgt->os_bsize = HTON__u32(src->os_bsize);
+        tgt->os_namelen = HTON__u32(src->os_namelen);
+}
+
+#define obd_statfs_unpack(tgt, src) obd_statfs_pack(tgt, src)
 
-        osfs->os_type = HTON__u64(sfs->f_type);
-        osfs->os_blocks = HTON__u64(sfs->f_blocks);
-        osfs->os_bfree = HTON__u64(sfs->f_bfree);
-        osfs->os_bavail = HTON__u64(sfs->f_bavail);
-        osfs->os_files = HTON__u64(sfs->f_files);
-        osfs->os_ffree = HTON__u64(sfs->f_ffree);
-        osfs->os_bsize = HTON__u32(sfs->f_bsize);
-        osfs->os_namelen = HTON__u32(sfs->f_namelen);
+void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs)
+{
+        osfs->os_type = sfs->f_type;
+        osfs->os_blocks = sfs->f_blocks;
+        osfs->os_bfree = sfs->f_bfree;
+        osfs->os_bavail = sfs->f_bavail;
+        osfs->os_files = sfs->f_files;
+        osfs->os_ffree = sfs->f_ffree;
+        osfs->os_bsize = sfs->f_bsize;
+        osfs->os_namelen = sfs->f_namelen;
 }
 
 #if BITS_PER_LONG > 32
@@ -59,18 +70,15 @@ static inline long statfs_max(__u64 val)
  * fields as an unsigned long, which is helps us a bit, and it also
  * appears to do 64-bit math for at least some of the computations.
  */
-void obd_statfs_unpack(struct obd_statfs *osfs, struct statfs *sfs)
+void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs)
 {
-        if (osfs == NULL || sfs == NULL)
-                LBUG();
-
-        sfs->f_type = NTOH__u64(osfs->os_type);
-        sfs->f_blocks = statfs_max(NTOH__u64(osfs->os_blocks));
-        sfs->f_bfree = statfs_max(NTOH__u64(osfs->os_bfree));
-        sfs->f_bavail = statfs_max(NTOH__u64(osfs->os_bavail));
-        sfs->f_files = statfs_max(NTOH__u64(osfs->os_files));
-        sfs->f_ffree = statfs_max(NTOH__u64(osfs->os_ffree));
-        sfs->f_bsize = NTOH__u32(osfs->os_bsize);
-        sfs->f_namelen = NTOH__u32(osfs->os_namelen);
+        sfs->f_type = osfs->os_type;
+        sfs->f_blocks = statfs_max(osfs->os_blocks);
+        sfs->f_bfree = statfs_max(osfs->os_bfree);
+        sfs->f_bavail = statfs_max(osfs->os_bavail);
+        sfs->f_files = statfs_max(osfs->os_files);
+        sfs->f_ffree = statfs_max(osfs->os_ffree);
+        sfs->f_bsize = osfs->os_bsize;
+        sfs->f_namelen = osfs->os_namelen;
 }
 
index 687b199..811b77d 100644 (file)
@@ -87,7 +87,7 @@ static struct super_block * ll_read_super(struct super_block *sb,
         char *mdc = NULL;
         int err;
         struct ll_fid rootfid;
-        struct statfs sfs;
+        struct obd_statfs osfs;
         __u64 last_committed;
         __u64 last_xid;
         struct ptlrpc_request *request = NULL;
@@ -157,14 +157,14 @@ static struct super_block * ll_read_super(struct super_block *sb,
         CDEBUG(D_SUPER, "rootfid %Ld\n", (unsigned long long)rootfid.id);
         sbi->ll_rootino = rootfid.id;
 
-        memset(&sfs, 0, sizeof(sfs));
+        memset(&osfs, 0, sizeof(osfs));
         request = NULL;
-        err = mdc_statfs(&sbi->ll_mdc_conn, &sfs, &request);
+        err = mdc_statfs(&sbi->ll_mdc_conn, &osfs, &request);
         ptlrpc_req_finished(request);
-        sb->s_blocksize = sfs.f_bsize;
-        sb->s_blocksize_bits = log2(sfs.f_bsize);
+        sb->s_blocksize = osfs.os_bsize;
+        sb->s_blocksize_bits = log2(osfs.os_bsize);
         sb->s_magic = LL_SUPER_MAGIC;
-        sb->s_maxbytes = (1ULL << (32 + 9)) - sfs.f_bsize;
+        sb->s_maxbytes = (1ULL << (32 + 9)) - osfs.os_bsize;
 
         sb->s_op = &ll_super_operations;
 
@@ -356,31 +356,36 @@ static int ll_statfs(struct super_block *sb, struct statfs *sfs)
 {
         struct ptlrpc_request *request = NULL;
         struct ll_sb_info *sbi = ll_s2sbi(sb);
+        struct obd_statfs osfs;
         int rc;
         ENTRY;
 
         memset(sfs, 0, sizeof(*sfs));
-        rc = mdc_statfs(&sbi->ll_mdc_conn, sfs, &request);
+        rc = mdc_statfs(&sbi->ll_mdc_conn, &osfs, &request);
+        statfs_unpack(sfs, &osfs);
         ptlrpc_req_finished(request);
         if (rc)
-                CERROR("obd_statfs fails: rc = %d\n", rc);
+                CERROR("mdc_statfs fails: rc = %d\n", rc);
         else
-                CDEBUG(D_SUPER, "statfs shows blocks %lu/%lu objects %lu/%lu\n",
-                       sfs->f_bavail, sfs->f_blocks, sfs->f_ffree,sfs->f_files);
+                CDEBUG(D_SUPER, "mdc_statfs shows blocks "LPU64"/"LPU64
+                       " objects "LPU64"/"LPU64"\n",
+                       osfs.os_bavail, osfs.os_blocks,
+                       osfs.os_ffree, osfs.os_files);
 
         /* temporary until mds_statfs returns statfs info for all OSTs */
         if (!rc) {
                 struct statfs obd_sfs;
 
-                rc = obd_statfs(&sbi->ll_osc_conn, &obd_sfs);
+                rc = obd_statfs(&sbi->ll_osc_conn, &osfs);
+                statfs_unpack(&obd_sfs, &osfs);
                 if (rc) {
                         CERROR("obd_statfs fails: rc = %d\n", rc);
                         GOTO(out, rc);
                 }
-                CDEBUG(D_SUPER, "obd_statfs returns blocks %lu/%lu, "
-                       "objects %lu/%lu\n",
-                       obd_sfs.f_bavail, obd_sfs.f_blocks,
-                       obd_sfs.f_ffree, obd_sfs.f_files);
+                CDEBUG(D_SUPER, "obd_statfs shows blocks "LPU64"/"LPU64
+                       " objects "LPU64"/"LPU64"\n",
+                       osfs.os_bavail, osfs.os_blocks,
+                       osfs.os_ffree, osfs.os_files);
 
                 sfs->f_bfree = obd_sfs.f_bfree;
                 sfs->f_bavail = obd_sfs.f_bavail;
index bba10b8..f6e9949 100644 (file)
@@ -738,11 +738,11 @@ static int lov_cancel(struct lustre_handle *conn, struct lov_stripe_md *md,
         RETURN(rc);
 }
 
-static int lov_statfs(struct lustre_handle *conn, struct statfs *sfs)
+static int lov_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
 {
         struct obd_export *export = class_conn2export(conn);
         struct lov_obd *lov;
-        struct statfs lov_sfs;
+        struct obd_statfs lov_sfs;
         int set = 0;
         int rc = 0;
         int i;
@@ -766,12 +766,12 @@ static int lov_statfs(struct lustre_handle *conn, struct statfs *sfs)
                         continue; /* XXX or break? - probably OK to continue */
                 }
                 if (!set) {
-                        memcpy(sfs, &lov_sfs, sizeof(lov_sfs));
+                        memcpy(osfs, &lov_sfs, sizeof(lov_sfs));
                         set = 1;
                 } else {
-                        sfs->f_bfree += lov_sfs.f_bfree;
-                        sfs->f_bavail += lov_sfs.f_bavail;
-                        sfs->f_blocks += lov_sfs.f_blocks;
+                        osfs->os_bfree += lov_sfs.os_bfree;
+                        osfs->os_bavail += lov_sfs.os_bavail;
+                        osfs->os_blocks += lov_sfs.os_blocks;
                         /* XXX not sure about this one - depends on policy.
                          *   - could be minimum if we always stripe on all OBDs
                          *     (but that would be wrong for any other policy,
index ea5e21c..c881645 100644 (file)
@@ -468,10 +468,9 @@ int mdc_readpage(struct lustre_handle *conn, obd_id ino, int type, __u64 offset,
         return rc;
 }
 
-int mdc_statfs(struct lustre_handle *conn, struct statfs *sfs,
+int mdc_statfs(struct lustre_handle *conn, struct obd_statfs *osfs,
                struct ptlrpc_request **request)
 {
-        struct obd_statfs *osfs;
         struct ptlrpc_request *req;
         int rc, size = sizeof(*osfs);
         ENTRY;
@@ -488,8 +487,7 @@ int mdc_statfs(struct lustre_handle *conn, struct statfs *sfs,
         if (rc)
                 GOTO(out, rc);
 
-        osfs = lustre_msg_buf(req->rq_repmsg, 0);
-        obd_statfs_unpack(osfs, sfs);
+        obd_statfs_unpack(osfs, lustre_msg_buf(req->rq_repmsg, 0));
 
         EXIT;
 out:
index b97bc88..f54b3c6 100644 (file)
@@ -628,7 +628,8 @@ static int mds_statfs(struct ptlrpc_request *req)
         }
         osfs = lustre_msg_buf(req->rq_repmsg, 0);
         memset(osfs, 0, size);
-        obd_statfs_pack(osfs, &sfs);
+        statfs_pack(osfs, &sfs);
+        obd_statfs_pack(osfs, osfs);
 
 out:
         req->rq_status = rc;
index 1eab611..68eeee2 100644 (file)
@@ -8,7 +8,10 @@ MODULE = obdfilter
 modulefs_DATA = obdfilter.o
 EXTRA_PROGRAMS = obdfilter
 
-LINX=simple.c
+LINX=simple.c ll_pack.c
+ll_pack.c:
+       test -e ll_pack.c || ln -sf $(top_srcdir)/lib/ll_pack.c
+
 simple.c:
        test -e simple.c || ln -sf $(top_srcdir)/lib/simple.c
 
index fb87334..7347368 100644 (file)
@@ -1,14 +1,15 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  linux/fs/filter/filter.c
+ *  linux/fs/obdfilter/filter.c
  *
- * Copyright (C) 2001  Cluster File Systems, Inc.
+ * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
  *
  * This code is issued under the GNU General Public License.
  * See the file COPYING in this distribution
  *
  * by Peter Braam <braam@clusterfs.com>
+ * and Andreas Dilger <adilger@clusterfs.com>
  */
 
 #define EXPORT_SYMTAB
@@ -1359,12 +1360,18 @@ out_ctxt:
         RETURN(rc);
 }
 
-static int filter_statfs(struct lustre_handle *conn, struct statfs *statfs)
+static int filter_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
 {
         struct obd_device *obd = class_conn2obd(conn);
+        struct statfs sfs;
+        int rc;
 
         ENTRY;
-        RETURN(vfs_statfs(obd->u.filter.fo_sb, statfs));
+        rc = vfs_statfs(obd->u.filter.fo_sb, &sfs);
+        if (!rc)
+                statfs_pack(osfs, &sfs);
+
+        return rc;
 }
 
 static int filter_get_info(struct lustre_handle *conn, obd_count keylen,
index c88ce46..c63e7f1 100644 (file)
@@ -672,10 +672,9 @@ static int osc_cancel(struct lustre_handle *oconn, struct lov_stripe_md *md,
         RETURN(0);
 }
 
-static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs)
+static int osc_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
 {
         struct ptlrpc_request *request;
-        struct obd_statfs *osfs;
         int rc, size = sizeof(*osfs);
         ENTRY;
 
@@ -693,8 +692,7 @@ static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs)
                 GOTO(out, rc);
         }
 
-        osfs = lustre_msg_buf(request->rq_repmsg, 0);
-        obd_statfs_unpack(osfs, sfs);
+        obd_statfs_unpack(osfs, lustre_msg_buf(request->rq_repmsg, 0));
 
         EXIT;
  out:
index 2ac42ef..f81eede 100644 (file)
@@ -79,24 +79,24 @@ static int ost_statfs(struct ptlrpc_request *req)
 {
         struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg;
         struct obd_statfs *osfs;
-        struct statfs sfs;
         int rc, size = sizeof(*osfs);
         ENTRY;
 
-        rc = obd_statfs(conn, &sfs);
-        if (rc) {
-                CERROR("ost: statfs failed: rc %d\n", rc);
-                req->rq_status = rc;
-                RETURN(rc);
-        }
-
         rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
         if (rc)
                 RETURN(rc);
 
         osfs = lustre_msg_buf(req->rq_repmsg, 0);
         memset(osfs, 0, size);
-        obd_statfs_pack(osfs, &sfs);
+
+        rc = obd_statfs(conn, osfs);
+        if (rc) {
+                CERROR("ost: statfs failed: rc %d\n", rc);
+                req->rq_status = rc;
+                RETURN(rc);
+        }
+        obd_statfs_pack(osfs, osfs);
+
         RETURN(0);
 }