Whamcloud - gitweb
LU-6158 mdt: always shrink_capsule in getxattr_all
[fs/lustre-release.git] / lustre / obdecho / echo.c
index ee854f1..00163bb 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) 2010, 2013, Intel Corporation.
+ * Copyright (c) 2010, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -104,9 +104,9 @@ static int echo_destroy_export(struct obd_export *exp)
         RETURN(0);
 }
 
- static __u64 echo_next_id(struct obd_device *obddev)
+static u64 echo_next_id(struct obd_device *obddev)
 {
-       obd_id id;
+       u64 id;
 
        spin_lock(&obddev->u.echo.eo_lock);
        id = ++obddev->u.echo.eo_lastino;
@@ -116,8 +116,7 @@ static int echo_destroy_export(struct obd_export *exp)
 }
 
 static int echo_create(const struct lu_env *env, struct obd_export *exp,
-                      struct obdo *oa, struct lov_stripe_md **ea,
-                      struct obd_trans_info *oti)
+                      struct obdo *oa)
 {
         struct obd_device *obd = class_exp2obd(exp);
 
@@ -127,10 +126,10 @@ static int echo_create(const struct lu_env *env, struct obd_export *exp,
                 return -EINVAL;
         }
 
-        if (!(oa->o_mode && S_IFMT)) {
-                CERROR("echo obd: no type!\n");
-                return -ENOENT;
-        }
+       if (!(oa->o_mode & S_IFMT)) {
+               CERROR("echo obd: no type!\n");
+               return -ENOENT;
+       }
 
         if (!(oa->o_valid & OBD_MD_FLTYPE)) {
                 CERROR("invalid o_valid "LPX64"\n", oa->o_valid);
@@ -145,9 +144,7 @@ static int echo_create(const struct lu_env *env, struct obd_export *exp,
 }
 
 static int echo_destroy(const struct lu_env *env, struct obd_export *exp,
-                       struct obdo *oa, struct lov_stripe_md *ea,
-                       struct obd_trans_info *oti, struct obd_export *md_exp,
-                       void *capa)
+                       struct obdo *oa)
 {
         struct obd_device *obd = class_exp2obd(exp);
 
@@ -173,66 +170,57 @@ static int echo_destroy(const struct lu_env *env, struct obd_export *exp,
 }
 
 static int echo_getattr(const struct lu_env *env, struct obd_export *exp,
-                        struct obd_info *oinfo)
+                       struct obdo *oa)
 {
        struct obd_device *obd = class_exp2obd(exp);
-       obd_id id = ostid_id(&oinfo->oi_oa->o_oi);
+       u64 id = ostid_id(&oa->o_oi);
 
-        ENTRY;
-        if (!obd) {
-                CERROR("invalid client cookie "LPX64"\n",
-                       exp->exp_handle.h_cookie);
-                RETURN(-EINVAL);
-        }
+       ENTRY;
+       if (!obd) {
+               CERROR("invalid client cookie "LPX64"\n",
+                      exp->exp_handle.h_cookie);
+               RETURN(-EINVAL);
+       }
 
-        if (!(oinfo->oi_oa->o_valid & OBD_MD_FLID)) {
-                CERROR("obdo missing FLID valid flag: "LPX64"\n",
-                       oinfo->oi_oa->o_valid);
-                RETURN(-EINVAL);
-        }
+       if (!(oa->o_valid & OBD_MD_FLID)) {
+               CERROR("obdo missing FLID valid flag: "LPX64"\n", oa->o_valid);
+               RETURN(-EINVAL);
+       }
 
-       obdo_cpy_md(oinfo->oi_oa, &obd->u.echo.eo_oa, oinfo->oi_oa->o_valid);
-       ostid_set_seq_echo(&oinfo->oi_oa->o_oi);
-       ostid_set_id(&oinfo->oi_oa->o_oi, id);
+       obdo_cpy_md(oa, &obd->u.echo.eo_oa, oa->o_valid);
+       ostid_set_seq_echo(&oa->o_oi);
+       ostid_set_id(&oa->o_oi, id);
 
        RETURN(0);
 }
 
 static int echo_setattr(const struct lu_env *env, struct obd_export *exp,
-                        struct obd_info *oinfo, struct obd_trans_info *oti)
+                       struct obdo *oa)
 {
-        struct obd_device *obd = class_exp2obd(exp);
-
-        ENTRY;
-        if (!obd) {
-                CERROR("invalid client cookie "LPX64"\n",
-                       exp->exp_handle.h_cookie);
-                RETURN(-EINVAL);
-        }
+       struct obd_device *obd = class_exp2obd(exp);
 
-        if (!(oinfo->oi_oa->o_valid & OBD_MD_FLID)) {
-                CERROR("obdo missing FLID valid flag: "LPX64"\n",
-                       oinfo->oi_oa->o_valid);
-                RETURN(-EINVAL);
-        }
+       ENTRY;
+       if (!obd) {
+               CERROR("invalid client cookie "LPX64"\n",
+                      exp->exp_handle.h_cookie);
+               RETURN(-EINVAL);
+       }
 
-        memcpy(&obd->u.echo.eo_oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa));
+       if (!(oa->o_valid & OBD_MD_FLID)) {
+               CERROR("obdo missing FLID valid flag: "LPX64"\n", oa->o_valid);
+               RETURN(-EINVAL);
+       }
 
-        if (ostid_id(&oinfo->oi_oa->o_oi) & 4) {
-                /* Save lock to force ACKed reply */
-                ldlm_lock_addref (&obd->u.echo.eo_nl_lock, LCK_NL);
-                oti->oti_ack_locks[0].mode = LCK_NL;
-                oti->oti_ack_locks[0].lock = obd->u.echo.eo_nl_lock;
-        }
+       obd->u.echo.eo_oa = *oa;
 
-        RETURN(0);
+       RETURN(0);
 }
 
 static void
-echo_page_debug_setup(struct page *page, int rw, obd_id id,
+echo_page_debug_setup(struct page *page, int rw, u64 id,
                      __u64 offset, int len)
 {
-       int   page_offset = offset & ~CFS_PAGE_MASK;
+       int   page_offset = offset & ~PAGE_MASK;
        char *addr        = ((char *)kmap(page)) + page_offset;
 
         if (len % OBD_ECHO_BLOCK_SIZE != 0)
@@ -256,10 +244,10 @@ echo_page_debug_setup(struct page *page, int rw, obd_id id,
 }
 
 static int
-echo_page_debug_check(struct page *page, obd_id id,
+echo_page_debug_check(struct page *page, u64 id,
                      __u64 offset, int len)
 {
-       int   page_offset = offset & ~CFS_PAGE_MASK;
+       int   page_offset = offset & ~PAGE_MASK;
        char *addr        = ((char *)kmap(page)) + page_offset;
        int   rc          = 0;
        int   rc2;
@@ -284,22 +272,19 @@ echo_page_debug_check(struct page *page, obd_id id,
        return rc;
 }
 
-/* This allows us to verify that desc_private is passed unmolested */
-#define DESC_PRIV 0x10293847
-
 static int echo_map_nb_to_lb(struct obdo *oa, struct obd_ioobj *obj,
                              struct niobuf_remote *nb, int *pages,
                              struct niobuf_local *lb, int cmd, int *left)
 {
-       int gfp_mask = (ostid_id(&obj->ioo_oid) & 1) ?
+       gfp_t gfp_mask = (ostid_id(&obj->ioo_oid) & 1) ?
                        GFP_HIGHUSER : GFP_IOFS;
        int ispersistent = ostid_id(&obj->ioo_oid) == ECHO_PERSISTENT_OBJID;
        int debug_setup = (!ispersistent &&
                           (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
                           (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
        struct niobuf_local *res = lb;
-       obd_off offset = nb->offset;
-       int len = nb->len;
+       u64 offset = nb->rnb_offset;
+       int len = nb->rnb_len;
 
        while (len > 0) {
                int plen = PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1));
@@ -311,37 +296,38 @@ static int echo_map_nb_to_lb(struct obdo *oa, struct obd_ioobj *obj,
                         return -EINVAL;
 
                res->lnb_file_offset = offset;
-               res->len = plen;
-               LASSERT((res->lnb_file_offset & ~CFS_PAGE_MASK) + res->len <=
-                       PAGE_CACHE_SIZE);
+               res->lnb_len = plen;
+               LASSERT((res->lnb_file_offset & ~PAGE_MASK) +
+                       res->lnb_len <= PAGE_CACHE_SIZE);
 
                if (ispersistent &&
                    ((res->lnb_file_offset >> PAGE_CACHE_SHIFT) <
                      ECHO_PERSISTENT_PAGES)) {
-                       res->page =
+                       res->lnb_page =
                                echo_persistent_pages[res->lnb_file_offset >>
                                                      PAGE_CACHE_SHIFT];
                        /* Take extra ref so __free_pages() can be called OK */
-                       get_page (res->page);
+                       get_page(res->lnb_page);
                } else {
-                        OBD_PAGE_ALLOC(res->page, gfp_mask);
-                        if (res->page == NULL) {
-                                CERROR("can't get page for id " DOSTID"\n",
-                                       POSTID(&obj->ioo_oid));
-                                return -ENOMEM;
-                        }
-                }
+                       res->lnb_page = alloc_page(gfp_mask);
+                       if (res->lnb_page == NULL) {
+                               CERROR("can't get page for id " DOSTID"\n",
+                                      POSTID(&obj->ioo_oid));
+                               return -ENOMEM;
+                       }
+               }
 
-                CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n",
-                      res->page, res->lnb_file_offset, res->len);
+               CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n",
+                      res->lnb_page, res->lnb_file_offset, res->lnb_len);
 
-                if (cmd & OBD_BRW_READ)
-                        res->rc = res->len;
+               if (cmd & OBD_BRW_READ)
+                       res->lnb_rc = res->lnb_len;
 
                if (debug_setup)
-                       echo_page_debug_setup(res->page, cmd,
+                       echo_page_debug_setup(res->lnb_page, cmd,
                                              ostid_id(&obj->ioo_oid),
-                                             res->lnb_file_offset, res->len);
+                                             res->lnb_file_offset,
+                                             res->lnb_len);
 
                 offset += plen;
                 len -= plen;
@@ -359,15 +345,15 @@ static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
                            struct niobuf_local *lb, int verify)
 {
        struct niobuf_local *res = lb;
-       obd_off start  = rb->offset >> PAGE_CACHE_SHIFT;
-       obd_off end    = (rb->offset + rb->len + PAGE_CACHE_SIZE - 1) >>
-                        PAGE_CACHE_SHIFT;
+       u64 start = rb->rnb_offset >> PAGE_CACHE_SHIFT;
+       u64 end   = (rb->rnb_offset + rb->rnb_len + PAGE_CACHE_SIZE - 1) >>
+                   PAGE_CACHE_SHIFT;
        int     count  = (int)(end - start);
        int     rc     = 0;
        int     i;
 
        for (i = 0; i < count; i++, (*pgs) ++, res++) {
-               struct page *page = res->page;
+               struct page *page = res->lnb_page;
                void       *addr;
 
                if (page == NULL) {
@@ -380,13 +366,13 @@ static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
                addr = kmap(page);
 
                CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n",
-                      res->page, addr, res->lnb_file_offset);
+                      res->lnb_page, addr, res->lnb_file_offset);
 
                if (verify) {
                        int vrc = echo_page_debug_check(page,
                                                        ostid_id(&obj->ioo_oid),
                                                        res->lnb_file_offset,
-                                                       res->len);
+                                                       res->lnb_len);
                        /* check all the pages always */
                        if (vrc != 0 && rc == 0)
                                rc = vrc;
@@ -394,7 +380,7 @@ static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
 
                kunmap(page);
                /* NB see comment above regarding persistent pages */
-               OBD_PAGE_FREE(page);
+               __free_page(page);
        }
 
        return rc;
@@ -404,8 +390,7 @@ static int echo_preprw(const struct lu_env *env, int cmd,
                       struct obd_export *export, struct obdo *oa,
                       int objcount, struct obd_ioobj *obj,
                       struct niobuf_remote *nb, int *pages,
-                      struct niobuf_local *res, struct obd_trans_info *oti,
-                      struct lustre_capa *unused)
+                      struct niobuf_local *res)
 {
         struct obd_device *obd;
         int tot_bytes = 0;
@@ -425,9 +410,6 @@ static int echo_preprw(const struct lu_env *env, int cmd,
         CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, *pages);
 
-        if (oti)
-                oti->oti_handle = (void *)DESC_PRIV;
-
         left = *pages;
         *pages = 0;
 
@@ -441,11 +423,11 @@ static int echo_preprw(const struct lu_env *env, int cmd,
                         if (rc)
                                 GOTO(preprw_cleanup, rc);
 
-                        tot_bytes += nb->len;
+                       tot_bytes += nb->rnb_len;
                 }
         }
 
-        cfs_atomic_add(*pages, &obd->u.echo.eo_prep);
+       atomic_add(*pages, &obd->u.echo.eo_prep);
 
         if (cmd & OBD_BRW_READ)
                 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_READ_BYTES,
@@ -455,7 +437,7 @@ static int echo_preprw(const struct lu_env *env, int cmd,
                                     tot_bytes);
 
         CDEBUG(D_PAGE, "%d pages allocated after prep\n",
-               cfs_atomic_read(&obd->u.echo.eo_prep));
+              atomic_read(&obd->u.echo.eo_prep));
 
         RETURN(0);
 
@@ -467,23 +449,22 @@ preprw_cleanup:
          */
         CERROR("cleaning up %u pages (%d obdos)\n", *pages, objcount);
         for (i = 0; i < *pages; i++) {
-               kunmap(res[i].page);
-                /* NB if this is a persistent page, __free_pages will just
-                 * lose the extra ref gained above */
-                OBD_PAGE_FREE(res[i].page);
-                res[i].page = NULL;
-                cfs_atomic_dec(&obd->u.echo.eo_prep);
-        }
+               kunmap(res[i].lnb_page);
+               /* NB if this is a persistent page, __free_page() will just
+                * lose the extra ref gained above */
+               __free_page(res[i].lnb_page);
+               res[i].lnb_page = NULL;
+               atomic_dec(&obd->u.echo.eo_prep);
+       }
 
-        return rc;
+       return rc;
 }
 
 static int echo_commitrw(const struct lu_env *env, int cmd,
                         struct obd_export *export, struct obdo *oa,
                         int objcount, struct obd_ioobj *obj,
                         struct niobuf_remote *rb, int niocount,
-                        struct niobuf_local *res, struct obd_trans_info *oti,
-                        int rc)
+                        struct niobuf_local *res, int rc)
 {
         struct obd_device *obd;
         int pgs = 0;
@@ -510,8 +491,6 @@ static int echo_commitrw(const struct lu_env *env, int cmd,
                 RETURN(-EINVAL);
         }
 
-        LASSERT(oti == NULL || oti->oti_handle == (void *)DESC_PRIV);
-
        for (i = 0; i < objcount; i++, obj++) {
                int verify = (rc == 0 &&
                             ostid_id(&obj->ioo_oid) != ECHO_PERSISTENT_OBJID &&
@@ -534,35 +513,36 @@ static int echo_commitrw(const struct lu_env *env, int cmd,
 
        }
 
-        cfs_atomic_sub(pgs, &obd->u.echo.eo_prep);
+       atomic_sub(pgs, &obd->u.echo.eo_prep);
 
         CDEBUG(D_PAGE, "%d pages remain after commit\n",
-               cfs_atomic_read(&obd->u.echo.eo_prep));
+              atomic_read(&obd->u.echo.eo_prep));
         RETURN(rc);
 
 commitrw_cleanup:
-        cfs_atomic_sub(pgs, &obd->u.echo.eo_prep);
+       atomic_sub(pgs, &obd->u.echo.eo_prep);
 
-        CERROR("cleaning up %d pages (%d obdos)\n",
-               niocount - pgs - 1, objcount);
+       CERROR("cleaning up %d pages (%d obdos)\n",
+              niocount - pgs - 1, objcount);
 
-        while (pgs < niocount) {
-               struct page *page = res[pgs++].page;
+       while (pgs < niocount) {
+               struct page *page = res[pgs++].lnb_page;
 
-                if (page == NULL)
-                        continue;
+               if (page == NULL)
+                       continue;
 
-                /* NB see comment above regarding persistent pages */
-                OBD_PAGE_FREE(page);
-                cfs_atomic_dec(&obd->u.echo.eo_prep);
-        }
-        return rc;
+               /* NB see comment above regarding persistent pages */
+               __free_page(page);
+               atomic_dec(&obd->u.echo.eo_prep);
+       }
+       return rc;
 }
 
 LPROC_SEQ_FOPS_RO_TYPE(echo, uuid);
-static struct lprocfs_seq_vars lprocfs_echo_obd_vars[] = {
-       { "uuid",       &echo_uuid_fops         },
-       { 0 }
+static struct lprocfs_vars lprocfs_echo_obd_vars[] = {
+       { .name =       "uuid",
+         .fops =       &echo_uuid_fops         },
+       { NULL }
 };
 
 static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
@@ -594,7 +574,7 @@ static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
         LASSERT (rc == ELDLM_OK);
 
        obd->obd_vars = lprocfs_echo_obd_vars;
-       if (lprocfs_seq_obd_setup(obd) == 0 &&
+       if (lprocfs_obd_setup(obd) == 0 &&
             lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST) == 0) {
                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES,
                                      LPROCFS_CNTR_AVGMINMAX,
@@ -604,8 +584,8 @@ static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                                      "write_bytes", "bytes");
         }
 
-        ptlrpc_init_client (LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
-                            "echo_ldlm_cb_client", &obd->obd_ldlm_client);
+       ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
+                          "echo_ldlm_cb_client", &obd->obd_ldlm_client);
         RETURN(0);
 }
 
@@ -621,12 +601,13 @@ static int echo_cleanup(struct obd_device *obd)
 
        /* XXX Bug 3413; wait for a bit to ensure the BL callback has
         * happened before calling ldlm_namespace_free() */
-       schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, cfs_time_seconds(1));
+       set_current_state(TASK_UNINTERRUPTIBLE);
+       schedule_timeout(cfs_time_seconds(1));
 
        ldlm_namespace_free(obd->obd_namespace, NULL, obd->obd_force);
        obd->obd_namespace = NULL;
 
-       leaked = cfs_atomic_read(&obd->u.echo.eo_prep);
+       leaked = atomic_read(&obd->u.echo.eo_prep);
        if (leaked != 0)
                CERROR("%d prep/commitrw pages leaked\n", leaked);
 
@@ -651,13 +632,13 @@ struct obd_ops echo_obd_ops = {
 
 void echo_persistent_pages_fini(void)
 {
-        int     i;
+       int i;
 
-        for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
-                if (echo_persistent_pages[i] != NULL) {
-                        OBD_PAGE_FREE(echo_persistent_pages[i]);
-                        echo_persistent_pages[i] = NULL;
-                }
+       for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
+               if (echo_persistent_pages[i] != NULL) {
+                       __free_page(echo_persistent_pages[i]);
+                       echo_persistent_pages[i] = NULL;
+               }
 }
 
 int echo_persistent_pages_init(void)
@@ -666,10 +647,10 @@ int echo_persistent_pages_init(void)
        int          i;
 
        for (i = 0; i < ECHO_PERSISTENT_PAGES; i++) {
-               int gfp_mask = (i < ECHO_PERSISTENT_PAGES/2) ?
+               gfp_t gfp_mask = (i < ECHO_PERSISTENT_PAGES/2) ?
                        GFP_IOFS : GFP_HIGHUSER;
 
-               OBD_PAGE_ALLOC(pg, gfp_mask);
+               pg = alloc_page(gfp_mask);
                if (pg == NULL) {
                        echo_persistent_pages_fini();
                        return -ENOMEM;