Whamcloud - gitweb
b=11694
authorkomaln <komaln>
Tue, 6 Nov 2007 09:18:53 +0000 (09:18 +0000)
committerkomaln <komaln>
Tue, 6 Nov 2007 09:18:53 +0000 (09:18 +0000)
r=Nathan, Adilger

Improve 'lfs getstripe' functionality to return default values for directories instead of "no stripe info".

lustre/include/lustre/lustre_idl.h
lustre/mds/handler.c
lustre/mds/mds_internal.h
lustre/mds/mds_join.c
lustre/mds/mds_lov.c
lustre/mds/mds_open.c
lustre/mds/mds_reint.c
lustre/mds/mds_unlink_open.c
lustre/utils/liblustreapi.c

index b53081a..57f624c 100644 (file)
@@ -451,6 +451,9 @@ extern void lustre_swab_obdo (struct obdo *o);
 #define LOV_PATTERN_FIRST 0x100   /* first stripe is not in round-robin */
 #define LOV_PATTERN_CMOBD 0x200
 
+#define LOV_OBJECT_GROUP_DEFAULT ~0ULL
+#define LOV_OBJECT_GROUP_CLEAR 0ULL
+
 #define lov_ost_data lov_ost_data_v1
 struct lov_ost_data_v1 {          /* per-stripe data structure (little-endian)*/
         __u64 l_object_id;        /* OST object ID */
index c49acd5..edaa77f 100644 (file)
@@ -457,7 +457,8 @@ static int mds_destroy_export(struct obd_export *export)
                        mfd->mfd_dentry->d_name.len,mfd->mfd_dentry->d_name.name,
                        mfd->mfd_dentry->d_inode->i_ino);
 
-                rc = mds_get_md(obd, mfd->mfd_dentry->d_inode, lmm,&lmm_size,1);
+                rc = mds_get_md(obd, mfd->mfd_dentry->d_inode, lmm,
+                                &lmm_size, 1, 0);
                 if (rc < 0)
                         CWARN("mds_get_md failure, rc=%d\n", rc);
                 else
@@ -562,15 +563,18 @@ static int mds_getstatus(struct ptlrpc_request *req)
  * The EA size is also returned on success, and -ve errno on failure. 
  * If there is no EA then 0 is returned. */
 int mds_get_md(struct obd_device *obd, struct inode *inode, void *md,
-               int *size, int lock)
+               int *size, int lock, int flags)
 {
         int rc = 0;
-        int lmm_size;
+        int lmm_size = 0;
 
         if (lock)
                 LOCK_INODE_MUTEX(inode);
         rc = fsfilt_get_md(obd, inode, md, *size, "lov");
 
+        if (rc == 0 && flags == MDS_GETATTR)
+                rc = mds_get_default_md(obd, md, &lmm_size);
+
         if (rc < 0) {
                 CERROR("Error %d reading eadata for ino %lu\n",
                        rc, inode->i_ino);
@@ -597,7 +601,7 @@ int mds_get_md(struct obd_device *obd, struct inode *inode, void *md,
 /* Call with lock=1 if you want mds_pack_md to take the i_mutex.
  * Call with lock=0 if the caller has already taken the i_mutex. */
 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
-                struct mds_body *body, struct inode *inode, int lock)
+                struct mds_body *body, struct inode *inode, int lock, int flags)
 {
         struct mds_obd *mds = &obd->u.mds;
         void *lmm;
@@ -625,7 +629,7 @@ int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
                 // RETURN(-EINVAL);
         }
 
-        rc = mds_get_md(obd, inode, lmm, &lmm_size, lock);
+        rc = mds_get_md(obd, inode, lmm, &lmm_size, lock, flags);
         if (rc > 0) {
                 if (S_ISDIR(inode->i_mode))
                         body->valid |= OBD_MD_FLDIREA;
@@ -692,6 +696,7 @@ static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
         struct mds_body *body;
         struct inode *inode = dentry->d_inode;
         int rc = 0;
+        int flags = 0;
         ENTRY;
 
         if (inode == NULL)
@@ -707,8 +712,12 @@ static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
 
         if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
             (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
+                if (lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR &&
+                   ((S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))))
+                        flags = MDS_GETATTR;
+
                 rc = mds_pack_md(obd, req->rq_repmsg, reply_off, body,
-                                 inode, 1);
+                                 inode, 1, flags);
 
                 /* If we have LOV EA data, the OST holds size, atime, mtime */
                 if (!(body->valid & OBD_MD_FLEASIZE) &&
@@ -803,6 +812,9 @@ static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct inode *inode,
                 UNLOCK_INODE_MUTEX(inode);
                 CDEBUG(D_INODE, "got %d bytes MD data for inode %lu\n",
                        rc, inode->i_ino);
+                if ((rc == 0) && (lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) &&
+                     ((S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))))
+                        rc = sizeof(struct lov_mds_md);
                 if (rc < 0) {
                         if (rc != -ENODATA) {
                                 CERROR("error getting inode %lu MD: rc = %d\n",
index 789a14d..afc27ac 100644 (file)
@@ -205,6 +205,8 @@ int mds_lov_start_synchronize(struct obd_device *obd,
 int mds_post_mds_lovconf(struct obd_device *obd);
 int mds_notify(struct obd_device *obd, struct obd_device *watched,
                enum obd_notify_event ev, void *data);
+int mds_get_default_md(struct obd_device *obd, struct lov_mds_md *lmm,
+                       int *lmmsize);
 int mds_convert_lov_ea(struct obd_device *obd, struct inode *inode,
                        struct lov_mds_md *lmm, int lmm_size);
 void mds_objids_from_lmm(obd_id *ids, struct lov_mds_md *lmm,
@@ -247,9 +249,9 @@ int mds_postrecov(struct obd_device *obd);
 int mds_init_export(struct obd_export *exp);
 #ifdef __KERNEL__
 int mds_get_md(struct obd_device *, struct inode *, void *md, int *size,
-               int lock);
+               int lock, int flags);
 int mds_pack_md(struct obd_device *, struct lustre_msg *, int offset,
-                struct mds_body *, struct inode *, int lock);
+                struct mds_body *, struct inode *, int lock, int flags);
 void mds_pack_inode2fid(struct ll_fid *fid, struct inode *inode);
 void mds_pack_inode2body(struct mds_body *body, struct inode *inode);
 #endif
index 1015d4e..af5ab26 100644 (file)
@@ -295,7 +295,7 @@ static int mds_join_unlink_tail_inode(struct mds_update_record *rec,
                 GOTO(cleanup, rc);
         }
 
-        rc = mds_get_md(obd, tail_inode, tail_lmm, &lmm_size, 1);
+        rc = mds_get_md(obd, tail_inode, tail_lmm, &lmm_size, 1, 0);
         if (rc < 0) /* get md fails */
                 GOTO(cleanup, rc);
 
@@ -383,7 +383,7 @@ int mds_join_file(struct mds_update_record *rec, struct ptlrpc_request *req,
 
         LOCK_INODE_MUTEX(head_inode);
         cleanup_phase = 1;
-        rc = mds_get_md(obd, head_inode, head_lmm, &size, 0);
+        rc = mds_get_md(obd, head_inode, head_lmm, &size, 0, 0);
         if (rc < 0)
                 GOTO(cleanup, rc);
 
index 269c418..6b67e21 100644 (file)
@@ -866,6 +866,28 @@ int mds_notify(struct obd_device *obd, struct obd_device *watched,
         RETURN(rc);
 }
 
+int mds_get_default_md(struct obd_device *obd, struct lov_mds_md *lmm,
+                       int *size)
+{
+        struct lov_desc *ldesc;
+        ENTRY;
+
+        ldesc = &obd->u.mds.mds_lov_desc;
+        LASSERT(ldesc != NULL);
+
+        if (!lmm)
+                RETURN(0);
+
+        lmm->lmm_magic = LOV_MAGIC_V1;
+        lmm->lmm_object_gr = LOV_OBJECT_GROUP_DEFAULT;
+        lmm->lmm_pattern = ldesc->ld_pattern;
+        lmm->lmm_stripe_size = ldesc->ld_default_stripe_size;
+        lmm->lmm_stripe_count = ldesc->ld_default_stripe_count;
+        *size = sizeof(struct lov_mds_md);
+
+        RETURN(sizeof(struct lov_mds_md));
+}
+
 /* Convert the on-disk LOV EA structre.
  * We always try to convert from an old LOV EA format to the common in-memory
  * (lsm) format (obd_unpackmd() understands the old on-disk (lmm) format) and
index a71b663..f287664 100644 (file)
@@ -399,7 +399,7 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset,
 
                         lmm_size = mds->mds_max_mdsize;
                         rc = mds_get_md(obd, dchild->d_parent->d_inode,
-                                        lmm, &lmm_size, 1);
+                                        lmm, &lmm_size, 1, 0);
                         if (rc > 0)
                                 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE,
                                                    mds->mds_osc_exp,
@@ -549,7 +549,7 @@ static void reconstruct_open(struct mds_update_record *rec, int offset,
         mds_pack_inode2body(body, dchild->d_inode);
         if (S_ISREG(dchild->d_inode->i_mode)) {
                 rc = mds_pack_md(obd, req->rq_repmsg, DLM_REPLY_REC_OFF + 1,
-                                 body, dchild->d_inode, 1);
+                                 body, dchild->d_inode, 1, 0);
 
                 if (rc)
                         LASSERT(rc == req->rq_status);
@@ -683,7 +683,7 @@ static int mds_finish_open(struct ptlrpc_request *req, struct dentry *dchild,
         if (S_ISREG(dchild->d_inode->i_mode) &&
             !(body->valid & OBD_MD_FLEASIZE)) {
                 rc = mds_pack_md(obd, req->rq_repmsg, DLM_REPLY_REC_OFF + 1,
-                                 body, dchild->d_inode, 0);
+                                 body, dchild->d_inode, 0, 0);
                 if (rc) {
                         UNLOCK_INODE_MUTEX(dchild->d_inode);
                         RETURN(rc);
@@ -1491,7 +1491,7 @@ int mds_close(struct ptlrpc_request *req, int offset)
                 mds_pack_inode2fid(&body->fid1, inode);
                 mds_pack_inode2body(body, inode);
                 mds_pack_md(obd, req->rq_repmsg, REPLY_REC_OFF + 1, body, inode,
-                            MDS_PACK_MD_LOCK);
+                            MDS_PACK_MD_LOCK, 0);
         }
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
index 1d5e8e8..f09bcc6 100644 (file)
@@ -574,7 +574,7 @@ static int mds_reint_setattr(struct mds_update_record *rec, int offset,
                         GOTO(cleanup, rc = -ENOMEM);
 
                 cleanup_phase = 2;
-                rc = mds_get_md(obd, inode, lmm, &lmm_size, need_lock);
+                rc = mds_get_md(obd, inode, lmm, &lmm_size, need_lock, 0);
                 if (rc < 0)
                         GOTO(cleanup, rc);
                 rc = 0;
@@ -928,7 +928,7 @@ static int mds_reint_create(struct mds_update_record *rec, int offset,
                 if (S_ISDIR(inode->i_mode)) {
                         struct lov_mds_md lmm;
                         int lmm_size = sizeof(lmm);
-                        rc = mds_get_md(obd, dir, &lmm, &lmm_size, 1);
+                        rc = mds_get_md(obd, dir, &lmm, &lmm_size, 1, 0);
                         if (rc > 0) {
                                 LOCK_INODE_MUTEX(inode);
                                 rc = fsfilt_set_md(obd, inode, handle,
@@ -1653,7 +1653,7 @@ static int mds_reint_unlink(struct mds_update_record *rec, int offset,
                         mds_pack_inode2fid(&body->fid1, child_inode);
                         mds_pack_inode2body(body, child_inode);
                         mds_pack_md(obd, req->rq_repmsg, offset + 1, body,
-                                    child_inode, MDS_PACK_MD_LOCK);
+                                    child_inode, MDS_PACK_MD_LOCK, 0);
                 }
         }
 
@@ -2229,7 +2229,7 @@ static int mds_reint_rename(struct mds_update_record *rec, int offset,
                         mds_pack_inode2fid(&body->fid1, new_inode);
                         mds_pack_inode2body(body, new_inode);
                         mds_pack_md(obd, req->rq_repmsg, offset + 1, body,
-                                    new_inode, MDS_PACK_MD_LOCK);
+                                    new_inode, MDS_PACK_MD_LOCK, 0);
                 }
         }
 
index a435df5..053c549 100644 (file)
@@ -127,7 +127,7 @@ static int mds_unlink_orphan(struct obd_device *obd, struct dentry *dchild,
         if (lmm == NULL)
                 RETURN(-ENOMEM);
 
-        rc = mds_get_md(obd, inode, lmm, &lmm_size, 1);
+        rc = mds_get_md(obd, inode, lmm, &lmm_size, 1, 0);
         if (rc < 0)
                 GOTO(out_free_lmm, rc);
 
index e4764d4..9696ea9 100644 (file)
@@ -432,7 +432,11 @@ void lov_dump_user_lmm_v1(struct lov_user_md_v1 *lum, char *path, int is_dir,
         /* if it's a directory */
         if (is_dir) {
                 if (obdstripe == 1) {
-                        printf("default stripe_count: %d stripe_size: %u "
+                        if (lum->lmm_object_gr == LOV_OBJECT_GROUP_DEFAULT) {
+                                printf("(Default) ");
+                                lum->lmm_object_gr = LOV_OBJECT_GROUP_CLEAR;
+                        }
+                        printf("stripe_count: %d stripe_size: %u "
                                "stripe_offset: %d\n",
                                lum->lmm_stripe_count == (__u16)-1 ? -1 :
                                         lum->lmm_stripe_count,