Whamcloud - gitweb
new handling of root directory:
authornikita <nikita>
Wed, 17 May 2006 17:49:12 +0000 (17:49 +0000)
committernikita <nikita>
Wed, 17 May 2006 17:49:12 +0000 (17:49 +0000)
osd returns a fid of its real root directory as result of ->dt_root_get();

mdd gets osd root fid during cluster startup, created corresponding object and
looks "ROOT" there.

lustre/mdd/mdd_handler.c
lustre/osd/osd_handler.c
lustre/osd/osd_internal.h
lustre/osd/osd_oi.c

index bb2a1a2..dba12dd 100644 (file)
@@ -65,8 +65,11 @@ static struct lu_context_key       mdd_thread_key;
 
 struct mdd_thread_info {
         struct txn_param mti_param;
+        struct lu_fid    mti_fid;
 };
 
+const char *mdd_root_dir_name = "ROOT";
+
 static struct mdd_thread_info *mdd_ctx_info(struct lu_context *ctx)
 {
         struct mdd_thread_info *info;
@@ -321,6 +324,57 @@ static int mdd_object_print(struct lu_context *ctxt,
         return seq_printf(f, LUSTRE_MDD0_NAME"-object@%p", o);
 }
 
+static int mdd_dt_lookup(struct lu_context *ctx, struct mdd_device *mdd,
+                         struct mdd_object *obj, const char *name,
+                         struct lu_fid *fid)
+{
+        struct dt_object *dir    = mdd_object_child(obj);
+        struct dt_rec    *rec    = (struct dt_rec *)fid;
+        const struct dt_key *key = (const struct dt_key *)name;
+        int result;
+
+        if (dir->do_index_ops != NULL)
+                result = dir->do_index_ops->dio_lookup(ctx, dir, rec, key);
+        else
+                result = -ENOTDIR;
+        return result;
+}
+
+static int mdd_mount(struct lu_context *ctx, struct mdd_device *mdd)
+{
+        int result;
+        struct mdd_thread_info *info = lu_context_key_get(ctx,
+                                                          &mdd_thread_key);
+        struct lu_device *dev = &mdd->mdd_md_dev.md_lu_dev;
+
+        result = mdd_child_ops(mdd)->dt_root_get(ctx, mdd->mdd_child,
+                                                 &info->mti_fid);
+        if (result == 0) {
+                struct lu_object *root;
+
+                root = lu_object_find(ctx, dev->ld_site, &info->mti_fid);
+                if (!IS_ERR(root)) {
+                        struct mdd_object *obj;
+
+                        obj = mdd_obj(lu_object_locate(root->lo_header,
+                                                       dev->ld_type));
+                        if (obj != NULL)
+                                result = mdd_dt_lookup(ctx, mdd, obj,
+                                                       mdd_root_dir_name ,
+                                                       &mdd->mdd_root_fid);
+                        else {
+                                CERROR("No slice\n");
+                                result = -EINVAL;
+                        }
+                        lu_object_put(ctx, root);
+                } else {
+                        CERROR("No root\n");
+                        result = PTR_ERR(root);
+                }
+        }
+        return result;
+}
+
 static int mdd_fs_setup(struct lu_context *ctx, struct mdd_device *mdd)
 {
         return 0;
@@ -371,6 +425,8 @@ static int mdd_process_config(struct lu_context *ctx,
 
         default:
                 err = next->ld_ops->ldo_process_config(ctx, next, cfg);
+                if (err == 0 && cfg->lcfg_command == LCFG_SETUP)
+                        err = mdd_mount(ctx, m);
         }
 
         RETURN(err);
@@ -633,8 +689,10 @@ exit:
         RETURN(rc);
 }
 
-static void mdd_rename_lock(struct mdd_device *mdd, struct mdd_object *src_pobj,
-                            struct mdd_object *tgt_pobj, struct mdd_object *sobj,
+static void mdd_rename_lock(struct mdd_device *mdd,
+                            struct mdd_object *src_pobj,
+                            struct mdd_object *tgt_pobj,
+                            struct mdd_object *sobj,
                             struct mdd_object *tobj)
 {
         return;
@@ -752,7 +810,8 @@ static int mdd_root_get(struct lu_context *ctx,
         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
 
         ENTRY;
-        RETURN(mdd_child_ops(mdd)->dt_root_get(ctx, mdd->mdd_child, f));
+        *f = mdd->mdd_root_fid;
+        RETURN(0);
 }
 
 static int mdd_config(struct lu_context *ctx, struct md_device *m,
index eb5820b..194e132 100644 (file)
@@ -148,7 +148,7 @@ static int osd_root_get(struct lu_context *ctx,
 {
         struct osd_device *d = osd_dt_dev(dev);
 
-        return osd_inode_get_fid(d, d->od_root_dir->d_inode, f);
+        return osd_inode_get_fid(d, osd_sb(d)->s_root->d_inode, f);
 }
 
 
@@ -166,7 +166,7 @@ static struct lu_object *osd_object_alloc(struct lu_context *ctx,
                 struct lu_object *l;
 
                 l = &mo->oo_dt.do_lu;
-                lu_object_init(l, NULL, d);
+                dt_object_init(&mo->oo_dt, NULL, d);
                 mo->oo_dt.do_ops = &osd_obj_ops;
                 l->lo_ops = &osd_lu_obj_ops;
                 init_rwsem(&mo->oo_sem);
@@ -201,6 +201,7 @@ static int osd_object_init(struct lu_context *ctxt, struct lu_object *l)
 static void osd_object_free(struct lu_context *ctx, struct lu_object *l)
 {
         struct osd_object *obj = osd_obj(l);
+        dt_object_fini(&obj->oo_dt);
         OBD_FREE_PTR(obj);
 }
 
@@ -550,6 +551,23 @@ static struct dt_body_operations osd_body_ops = {
  * Index operations.
  */
 
+#if OI_IN_MEMORY
+
+/*
+ * XXX fid for "real" root.
+ */
+static const struct lu_fid uber_fid = {
+        .f_seq = LUSTRE_ROOT_FID_SEQ,
+        .f_oid = LUSTRE_ROOT_FID_OID,
+        .f_ver = 0
+};
+
+extern void osd_oi_init0(struct osd_oi *oi, const struct lu_fid *fid,
+                         __u64 root_ino, __u32 root_gen);
+extern int osd_oi_find_fid(struct osd_oi *oi,
+                           __u64 ino, __u32 gen, struct lu_fid *fid);
+#endif
+
 /*
  * XXX This is temporary solution: inode operations are used until iam is
  * ready.
@@ -567,7 +585,8 @@ static int osd_index_lookup(struct lu_context *ctxt, struct dt_object *dt,
         /*
          * XXX temporary solution.
          */
-        struct dentry     *dentry;
+        struct dentry *dentry;
+        struct dentry *parent;
 
         LASSERT(osd_has_index(obj));
         LASSERT(osd->od_obj_area != NULL);
@@ -578,7 +597,11 @@ static int osd_index_lookup(struct lu_context *ctxt, struct dt_object *dt,
         dir = obj->oo_inode;
         LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
 
-        dentry = d_alloc(NULL, &info->oti_str);
+        parent = d_alloc_root(dir);
+        if (parent == NULL)
+                return -ENOMEM;
+
+        dentry = d_alloc(parent, &info->oti_str);
         if (dentry != NULL) {
                 struct dentry *d;
 
@@ -593,12 +616,16 @@ static int osd_index_lookup(struct lu_context *ctxt, struct dt_object *dt,
                          */
                         if (dentry->d_inode != NULL) {
                                 struct lu_fid *fid = (struct lu_fid *)rec;
+                                struct inode  *inode = dentry->d_inode;
                                 /*
                                  * Build fid from inode.
                                  */
-                                fid->f_seq = 0; /* XXX hard-coded */
-                                fid->f_oid = dentry->d_inode->i_ino;
-                                fid->f_ver = dentry->d_inode->i_generation;
+                                /* XXX hard-coded */
+                                fid->f_seq = LUSTRE_ROOT_FID_SEQ + 1;
+                                fid->f_oid = inode->i_ino;
+                                fid->f_ver = inode->i_generation;
+                                osd_oi_init0(&osd->od_oi, fid,
+                                             inode->i_ino, inode->i_generation);
                                 result = 0;
                         } else
                                 result = -ENOENT;
@@ -611,6 +638,7 @@ static int osd_index_lookup(struct lu_context *ctxt, struct dt_object *dt,
                 dput(dentry);
         } else
                 result = -ENOMEM;
+        dput(parent);
         return result;
 }
 
@@ -680,15 +708,12 @@ static int osd_device_init(struct lu_context *ctx,
         return 0;
 }
 
-extern void osd_oi_init0(struct osd_oi *oi, __u64 root_ino, __u32 root_gen);
-extern int osd_oi_find_fid(struct osd_oi *oi,
-                           __u64 ino, __u32 gen, struct lu_fid *fid);
-
 static int osd_mount(struct lu_context *ctx,
                      struct osd_device *o, struct lustre_cfg *cfg)
 {
         struct lustre_mount_info *lmi;
-        const char *dev = lustre_cfg_string(cfg, 0);
+        const char               *dev = lustre_cfg_string(cfg, 0);
+        struct inode             *inode;
         int result;
 
         ENTRY;
@@ -713,16 +738,25 @@ static int osd_mount(struct lu_context *ctx,
         if (result == 0) {
                 struct dentry *d;
 
+                inode = osd_sb(o)->s_root->d_inode;
+                /*
+                 * XXX temporary kludge: this should be done by mkfs.
+                 */
+                osd_oi_init0(&o->od_oi, &uber_fid,
+                             inode->i_ino, inode->i_generation);
+
                 d = simple_mkdir(osd_sb(o)->s_root, "*OBJ-TEMP*", 0777, 1);
                 if (!IS_ERR(d)) {
                         o->od_obj_area = d;
 
+                        /*
+                         * XXX temporary fix for mdd/fld: create root
+                         * directory if not yet there, and insert it into fld.
+                         */
                         d = simple_mkdir(osd_sb(o)->s_root, "ROOT", 0777, 1);
-                        if (!IS_ERR(d)) {
-                                osd_oi_init0(&o->od_oi, d->d_inode->i_ino,
-                                             d->d_inode->i_generation);
-                                o->od_root_dir = d;
-                        } else
+                        if (!IS_ERR(d))
+                                dput(d);
+                        else
                                 result = PTR_ERR(d);
                 } else
                         result = PTR_ERR(d);
@@ -742,10 +776,6 @@ static struct lu_device *osd_device_fini(struct lu_context *ctx,
                 dput(o->od_obj_area);
                 o->od_obj_area = NULL;
         }
-        if (o->od_root_dir != NULL) {
-                dput(o->od_root_dir);
-                o->od_root_dir = NULL;
-        }
         osd_oi_fini(&o->od_oi);
 
         if (o->od_mount)
index e623d87..56c384f 100644 (file)
@@ -61,8 +61,6 @@ struct osd_device {
         struct lustre_mount_info *od_mount;
         /* object index */
         struct osd_oi             od_oi;
-        /* root directory */
-        struct dentry            *od_root_dir;
         /*
          * XXX temporary stuff for object index: directory where every object
          * is named by its fid.
index 781de2b..8963ace 100644 (file)
@@ -193,13 +193,8 @@ int osd_oi_delete(struct osd_thread_info *info,
         return result;
 }
 
-const struct lu_fid root_fid = {
-        .f_seq = LUSTRE_ROOT_FID_SEQ,
-        .f_oid = LUSTRE_ROOT_FID_OID,
-        .f_ver = 0
-};
-
-void osd_oi_init0(struct osd_oi *oi, __u64 root_ino, __u32 root_gen)
+void osd_oi_init0(struct osd_oi *oi, const struct lu_fid *fid,
+                  __u64 root_ino, __u32 root_gen)
 {
         int result;
         const struct osd_inode_id root_id = {
@@ -207,7 +202,7 @@ void osd_oi_init0(struct osd_oi *oi, __u64 root_ino, __u32 root_gen)
                 .oii_gen = root_gen
         };
 
-        result = osd_oi_insert(NULL, oi, &root_fid, &root_id, NULL);
+        result = osd_oi_insert(NULL, oi, fid, &root_id, NULL);
         LASSERT(result == 0);
 }