Whamcloud - gitweb
LU-3267 utils: missing setting echo seq for getattr/setattr
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index 6df84fc..bbb5f52 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -174,14 +174,6 @@ struct echo_object_conf *cl2echo_conf(const struct cl_object_conf *c)
         return container_of(c, struct echo_object_conf, eoc_cl);
 }
 
-static inline void lsm2fid(struct lov_stripe_md *lsm, struct lu_fid *fid)
-{
-        fid_zero(fid);
-        fid->f_seq = FID_SEQ_ECHO;
-        /* truncated to 32 bits by assignment */
-        fid->f_oid = lsm->lsm_object_id;
-        fid->f_ver = lsm->lsm_object_id >> 32;
-}
 /** @} echo_helpers */
 
 static struct echo_object *cl_echo_object_find(struct echo_device *d,
@@ -543,6 +535,7 @@ static int echo_alloc_memmd(struct echo_device *ed,
 
        loi_init((*lsmp)->lsm_oinfo[0]);
        (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
+       ostid_set_seq_echo(&(*lsmp)->lsm_oi);
 
        RETURN(lsm_size);
 }
@@ -1086,12 +1079,15 @@ static struct echo_object *cl_echo_object_find(struct echo_device *d,
         struct cl_object   *obj;
         struct lu_fid *fid;
         int refcheck;
-        ENTRY;
+       int rc;
+       ENTRY;
 
-        LASSERT(lsmp);
-        lsm = *lsmp;
-        LASSERT(lsm);
-        LASSERT(lsm->lsm_object_id);
+       LASSERT(lsmp);
+       lsm = *lsmp;
+       LASSERT(lsm);
+       LASSERTF(ostid_id(&lsm->lsm_oi) != 0, DOSTID"\n", POSTID(&lsm->lsm_oi));
+       LASSERTF(ostid_seq(&lsm->lsm_oi) == FID_SEQ_ECHO, DOSTID"\n",
+                POSTID(&lsm->lsm_oi));
 
         /* Never return an object if the obd is to be freed. */
         if (echo_dev2cl(d)->cd_lu_dev.ld_obd->obd_stopping)
@@ -1107,8 +1103,7 @@ static struct echo_object *cl_echo_object_find(struct echo_device *d,
                 if (!d->ed_next_islov) {
                         struct lov_oinfo *oinfo = lsm->lsm_oinfo[0];
                         LASSERT(oinfo != NULL);
-                        oinfo->loi_id = lsm->lsm_object_id;
-                        oinfo->loi_seq = lsm->lsm_object_seq;
+                       oinfo->loi_oi = lsm->lsm_oi;
                         conf->eoc_cl.u.coc_oinfo = oinfo;
                 } else {
                         struct lustre_md *md;
@@ -1120,8 +1115,10 @@ static struct echo_object *cl_echo_object_find(struct echo_device *d,
         }
         conf->eoc_md = lsmp;
 
-        fid  = &info->eti_fid;
-        lsm2fid(lsm, fid);
+       fid  = &info->eti_fid;
+       rc = ostid_to_fid(fid, &lsm->lsm_oi, 0);
+       if (rc != 0)
+               GOTO(out, eco = ERR_PTR(rc));
 
        /* In the function below, .hs_keycmp resolves to
         * lu_obj_hop_keycmp() */
@@ -1956,12 +1953,12 @@ static int echo_md_destroy_internal(const struct lu_env *env,
         CDEBUG(D_RPCTRACE, "Start destroy object "DFID" %s %p\n",
                PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
 
-        rc = mdo_unlink(env, parent, lu2md(child), lname, ma);
-        if (rc) {
-                CERROR("Can not unlink child %s: rc = %d\n",
-                        lname->ln_name, rc);
-                GOTO(out_put, rc);
-        }
+       rc = mdo_unlink(env, parent, lu2md(child), lname, ma, 0);
+       if (rc) {
+               CERROR("Can not unlink child %s: rc = %d\n",
+                       lname->ln_name, rc);
+               GOTO(out_put, rc);
+       }
         CDEBUG(D_RPCTRACE, "End destroy object "DFID" %s %p\n",
                PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
 out_put:
@@ -2125,8 +2122,8 @@ static void echo_ucred_fini(struct lu_env *env)
 #define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
 #define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION)
 static int echo_md_handler(struct echo_device *ed, int command,
-                           char *path, int path_len, int id, int count,
-                           struct obd_ioctl_data *data)
+                          char *path, int path_len, __u64 id, int count,
+                          struct obd_ioctl_data *data)
 {
        struct echo_thread_info *info;
         struct lu_device      *ld = ed->ed_next;
@@ -2190,9 +2187,10 @@ static int echo_md_handler(struct echo_device *ed, int command,
                 int stripe_count = (int)data->ioc_obdo2.o_misc;
                 int stripe_index = (int)data->ioc_obdo2.o_stripe_idx;
 
-                fid->f_seq = data->ioc_obdo1.o_seq;
-                fid->f_oid = (__u32)data->ioc_obdo1.o_id;
-                fid->f_ver = 0;
+               rc = ostid_to_fid(fid, &data->ioc_obdo1.o_oi, 0);
+               if (rc != 0)
+                       break;
+
                /* In the function below, .hs_keycmp resolves to
                 * lu_obj_hop_keycmp() */
                /* coverity[overrun-buffer-val] */
@@ -2279,38 +2277,40 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
 
                 idx = cfs_rand();
 
-                /* setup stripes: indices + default ids if required */
-                for (i = 0; i < lsm->lsm_stripe_count; i++) {
-                        if (lsm->lsm_oinfo[i]->loi_id == 0)
-                                lsm->lsm_oinfo[i]->loi_id = lsm->lsm_object_id;
+               /* setup stripes: indices + default ids if required */
+               for (i = 0; i < lsm->lsm_stripe_count; i++) {
+                       if (ostid_id(&lsm->lsm_oinfo[i]->loi_oi) == 0)
+                               lsm->lsm_oinfo[i]->loi_oi = lsm->lsm_oi;
 
-                        lsm->lsm_oinfo[i]->loi_ost_idx =
-                                (idx + i) % ec->ec_nstripes;
-                }
+                       lsm->lsm_oinfo[i]->loi_ost_idx =
+                               (idx + i) % ec->ec_nstripes;
+               }
         }
 
-        /* setup object ID here for !on_target and LOV hint */
-        if (oa->o_valid & OBD_MD_FLID)
-                lsm->lsm_object_id = oa->o_id;
+       /* setup object ID here for !on_target and LOV hint */
+       if (oa->o_valid & OBD_MD_FLID) {
+               LASSERT(oa->o_valid & OBD_MD_FLGROUP);
+               lsm->lsm_oi = oa->o_oi;
+       }
 
-        if (lsm->lsm_object_id == 0)
-                lsm->lsm_object_id = ++last_object_id;
+       if (ostid_id(&lsm->lsm_oi) == 0)
+               ostid_set_id(&lsm->lsm_oi, ++last_object_id);
 
         rc = 0;
-        if (on_target) {
-                /* Only echo objects are allowed to be created */
-                LASSERT((oa->o_valid & OBD_MD_FLGROUP) &&
-                        (oa->o_seq == FID_SEQ_ECHO));
-                rc = obd_create(env, ec->ec_exp, oa, &lsm, oti);
-                if (rc != 0) {
-                        CERROR("Cannot create objects: rc = %d\n", rc);
-                        GOTO(failed, rc);
-                }
-                created = 1;
-        }
+       if (on_target) {
+               /* Only echo objects are allowed to be created */
+               LASSERT((oa->o_valid & OBD_MD_FLGROUP) &&
+                       (ostid_seq(&oa->o_oi) == FID_SEQ_ECHO));
+               rc = obd_create(env, ec->ec_exp, oa, &lsm, oti);
+               if (rc != 0) {
+                       CERROR("Cannot create objects: rc = %d\n", rc);
+                       GOTO(failed, rc);
+               }
+               created = 1;
+       }
 
         /* See what object ID we were given */
-        oa->o_id = lsm->lsm_object_id;
+       oa->o_oi = lsm->lsm_oi;
         oa->o_valid |= OBD_MD_FLID;
 
         eco = cl_echo_object_find(ed, &lsm);
@@ -2318,7 +2318,7 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
                 GOTO(failed, rc = PTR_ERR(eco));
         cl_echo_object_put(eco);
 
-        CDEBUG(D_INFO, "oa->o_id = %lx\n", (long)oa->o_id);
+        CDEBUG(D_INFO, "oa oid "DOSTID"\n", POSTID(&oa->o_oi));
         EXIT;
 
  failed:
@@ -2339,9 +2339,8 @@ static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
         int                     rc;
         ENTRY;
 
-        if ((oa->o_valid & OBD_MD_FLID) == 0 ||
-            oa->o_id == 0)  /* disallow use of object id 0 */
-        {
+        if ((oa->o_valid & OBD_MD_FLID) == 0 || ostid_id(&oa->o_oi) == 0) {
+               /* disallow use of object id 0 */
                 CERROR ("No valid oid\n");
                 RETURN(-EINVAL);
         }
@@ -2350,11 +2349,9 @@ static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
         if (rc < 0)
                 RETURN(rc);
 
-        lsm->lsm_object_id = oa->o_id;
-        if (oa->o_valid & OBD_MD_FLGROUP)
-                lsm->lsm_object_seq = oa->o_seq;
-        else
-                lsm->lsm_object_seq = FID_SEQ_ECHO;
+       lsm->lsm_oi = oa->o_oi;
+       if (!(oa->o_valid & OBD_MD_FLGROUP))
+               ostid_set_seq_echo(&lsm->lsm_oi);
 
         rc = 0;
         eco = cl_echo_object_find(ed, &lsm);
@@ -2398,8 +2395,8 @@ echo_get_stripe_off_id (struct lov_stripe_md *lsm, obd_off *offp, obd_id *idp)
 
         stripe_index = woffset / stripe_size;
 
-        *idp = lsm->lsm_oinfo[stripe_index]->loi_id;
-        *offp = offset * stripe_size + woffset % stripe_size;
+       *idp = ostid_id(&lsm->lsm_oinfo[stripe_index]->loi_oi);
+       *offp = offset * stripe_size + woffset % stripe_size;
 }
 
 static void
@@ -2485,15 +2482,15 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
         int                     brw_flags = 0;
         ENTRY;
 
-        verify = ((oa->o_id) != ECHO_PERSISTENT_OBJID &&
+        verify = (ostid_id(&oa->o_oi) != ECHO_PERSISTENT_OBJID &&
                   (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
                   (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
 
-        gfp_mask = ((oa->o_id & 2) == 0) ? CFS_ALLOC_STD : CFS_ALLOC_HIGHUSER;
+        gfp_mask = ((ostid_id(&oa->o_oi) & 2) == 0) ? CFS_ALLOC_STD : CFS_ALLOC_HIGHUSER;
 
-        LASSERT(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ);
-        LASSERT(lsm != NULL);
-        LASSERT(lsm->lsm_object_id == oa->o_id);
+       LASSERT(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ);
+       LASSERT(lsm != NULL);
+       LASSERT(ostid_id(&lsm->lsm_oi) == ostid_id(&oa->o_oi));
 
         if (count <= 0 ||
             (count & (~CFS_PAGE_MASK)) != 0)
@@ -2531,9 +2528,10 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                 pgp->off = off;
                 pgp->flag = brw_flags;
 
-                if (verify)
-                        echo_client_page_debug_setup(lsm, pgp->pg, rw,
-                                                     oa->o_id, off, pgp->count);
+               if (verify)
+                       echo_client_page_debug_setup(lsm, pgp->pg, rw,
+                                                    ostid_id(&oa->o_oi), off,
+                                                    pgp->count);
         }
 
         /* brw mode can only be used at client */
@@ -2548,14 +2546,15 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                 if (pgp->pg == NULL)
                         continue;
 
-                if (verify) {
-                        int vrc;
-                        vrc = echo_client_page_debug_check(lsm, pgp->pg, oa->o_id,
-                                                           pgp->off, pgp->count);
-                        if (vrc != 0 && rc == 0)
-                                rc = vrc;
-                }
-                OBD_PAGE_FREE(pgp->pg);
+               if (verify) {
+                       int vrc;
+                       vrc = echo_client_page_debug_check(lsm, pgp->pg,
+                                                          ostid_id(&oa->o_oi),
+                                                          pgp->off, pgp->count);
+                       if (vrc != 0 && rc == 0)
+                               rc = vrc;
+               }
+               OBD_PAGE_FREE(pgp->pg);
         }
         OBD_FREE(pga, npages * sizeof(*pga));
         OBD_FREE(pages, npages * sizeof(*pages));
@@ -2579,9 +2578,9 @@ static int echo_client_prep_commit(const struct lu_env *env,
 
         ENTRY;
 
-        if (count <= 0 || (count & (~CFS_PAGE_MASK)) != 0 ||
-            (lsm != NULL && lsm->lsm_object_id != oa->o_id))
-                RETURN(-EINVAL);
+       if (count <= 0 || (count & (~CFS_PAGE_MASK)) != 0 ||
+           (lsm != NULL && ostid_id(&lsm->lsm_oi) != ostid_id(&oa->o_oi)))
+               RETURN(-EINVAL);
 
         npages = batch >> CFS_PAGE_SHIFT;
         tot_pages = count >> CFS_PAGE_SHIFT;
@@ -2631,22 +2630,22 @@ static int echo_client_prep_commit(const struct lu_env *env,
                         if (async)
                                 lnb[i].flags |= OBD_BRW_ASYNC;
 
-                        if (oa->o_id == ECHO_PERSISTENT_OBJID ||
-                            (oa->o_valid & OBD_MD_FLFLAGS) == 0 ||
-                            (oa->o_flags & OBD_FL_DEBUG_CHECK) == 0)
-                                continue;
-
-                        if (rw == OBD_BRW_WRITE)
-                                echo_client_page_debug_setup(lsm, page, rw,
-                                                             oa->o_id,
-                                                             rnb[i].offset,
-                                                             rnb[i].len);
-                        else
-                                echo_client_page_debug_check(lsm, page,
-                                                             oa->o_id,
-                                                             rnb[i].offset,
-                                                             rnb[i].len);
-                }
+                       if (ostid_id(&oa->o_oi) == ECHO_PERSISTENT_OBJID ||
+                           (oa->o_valid & OBD_MD_FLFLAGS) == 0 ||
+                           (oa->o_flags & OBD_FL_DEBUG_CHECK) == 0)
+                               continue;
+
+                       if (rw == OBD_BRW_WRITE)
+                               echo_client_page_debug_setup(lsm, page, rw,
+                                                           ostid_id(&oa->o_oi),
+                                                            rnb[i].offset,
+                                                            rnb[i].len);
+                       else
+                               echo_client_page_debug_check(lsm, page,
+                                                           ostid_id(&oa->o_oi),
+                                                            rnb[i].offset,
+                                                            rnb[i].len);
+               }
 
                ret = obd_commitrw(env, rw, exp, oa, 1, &ioo,
                                   rnb, npages, lnb, oti, ret);
@@ -2792,14 +2791,14 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
         memset(&dummy_oti, 0, sizeof(dummy_oti));
 
-        oa = &data->ioc_obdo1;
-        if (!(oa->o_valid & OBD_MD_FLGROUP)) {
-                oa->o_valid |= OBD_MD_FLGROUP;
-                oa->o_seq = FID_SEQ_ECHO;
-        }
+       oa = &data->ioc_obdo1;
+       if (!(oa->o_valid & OBD_MD_FLGROUP)) {
+               oa->o_valid |= OBD_MD_FLGROUP;
+               ostid_set_seq_echo(&oa->o_oi);
+       }
 
         /* This FID is unpacked just for validation at this point */
-        rc = fid_ostid_unpack(&fid, &oa->o_oi, 0);
+        rc = ostid_to_fid(&fid, &oa->o_oi, 0);
         if (rc < 0)
                 RETURN(rc);
 
@@ -2820,35 +2819,35 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                                         data->ioc_plen1, &dummy_oti);
                 GOTO(out, rc);
 
-        case OBD_IOC_ECHO_MD: {
-                int count;
-                int cmd;
-                char *dir = NULL;
-                int dirlen;
-                __u64 id;
+       case OBD_IOC_ECHO_MD: {
+               int count;
+               int cmd;
+               char *dir = NULL;
+               int dirlen;
+               __u64 id;
 
-                if (!cfs_capable(CFS_CAP_SYS_ADMIN))
-                        GOTO(out, rc = -EPERM);
+               if (!cfs_capable(CFS_CAP_SYS_ADMIN))
+                       GOTO(out, rc = -EPERM);
 
-                count = data->ioc_count;
-                cmd = data->ioc_command;
+               count = data->ioc_count;
+               cmd = data->ioc_command;
 
-                id = data->ioc_obdo2.o_id;
+               id = ostid_id(&data->ioc_obdo2.o_oi);
 
-                dirlen = data->ioc_plen1;
-                OBD_ALLOC(dir, dirlen + 1);
-                if (dir == NULL)
-                        GOTO(out, rc = -ENOMEM);
+               dirlen = data->ioc_plen1;
+               OBD_ALLOC(dir, dirlen + 1);
+               if (dir == NULL)
+                       GOTO(out, rc = -ENOMEM);
 
-                if (cfs_copy_from_user(dir, data->ioc_pbuf1, dirlen)) {
-                        OBD_FREE(dir, data->ioc_plen1 + 1);
-                        GOTO(out, rc = -EFAULT);
-                }
+               if (cfs_copy_from_user(dir, data->ioc_pbuf1, dirlen)) {
+                       OBD_FREE(dir, data->ioc_plen1 + 1);
+                       GOTO(out, rc = -EFAULT);
+               }
 
-                rc = echo_md_handler(ed, cmd, dir, dirlen, id, count, data);
-                OBD_FREE(dir, dirlen + 1);
-                GOTO(out, rc);
-        }
+               rc = echo_md_handler(ed, cmd, dir, dirlen, id, count, data);
+               OBD_FREE(dir, dirlen + 1);
+               GOTO(out, rc);
+       }
         case OBD_IOC_ECHO_ALLOC_SEQ: {
                 struct lu_env   *cl_env;
                 int              refcheck;