Whamcloud - gitweb
Add mount_count file to hold the current MDS generation number. Note that
authoradilger <adilger>
Tue, 16 Apr 2002 07:22:49 +0000 (07:22 +0000)
committeradilger <adilger>
Tue, 16 Apr 2002 07:22:49 +0000 (07:22 +0000)
you cannot read this file from userspace, because it will (mistakenly) think
that this file lives on the OST and LBUG if that inode isn't allocated, or
you will get garbage data.  The kernel code has no problem reading it, of
course.  This LBUG will go away with EAs and/or when we start mounting the
ROOT directory, at which point you will not be able to read the file at all.

lustre/include/linux/lustre_lib.h
lustre/include/linux/obd.h
lustre/lib/simple.c
lustre/mds/handler.c

index 6b109e8..f6e3ecb 100644 (file)
@@ -43,6 +43,8 @@ struct obd_run_ctxt;
 void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new);
 void pop_ctxt(struct obd_run_ctxt *saved);
 int simple_mkdir(struct dentry *dir, char *name, int mode);
+int lustre_fread(struct file *file, char *str, int len, loff_t *off);
+int lustre_fwrite(struct file *file, const char *str, int len, loff_t *off);
 #endif
 
 #include <linux/portals_lib.h>
index ac9667f..0e80c8d 100644 (file)
@@ -75,6 +75,8 @@ struct mds_obd {
         struct inode_operations *mds_iop;
         struct address_space_operations *mds_aops;
         struct mds_fs_operations *mds_fsops;
+        struct file *mds_last_rcvd;
+        __u64 mds_mount_count;
 };
 
 struct ldlm_obd {
index aa96121..366ec68 100644 (file)
@@ -63,3 +63,22 @@ out:
 
         RETURN(err);
 }
+
+int lustre_fread(struct file *file, char *str, int len, loff_t *off)
+{
+       if (!file || !file->f_op || !file->f_op->read || !off)
+               RETURN(-EINVAL);
+
+       return file->f_op->read(file, str, len, off);
+}
+
+int lustre_fwrite(struct file *file, const char *str, int len, loff_t *off)
+{
+       if (!file || !file->f_op || !file->f_op->write || !off)
+               RETURN(-EINVAL);
+
+       if (!file->f_op->write)
+               RETURN(-EROFS);
+
+       return file->f_op->write(file, str, len, off);
+}
index a2cb3b6..652cf8f 100644 (file)
@@ -403,7 +403,9 @@ static int mds_prep(struct obd_device *obddev)
         struct mds_obd *mds = &obddev->u.mds;
         struct super_operations *s_ops;
         struct file *f;
-        int err;
+        loff_t off = 0;
+        __u64 mount_count;
+        int rc;
 
         mds->mds_service = ptlrpc_init_svc(128 * 1024,
                                            MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
@@ -414,29 +416,60 @@ static int mds_prep(struct obd_device *obddev)
                 RETURN(-EINVAL);
         }
 
-        err = ptlrpc_start_thread(obddev, mds->mds_service, "lustre_mds");
-        if (err) {
+        rc = ptlrpc_start_thread(obddev, mds->mds_service, "lustre_mds");
+        if (rc) {
                 CERROR("cannot start thread\n");
-                GOTO(err_svc, err);
+                GOTO(err_svc, rc);
         }
 
         push_ctxt(&saved, &mds->mds_ctxt);
-        err = simple_mkdir(current->fs->pwd, "ROOT", 0700);
-        if (err && err != -EEXIST) {
+        rc = simple_mkdir(current->fs->pwd, "ROOT", 0700);
+        if (rc && rc != -EEXIST) {
                 CERROR("cannot create ROOT directory\n");
-                GOTO(err_svc, err);
+                GOTO(err_svc, rc);
         }
-        err = simple_mkdir(current->fs->pwd, "FH", 0700);
-        if (err && err != -EEXIST) {
+        rc = simple_mkdir(current->fs->pwd, "FH", 0700);
+        if (rc && rc != -EEXIST) {
                 CERROR("cannot create FH directory\n");
-                GOTO(err_svc, err);
+                GOTO(err_svc, rc);
         }
+
+        f = filp_open("mount_count", O_RDWR | O_CREAT, 0644);
+        if (IS_ERR(f)) {
+                CERROR("cannot open/create mount_count file, rc = %ld\n",
+                       PTR_ERR(f));
+                GOTO(err_svc, rc = PTR_ERR(f));
+        }
+        rc = lustre_fread(f, (char *)&mount_count, sizeof(mount_count), &off);
+        if (rc == 0) {
+                CERROR("empty MDS mount_count, new MDS?\n");
+                /* XXX maybe this should just be a random number? */
+                mds->mds_mount_count = 0;
+        } else if (rc != sizeof(mount_count)) {
+                CERROR("error reading mount_count: rc = %d\n", rc);
+                /* XXX maybe this should just be a random number? */
+                mds->mds_mount_count = 0;
+        } else {
+                mds->mds_mount_count = le64_to_cpu(mount_count);
+        }
+
+        mds->mds_mount_count++;
+        CDEBUG(D_SUPER, "MDS mount_count is %Ld\n", mds->mds_mount_count);
+        off = 0;
+        mount_count = cpu_to_le64(mds->mds_mount_count);
+        rc = lustre_fwrite(f, (char *)&mount_count, sizeof(mount_count), &off);
+        if (rc != sizeof(mount_count))
+                CERROR("error writing mount_count: rc = %d\n", rc);
+        rc = filp_close(f, 0);
+        if (rc)
+                CERROR("error closing mount_count: rc = %d\n", rc);
+
         f = filp_open("last_rcvd", O_RDWR | O_CREAT, 0644);
         if (IS_ERR(f)) {
                 CERROR("cannot open/create last_rcvd file\n");
-                GOTO(err_svc, err = PTR_ERR(f));
+                GOTO(err_svc, rc = PTR_ERR(f));
         }
-        mds->last_rcvd = f;
+        mds->mds_last_rcvd = f;
         pop_ctxt(&saved);
 
         /*
@@ -462,7 +495,7 @@ err_svc:
         rpc_unregister_service(mds->mds_service);
         OBD_FREE(mds->mds_service, sizeof(*mds->mds_service));
 
-        return(err);
+        return rc;
 }
 
 /* mount the file system (secretly) */
@@ -547,9 +580,9 @@ static int mds_cleanup(struct obd_device * obddev)
         if (!mds->mds_sb)
                 RETURN(0);
 
-        if (mds->last_rcvd) {
-                int rc = filp_close(mds->last_rcvd, 0);
-                mds->last_rcvd = NULL;
+        if (mds->mds_last_rcvd) {
+                int rc = filp_close(mds->mds_last_rcvd, 0);
+                mds->mds_last_rcvd = NULL;
 
                 if (rc)
                         CERROR("last_rcvd file won't close, rc=%d\n", rc);