Whamcloud - gitweb
Land b1_2_smallfix onto b1_2 (20040616_1009)
[fs/lustre-release.git] / lustre / mds / mds_fs.c
index 453d8b4..5505329 100644 (file)
@@ -91,11 +91,12 @@ int mds_client_add(struct obd_device *obd, struct mds_obd *mds,
                 }
         }
 
-        CDEBUG(D_INFO, "client at index %d with UUID '%s' added\n",
+        CDEBUG(D_INFO, "client at idx %d with UUID '%s' added\n",
                cl_idx, med->med_mcd->mcd_uuid);
 
         med->med_idx = cl_idx;
-        med->med_off = MDS_LR_CLIENT_START + (cl_idx * MDS_LR_CLIENT_SIZE);
+        med->med_off = le32_to_cpu(mds->mds_server_data->msd_client_start) +
+                (cl_idx * le16_to_cpu(mds->mds_server_data->msd_client_size));
 
         if (new_client) {
                 struct obd_run_ctxt saved;
@@ -127,7 +128,6 @@ int mds_client_free(struct obd_export *exp, int clear_client)
         int rc;
         unsigned long *bitmap = mds->mds_client_bitmap;
 
-        LASSERT(bitmap);
         if (!med->med_mcd)
                 RETURN(0);
 
@@ -135,10 +135,14 @@ int mds_client_free(struct obd_export *exp, int clear_client)
         if (!strcmp(med->med_mcd->mcd_uuid, obd->obd_uuid.uuid))
                 GOTO(free_and_out, 0);
 
-        CDEBUG(D_INFO, "freeing client at index %u (%lld)with UUID '%s'\n",
+        CDEBUG(D_INFO, "freeing client at idx %u (%lld)with UUID '%s'\n",
                med->med_idx, med->med_off, med->med_mcd->mcd_uuid);
 
-        if (!test_and_clear_bit(med->med_idx, bitmap)) {
+        LASSERT(bitmap);
+
+        /* Clear the bit _after_ zeroing out the client so we don't
+           race with mds_client_add and zero out new clients.*/
+        if (!test_bit(med->med_idx, bitmap)) {
                 CERROR("MDS client %u: bit already clear in bitmap!!\n",
                        med->med_idx);
                 LBUG();
@@ -152,10 +156,16 @@ int mds_client_free(struct obd_export *exp, int clear_client)
                 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
 
                 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
-                       "zeroing out client %s off %u in %s rc %d\n",
+                       "zeroing out client %s idx %u in %s rc %d\n",
                        med->med_mcd->mcd_uuid, med->med_idx, LAST_RCVD, rc);
         }
 
+        if (!test_and_clear_bit(med->med_idx, bitmap)) {
+                CERROR("MDS client %u: bit already clear in bitmap!!\n",
+                       med->med_idx);
+                LBUG();
+        }
+
  free_and_out:
         OBD_FREE(med->med_mcd, sizeof(*med->med_mcd));
 
@@ -172,7 +182,7 @@ static int mds_server_free_data(struct mds_obd *mds)
         return 0;
 }
 
-static int mds_read_last_rcvd(struct obd_device *obd, struct file *file)
+static int mds_init_server_data(struct obd_device *obd, struct file *file)
 {
         struct mds_obd *mds = &obd->u.mds;
         struct mds_server_data *msd;
@@ -184,10 +194,10 @@ static int mds_read_last_rcvd(struct obd_device *obd, struct file *file)
         ENTRY;
 
         /* ensure padding in the struct is the correct size */
-        LASSERT (offsetof(struct mds_server_data, msd_padding) +
-                 sizeof(msd->msd_padding) == MDS_LR_SERVER_SIZE);
-        LASSERT (offsetof(struct mds_client_data, mcd_padding) +
-                 sizeof(mcd->mcd_padding) == MDS_LR_CLIENT_SIZE);
+        LASSERT(offsetof(struct mds_server_data, msd_padding) +
+                sizeof(msd->msd_padding) == MDS_LR_SERVER_SIZE);
+        LASSERT(offsetof(struct mds_client_data, mcd_padding) +
+                sizeof(mcd->mcd_padding) == MDS_LR_CLIENT_SIZE);
 
         OBD_ALLOC_WAIT(msd, sizeof(*msd));
         if (!msd)
@@ -207,7 +217,7 @@ static int mds_read_last_rcvd(struct obd_device *obd, struct file *file)
 
                 memcpy(msd->msd_uuid, obd->obd_uuid.uuid,sizeof(msd->msd_uuid));
                 msd->msd_last_transno = 0;
-                mount_count = msd->msd_mount_count = 0; 
+                mount_count = msd->msd_mount_count = 0;
                 msd->msd_server_size = cpu_to_le32(MDS_LR_SERVER_SIZE);
                 msd->msd_client_start = cpu_to_le32(MDS_LR_CLIENT_START);
                 msd->msd_client_size = cpu_to_le16(MDS_LR_CLIENT_SIZE);
@@ -256,8 +266,9 @@ static int mds_read_last_rcvd(struct obd_device *obd, struct file *file)
         CDEBUG(D_INODE, "%s: last_rcvd size: %lu\n",
                obd->obd_name, last_rcvd_size);
         CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
-               last_rcvd_size <= MDS_LR_CLIENT_START ? 0 :
-               (last_rcvd_size - MDS_LR_CLIENT_START) / MDS_LR_CLIENT_SIZE);
+               last_rcvd_size <= le32_to_cpu(msd->msd_client_start) ? 0 :
+               (last_rcvd_size - le32_to_cpu(msd->msd_client_start)) /
+                le16_to_cpu(msd->msd_client_size));
 
         /* When we do a clean MDS shutdown, we save the last_transno into
          * the header.  If we find clients with higher last_transno values
@@ -265,7 +276,8 @@ static int mds_read_last_rcvd(struct obd_device *obd, struct file *file)
         for (cl_idx = 0, off = le32_to_cpu(msd->msd_client_start);
              off < last_rcvd_size; cl_idx++) {
                 __u64 last_transno;
-                int mount_age;
+                struct obd_export *exp;
+                struct mds_export_data *med;
 
                 if (!mcd) {
                         OBD_ALLOC_WAIT(mcd, sizeof(*mcd));
@@ -296,36 +308,28 @@ static int mds_read_last_rcvd(struct obd_device *obd, struct file *file)
                 /* These exports are cleaned up by mds_disconnect(), so they
                  * need to be set up like real exports as mds_connect() does.
                  */
-                mount_age = mount_count - le64_to_cpu(mcd->mcd_mount_count);
-                if (mount_age < MDS_MOUNT_RECOV) {
-                        struct obd_export *exp = class_new_export(obd);
-                        struct mds_export_data *med;
-                        CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
-                               " srv lr: "LPU64" mnt: "LPU64" last mount: "
-                               LPU64"\n", mcd->mcd_uuid, cl_idx,
-                               last_transno, le64_to_cpu(msd->msd_last_transno),
-                               le64_to_cpu(mcd->mcd_mount_count), mount_count);
-                        if (exp == NULL)
-                                GOTO(err_client, rc = -ENOMEM);
-
-                        memcpy(&exp->exp_client_uuid.uuid, mcd->mcd_uuid,
-                               sizeof exp->exp_client_uuid.uuid);
-                        med = &exp->exp_mds_data;
-                        med->med_mcd = mcd;
-                        mds_client_add(obd, mds, med, cl_idx);
-                        /* create helper if export init gets more complex */
-                        INIT_LIST_HEAD(&med->med_open_head);
-                        spin_lock_init(&med->med_open_lock);
-
-                        mcd = NULL;
-                        obd->obd_recoverable_clients++;
-                        obd->obd_max_recoverable_clients++;
-                        class_export_put(exp);
-                } else {
-                        CDEBUG(D_INFO, "discarded client %d, UUID '%s', count "
-                               LPU64"\n", cl_idx, mcd->mcd_uuid,
-                               le64_to_cpu(mcd->mcd_mount_count));
-                }
+                CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
+                       " srv lr: "LPU64"\n", mcd->mcd_uuid, cl_idx,
+                       last_transno, le64_to_cpu(msd->msd_last_transno));
+
+                exp = class_new_export(obd);
+                if (exp == NULL)
+                        GOTO(err_client, rc = -ENOMEM);
+
+                memcpy(&exp->exp_client_uuid.uuid, mcd->mcd_uuid,
+                       sizeof exp->exp_client_uuid.uuid);
+                med = &exp->exp_mds_data;
+                med->med_mcd = mcd;
+                mds_client_add(obd, mds, med, cl_idx);
+                /* create helper if export init gets more complex */
+                INIT_LIST_HEAD(&med->med_open_head);
+                spin_lock_init(&med->med_open_lock);
+
+                mcd = NULL;
+                exp->exp_replay_needed = 1;
+                obd->obd_recoverable_clients++;
+                obd->obd_max_recoverable_clients++;
+                class_export_put(exp);
 
                 CDEBUG(D_OTHER, "client at idx %d has last_transno = "LPU64"\n",
                        cl_idx, last_transno);
@@ -334,25 +338,28 @@ static int mds_read_last_rcvd(struct obd_device *obd, struct file *file)
                        mds->mds_last_transno = last_transno;
         }
 
+        if (mcd)
+                OBD_FREE(mcd, sizeof(*mcd));
+
         obd->obd_last_committed = mds->mds_last_transno;
+
         if (obd->obd_recoverable_clients) {
-                CWARN("RECOVERY: %d recoverable clients, last_transno "
-                       LPU64"\n", obd->obd_recoverable_clients,
-                       mds->mds_last_transno);
+                CWARN("RECOVERY: service %s, %d recoverable clients, "
+                      "last_transno "LPU64"\n", obd->obd_name,
+                      obd->obd_recoverable_clients, mds->mds_last_transno);
                 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
                 obd->obd_recovering = 1;
         }
 
-        if (mcd)
-                OBD_FREE(mcd, sizeof(*mcd));
-        
         mds->mds_mount_count = mount_count + 1;
         msd->msd_mount_count = cpu_to_le64(mds->mds_mount_count);
 
         /* save it, so mount count and last_transno is current */
         rc = mds_update_server_data(obd, 1);
+        if (rc)
+                GOTO(err_client, rc);
 
-        RETURN(rc);
+        RETURN(0);
 
 err_client:
         class_disconnect_exports(obd, 0);
@@ -370,10 +377,9 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
         int rc;
         ENTRY;
 
-
-        /* Get rid of unneeded supplementary groups */
-        current->ngroups = 0;
-        memset(current->groups, 0, sizeof(current->groups));
+        rc = cleanup_group_info();
+        if (rc)
+                RETURN(rc);
 
         mds->mds_vfsmnt = mnt;
         mds->mds_sb = mnt->mnt_root->d_inode->i_sb;
@@ -388,7 +394,7 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
 
         /* setup the directory tree */
         push_ctxt(&saved, &obd->obd_ctxt, NULL);
-        dentry = simple_mkdir(current->fs->pwd, "ROOT", 0755);
+        dentry = simple_mkdir(current->fs->pwd, "ROOT", 0755, 0);
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
                 CERROR("cannot create ROOT directory: rc = %d\n", rc);
@@ -403,14 +409,19 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
 
         dentry = lookup_one_len("__iopen__", current->fs->pwd,
                                 strlen("__iopen__"));
-        if (IS_ERR(dentry) || !dentry->d_inode) {
-                rc = (IS_ERR(dentry)) ? PTR_ERR(dentry): -ENOENT;
-                CERROR("cannot open iopen FH directory: rc = %d\n", rc);
+        if (IS_ERR(dentry)) {
+                rc = PTR_ERR(dentry);
+                CERROR("cannot lookup __iopen__ directory: rc = %d\n", rc);
                 GOTO(err_pop, rc);
         }
+        if (!dentry->d_inode) {
+                rc = -ENOENT;
+                CERROR("__iopen__ directory has no inode? rc = %d\n", rc);
+                GOTO(err_fid, rc);
+        }
         mds->mds_fid_de = dentry;
 
-        dentry = simple_mkdir(current->fs->pwd, "PENDING", 0777);
+        dentry = simple_mkdir(current->fs->pwd, "PENDING", 0777, 1);
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
                 CERROR("cannot create PENDING directory: rc = %d\n", rc);
@@ -418,7 +429,7 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
         }
         mds->mds_pending_dir = dentry;
 
-        dentry = simple_mkdir(current->fs->pwd, "LOGS", 0777);
+        dentry = simple_mkdir(current->fs->pwd, "LOGS", 0777, 1);
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
                 CERROR("cannot create LOGS directory: rc = %d\n", rc);
@@ -426,7 +437,7 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
         }
         mds->mds_logs_dir = dentry;
 
-        dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777);
+        dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
                 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
@@ -448,7 +459,7 @@ int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
                 GOTO(err_last_rcvd, rc = -ENOENT);
         }
 
-        rc = mds_read_last_rcvd(obd, file);
+        rc = mds_init_server_data(obd, file);
         if (rc) {
                 CERROR("cannot read %s: rc = %d\n", LAST_RCVD, rc);
                 GOTO(err_last_rcvd, rc);
@@ -555,8 +566,8 @@ int mds_obd_create(struct obd_export *exp, struct obdo *oa,
         ENTRY;
 
         push_ctxt(&saved, &exp->exp_obd->obd_ctxt, NULL);
-        
-        sprintf(fidname, "OBJECTS/%u", tmpname);
+
+        sprintf(fidname, "OBJECTS/%u.%u", tmpname, current->pid);
         filp = filp_open(fidname, O_CREAT | O_EXCL, 0644);
         if (IS_ERR(filp)) {
                 rc = PTR_ERR(filp);
@@ -590,9 +601,9 @@ int mds_obd_create(struct obd_export *exp, struct obdo *oa,
 
         handle = fsfilt_start(exp->exp_obd, mds->mds_objects_dir->d_inode,
                               FSFILT_OP_RENAME, NULL);
-        if (IS_ERR(handle)) 
+        if (IS_ERR(handle))
                 GOTO(out_dput, rc = PTR_ERR(handle));
-        
+
         lock_kernel();
         rc = vfs_rename(mds->mds_objects_dir->d_inode, filp->f_dentry,
                         mds->mds_objects_dir->d_inode, new_child);
@@ -642,12 +653,15 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
         down(&parent_inode->i_sem);
         de = lookup_one_len(fidname, mds->mds_objects_dir, namelen);
         if (de == NULL || de->d_inode == NULL) {
-                CERROR("destroying non-existent object "LPU64"\n", oa->o_id);
-                GOTO(out, rc = IS_ERR(de) ? PTR_ERR(de) : -ENOENT);
+                CERROR("destroying non-existent object "LPU64" %s\n", 
+                       oa->o_id, fidname);
+                GOTO(out_dput, rc = IS_ERR(de) ? PTR_ERR(de) : -ENOENT);
         }
 
-        handle = fsfilt_start(obd, mds->mds_objects_dir->d_inode,
-                              FSFILT_OP_UNLINK_LOG, oti);
+        /* Stripe count is 1 here since this is some MDS specific stuff
+           that is unlinked, not spanned across multiple OSTs */
+        handle = fsfilt_start_log(obd, mds->mds_objects_dir->d_inode,
+                                  FSFILT_OP_UNLINK, oti, 1);
         if (IS_ERR(handle)) {
                 GOTO(out_dput, rc = PTR_ERR(handle));
         }
@@ -661,8 +675,8 @@ int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
         if (err && !rc)
                 rc = err;
 out_dput:
-        l_dput(de);
-out:
+        if (de != NULL)
+                l_dput(de);
         up(&parent_inode->i_sem);
         pop_ctxt(&saved, &obd->obd_ctxt, NULL);
         RETURN(rc);