Whamcloud - gitweb
reworked symlink() and readlink():
authorhuanghua <huanghua>
Tue, 1 Aug 2006 16:15:27 +0000 (16:15 +0000)
committerhuanghua <huanghua>
Tue, 1 Aug 2006 16:15:27 +0000 (16:15 +0000)
(1)symlink is implemented similar to other file type;
(2)target name is written to the regular file with dbo_write();
(3)taget name is read with dbo_read().

lustre/cmm/cmm_object.c
lustre/include/dt_object.h
lustre/include/md_object.h
lustre/mdd/mdd_handler.c
lustre/osd/osd_handler.c

index 585c342..aeeb846 100644 (file)
@@ -329,7 +329,6 @@ static struct md_object_operations cml_mo_ops = {
         .moo_attr_get      = cml_attr_get,
         .moo_attr_set      = cml_attr_set,
         .moo_xattr_get     = cml_xattr_get,
-        .moo_readlink      = cml_readlink,
         .moo_xattr_list    = cml_xattr_list,
         .moo_xattr_set     = cml_xattr_set,
         .moo_xattr_del     = cml_xattr_del,
@@ -338,7 +337,8 @@ static struct md_object_operations cml_mo_ops = {
         .moo_ref_del       = cml_ref_del,
         .moo_open          = cml_open,
         .moo_close         = cml_close,
-        .moo_readpage      = cml_readpage
+        .moo_readpage      = cml_readpage,
+        .moo_readlink      = cml_readlink
 };
 
 /* md_dir operations */
@@ -611,7 +611,6 @@ static struct md_object_operations cmr_mo_ops = {
         .moo_attr_get      = cmr_attr_get,
         .moo_attr_set      = cmr_attr_set,
         .moo_xattr_get     = cmr_xattr_get,
-        .moo_readlink      = cmr_readlink,
         .moo_xattr_set     = cmr_xattr_set,
         .moo_xattr_list    = cmr_xattr_list,
         .moo_xattr_del     = cmr_xattr_del,
@@ -620,7 +619,8 @@ static struct md_object_operations cmr_mo_ops = {
         .moo_ref_del       = cmr_ref_del,
         .moo_open          = cmr_open,
         .moo_close         = cmr_close,
-        .moo_readpage      = cmr_readpage
+        .moo_readpage      = cmr_readpage,
+        .moo_readlink      = cmr_readlink
 };
 
 /* remote part of md_dir operations */
index 487efda..7e0d283 100644 (file)
@@ -201,14 +201,12 @@ struct dt_object_operations {
                                struct dt_object *dt, void *buf, int buf_len);
         /*
          * Create new object on this device.
-         * @target_name is the symbolic target.
          *
          * precondition: !lu_object_exists(ctxt, &dt->do_lu);
          * postcondition: ergo(result == 0, lu_object_exists(ctxt, &dt->do_lu));
          */
         int   (*do_create)(const struct lu_context *ctxt, struct dt_object *dt,
-                           struct lu_attr *attr, const char *target_name, 
-                           struct thandle *th);
+                           struct lu_attr *attr, struct thandle *th);
         /*
          * Announce that this object is going to be used as an index. This
          * operation check that object supports indexing operations and
@@ -235,9 +233,6 @@ struct dt_object_operations {
 
         int (*do_readpage)(const struct lu_context *ctxt,
                            struct dt_object *dt, const struct lu_rdpg *rdpg);
-        int (*do_readlink)(const struct lu_context *ctxt,
-                           struct dt_object *dt,
-                           void *buf, int buf_len);
 };
 
 /*
index ca01d45..eaf340a 100644 (file)
@@ -85,6 +85,8 @@ struct md_object_operations {
         int (*moo_xattr_del)(const struct lu_context *ctxt,
                              struct md_object *obj, const char *name);
 
+        int (*moo_readpage)(const struct lu_context *, struct md_object *,
+                            const struct lu_rdpg *);
         int (*moo_readlink)(const struct lu_context *ctxt,
                             struct md_object *obj,
                             void *buf, int buf_len);
@@ -97,9 +99,6 @@ struct md_object_operations {
                            struct md_attr *);
         int (*moo_open)(const struct lu_context *, struct md_object *);
         int (*moo_close)(const struct lu_context *, struct md_object *);
-
-        int (*moo_readpage)(const struct lu_context *, struct md_object *,
-                            const struct lu_rdpg *);
 };
 
 /*
index bc57919..4241a90 100644 (file)
@@ -178,14 +178,14 @@ static int mdd_readlink(const struct lu_context *ctxt, struct md_object *obj,
 {
         struct mdd_object *mdd_obj = md2mdd_obj(obj);
         struct dt_object  *next;
-        int rc;
+        loff_t             pos = 0;
+        int                rc;
         ENTRY;
 
         LASSERT(lu_object_exists(ctxt, &obj->mo_lu));
 
         next = mdd_object_child(mdd_obj);
-        rc = next->do_ops->do_readlink(ctxt, next, buf, buf_len);
-
+        rc = next->do_body_ops->dbo_read(ctxt, next, buf, buf_len, &pos);
         RETURN(rc);
 }
 static int mdd_xattr_list(const struct lu_context *ctxt, struct md_object *obj,
@@ -421,7 +421,6 @@ static void mdd_trans_stop(const struct lu_context *ctxt,
 
 static int __mdd_object_create(const struct lu_context *ctxt,
                                struct mdd_object *obj, struct md_attr *ma,
-                               const char *target_name,
                                struct thandle *handle)
 {
         struct dt_object *next;
@@ -431,8 +430,7 @@ static int __mdd_object_create(const struct lu_context *ctxt,
 
         if (!lu_object_exists(ctxt, mdd2lu_obj(obj))) {
                 next = mdd_object_child(obj);
-                rc = next->do_ops->do_create(ctxt, next, attr, 
-                                             target_name, handle);
+                rc = next->do_ops->do_create(ctxt, next, attr, handle);
         } else
                 rc = -EEXIST;
 
@@ -455,7 +453,7 @@ static int mdd_object_create(const struct lu_context *ctxt,
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
-        rc = __mdd_object_create(ctxt, md2mdd_obj(obj), attr, NULL, handle);
+        rc = __mdd_object_create(ctxt, md2mdd_obj(obj), attr, handle);
 
         mdd_trans_stop(ctxt, mdd, handle);
 
@@ -999,7 +997,7 @@ static int mdd_create(const struct lu_context *ctxt, struct md_object *pobj,
          * Maybe we should do the same. For now: creation-first.
          */
 
-        rc = __mdd_object_create(ctxt, son, ma, target_name, handle);
+        rc = __mdd_object_create(ctxt, son, ma, handle);
         if (rc)
                 GOTO(cleanup, rc);
         
@@ -1022,6 +1020,21 @@ static int mdd_create(const struct lu_context *ctxt, struct md_object *pobj,
         inserted = 1;
 
         rc = mdd_lov_set_md(ctxt, pobj, child, lmm, lmm_size, attr->la_mode);
+        if (rc)
+                GOTO(cleanup, rc);
+
+        if (S_ISLNK(attr->la_mode)) {
+                struct dt_object *dt = mdd_object_child(son);
+                loff_t pos = 0;
+                int sym_len = strlen(target_name);
+                rc = dt->do_body_ops->dbo_write(ctxt, dt, target_name,
+                                                sym_len, &pos, handle);
+                if (rc == sym_len)
+                        rc = 0;
+                else
+                        rc = -EFAULT;
+        }
+
         if (rc == 0) 
                 rc = mdd_attr_get(ctxt, child, ma);
         else 
@@ -1271,7 +1284,6 @@ static struct md_object_operations mdd_obj_ops = {
         .moo_attr_get      = mdd_attr_get,
         .moo_attr_set      = mdd_attr_set,
         .moo_xattr_get     = mdd_xattr_get,
-        .moo_readlink      = mdd_readlink,
         .moo_xattr_set     = mdd_xattr_set,
         .moo_xattr_list    = mdd_xattr_list,
         .moo_xattr_del     = mdd_xattr_del,
@@ -1280,7 +1292,8 @@ static struct md_object_operations mdd_obj_ops = {
         .moo_ref_del       = mdd_ref_del,
         .moo_open          = mdd_open,
         .moo_close         = mdd_close,
-        .moo_readpage      = mdd_readpage
+        .moo_readpage      = mdd_readpage,
+        .moo_readlink      = mdd_readlink
 };
 
 static struct obd_ops mdd_obd_device_ops = {
index d4c5ede..b030aa1 100644 (file)
@@ -644,7 +644,7 @@ static void osd_fid_build_name(const struct lu_fid *fid, char *name)
 }
 
 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
-                      umode_t mode, const char *target_name, struct thandle *th)
+                      umode_t mode, struct thandle *th)
 {
         int result;
         struct osd_device *osd = osd_obj2dev(obj);
@@ -668,10 +668,7 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
 
         dentry = d_alloc(osd->od_obj_area, &info->oti_str);
         if (dentry != NULL) {
-                if (S_ISLNK(mode))
-                        result = dir->i_op->symlink(dir, dentry, target_name);
-                else
-                        result = dir->i_op->create(dir, dentry, mode, NULL);
+                result = dir->i_op->create(dir, dentry, mode, NULL);
                 if (result == 0) {
                         LASSERT(dentry->d_inode != NULL);
                         obj->oo_inode = dentry->d_inode;
@@ -693,8 +690,7 @@ enum {
 };
 
 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
-                     struct lu_attr *attr, const char *target_name, 
-                     struct thandle *th)
+                     struct lu_attr *attr, struct thandle *th)
 {
         int result;
         struct osd_thandle *oth;
@@ -703,7 +699,7 @@ static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
         LASSERT(S_ISDIR(attr->la_mode));
         result = osd_mkfile(info, obj,
                             S_IFDIR | (attr->la_mode & (S_IRWXUGO|S_ISVTX)),
-                            target_name, th);
+                            th);
         if (result == 0) {
                 LASSERT(obj->oo_inode != NULL);
                 /*
@@ -717,38 +713,32 @@ static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
 }
 
 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
-                     struct lu_attr *attr, const char *target_name, 
-                     struct thandle *th)
+                     struct lu_attr *attr, struct thandle *th)
 {
         LASSERT(S_ISREG(attr->la_mode));
         return osd_mkfile(info, obj,
                           S_IFREG | (attr->la_mode & (S_IRWXUGO|S_ISVTX)), 
-                          target_name, th);
+                          th);
 }
 
 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
-                     struct lu_attr *attr, const char *target_name, 
-                     struct thandle *th)
+                     struct lu_attr *attr, struct thandle *th)
 {
         LASSERT(S_ISLNK(attr->la_mode));
-        LASSERT(target_name);
-        LASSERT(target_name[0] != 0);
 
-        CDEBUG(D_INODE, "I am going to symlink: "DFID3" to %s\n", 
-               PFID3(lu_object_fid(&obj->oo_dt.do_lu)), target_name);
-        return osd_mkfile(info, obj, S_IFLNK, target_name, th);
+        return osd_mkfile(info, obj,
+                          S_IFLNK | (attr->la_mode & (S_IRWXUGO|S_ISVTX)), 
+                          th);
 }
 
 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
-                     struct lu_attr *attr, const char *target_name, 
-                     struct thandle *th)
+                     struct lu_attr *attr, struct thandle *th)
 {
         return -EOPNOTSUPP;
 }
 
 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
-                              struct lu_attr *, const char *target_name,
-                              struct thandle *);
+                              struct lu_attr *, struct thandle *);
 
 static osd_obj_type_f osd_create_type_f(__u32 mode)
 {
@@ -778,8 +768,7 @@ static osd_obj_type_f osd_create_type_f(__u32 mode)
 }
 
 static int osd_object_create(const struct lu_context *ctx, struct dt_object *dt,
-                             struct lu_attr *attr, const char *target_name,
-                             struct thandle *th)
+                             struct lu_attr *attr, struct thandle *th)
 {
         const struct lu_fid    *fid  = lu_object_fid(&dt->do_lu);
         struct osd_object      *obj  = osd_dt_obj(dt);
@@ -807,9 +796,7 @@ static int osd_object_create(const struct lu_context *ctx, struct dt_object *dt,
         result = osd_create_pre(info, obj, attr, th);
         if (result == 0) {
                 result = osd_create_type_f(attr->la_mode & S_IFMT)(info, obj,
-                                                                   attr,
-                                                                   target_name,
-                                                                   th);
+                                                                   attr, th);
                 if (result == 0)
                         result = osd_create_post(info, obj, attr, th);
         }
@@ -1074,28 +1061,6 @@ static int osd_readpage(const struct lu_context *ctxt,
         return rc;
 }
 
-static int osd_readlink(const struct lu_context *ctxt, struct dt_object *dt,
-                        void *buf, int size)
-{
-        struct inode           *inode  = osd_dt_obj(dt)->oo_inode;
-        struct osd_thread_info *info   = lu_context_key_get(ctxt, &osd_key);
-        struct dentry          *dentry = &info->oti_dentry;
-        struct file            *file;
-        mm_segment_t            seg;
-        int                     rc;
-
-        LASSERT(lu_object_exists(ctxt, &dt->do_lu));
-        LASSERT(inode->i_op != NULL && inode->i_op->readlink != NULL);
-        LASSERT(buf != NULL);
-        dentry->d_inode = inode;
-
-        file = osd_rw_init(ctxt, inode, &seg);
-        rc = inode->i_op->readlink(dentry, buf, size);
-        osd_rw_fini(&seg);
-        return rc;
-
-}
-
 static struct dt_object_operations osd_obj_ops = {
         .do_lock       = osd_object_lock,
         .do_unlock     = osd_object_unlock,
@@ -1106,11 +1071,10 @@ static struct dt_object_operations osd_obj_ops = {
         .do_ref_add    = osd_object_ref_add,
         .do_ref_del    = osd_object_ref_del,
         .do_xattr_get  = osd_xattr_get,
-        .do_readlink   = osd_readlink,
         .do_xattr_set  = osd_xattr_set,
         .do_xattr_del  = osd_xattr_del,
         .do_xattr_list = osd_xattr_list,
-        .do_readpage   = osd_readpage
+        .do_readpage   = osd_readpage,
 };
 
 /*