Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
index 26192b4..f8d1845 100644 (file)
@@ -75,18 +75,24 @@ echo_find_object_locked (struct obd_device *obd, obd_id id)
 }
 
 static int
-echo_copyout_lsm (struct lov_stripe_md *lsm, void *ulsm, int ulsm_nob)
+echo_copyout_lsm (struct lov_stripe_md *lsm, void *_ulsm, int ulsm_nob)
 {
-        int nob;
+        struct lov_stripe_md *ulsm = _ulsm;
+        int nob, i;
 
         nob = offsetof (struct lov_stripe_md, lsm_oinfo[lsm->lsm_stripe_count]);
         if (nob > ulsm_nob)
                 return (-EINVAL);
 
-        if (copy_to_user (ulsm, lsm, nob))
+        if (copy_to_user (ulsm, lsm, sizeof(ulsm)))
                 return (-EFAULT);
 
-        return (0);
+        for (i = 0; i < lsm->lsm_stripe_count; i++) {
+                if (copy_to_user (ulsm->lsm_oinfo[i], lsm->lsm_oinfo[i],
+                                  sizeof(lsm->lsm_oinfo[0])))
+                        return (-EFAULT);
+        }
+        return 0;
 }
 
 static int
@@ -94,7 +100,7 @@ echo_copyin_lsm (struct obd_device *obd, struct lov_stripe_md *lsm,
                  void *ulsm, int ulsm_nob)
 {
         struct echo_client_obd *ec = &obd->u.echo_client;
-        int                     nob;
+        int                     i;
 
         if (ulsm_nob < sizeof (*lsm))
                 return (-EINVAL);
@@ -102,19 +108,19 @@ echo_copyin_lsm (struct obd_device *obd, struct lov_stripe_md *lsm,
         if (copy_from_user (lsm, ulsm, sizeof (*lsm)))
                 return (-EFAULT);
 
-        nob = lsm->lsm_stripe_count * sizeof (lsm->lsm_oinfo[0]);
-
-        if (ulsm_nob < nob ||
-            lsm->lsm_stripe_count > ec->ec_nstripes ||
+        if (lsm->lsm_stripe_count > ec->ec_nstripes ||
             lsm->lsm_magic != LOV_MAGIC ||
             (lsm->lsm_stripe_size & (~CFS_PAGE_MASK)) != 0 ||
             ((__u64)lsm->lsm_stripe_size * lsm->lsm_stripe_count > ~0UL))
                 return (-EINVAL);
 
-        if (copy_from_user(lsm->lsm_oinfo,
-                           ((struct lov_stripe_md *)ulsm)->lsm_oinfo, nob))
-                return (-EFAULT);
 
+        for (i = 0; i < lsm->lsm_stripe_count; i++) {
+                if (copy_from_user(lsm->lsm_oinfo[i],
+                                   ((struct lov_stripe_md *)ulsm)->lsm_oinfo[i],
+                                   sizeof(lsm->lsm_oinfo[0])))
+                        return (-EFAULT);
+        }
         return (0);
 }
 
@@ -151,9 +157,9 @@ echo_free_object (struct ec_object *eco)
         struct echo_client_obd *ec = &obd->u.echo_client;
 
         LASSERT (eco->eco_refcount == 0);
-        if (!eco->eco_lsm) 
+        if (!eco->eco_lsm)
                 CERROR("No object %s\n", obd->obd_name);
-        else 
+        else
                 obd_free_memmd(ec->ec_exp, &eco->eco_lsm);
         OBD_FREE (eco, sizeof (*eco));
 }
@@ -178,7 +184,7 @@ static int echo_create_object(struct obd_device *obd, int on_target,
 
         if (ulsm != NULL) {
                 eco = echo_allocate_object (obd);
-                if (eco == NULL) 
+                if (eco == NULL)
                         return (-ENOMEM);
 
                 lsm = eco->eco_lsm;
@@ -201,10 +207,10 @@ static int echo_create_object(struct obd_device *obd, int on_target,
 
                 /* 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;
+                        if (lsm->lsm_oinfo[i]->loi_id == 0)
+                                lsm->lsm_oinfo[i]->loi_id = lsm->lsm_object_id;
 
-                        lsm->lsm_oinfo[i].loi_ost_idx =
+                        lsm->lsm_oinfo[i]->loi_ost_idx =
                                 (idx + i) % ec->ec_nstripes;
                 }
         } else {
@@ -257,7 +263,7 @@ static int echo_create_object(struct obd_device *obd, int on_target,
                 eco, eco->eco_id,
                 eco->eco_lsm->lsm_stripe_size,
                 eco->eco_lsm->lsm_stripe_count,
-                eco->eco_lsm->lsm_oinfo[0].loi_ost_idx,
+                eco->eco_lsm->lsm_oinfo[0]->loi_ost_idx,
                 eco->eco_refcount, eco->eco_deleted);
         return (0);
 
@@ -300,7 +306,7 @@ echo_get_object (struct ec_object **ecop, struct obd_device *obd,
                         eco, eco->eco_id,
                         eco->eco_lsm->lsm_stripe_size,
                         eco->eco_lsm->lsm_stripe_count,
-                        eco->eco_lsm->lsm_oinfo[0].loi_ost_idx,
+                        eco->eco_lsm->lsm_oinfo[0]->loi_ost_idx,
                         eco->eco_refcount, eco->eco_deleted);
                 return (0);
         }
@@ -328,7 +334,7 @@ echo_get_object (struct ec_object **ecop, struct obd_device *obd,
                         eco, eco->eco_id,
                         eco->eco_lsm->lsm_stripe_size,
                         eco->eco_lsm->lsm_stripe_count,
-                        eco->eco_lsm->lsm_oinfo[0].loi_ost_idx,
+                        eco->eco_lsm->lsm_oinfo[0]->loi_ost_idx,
                         eco->eco_refcount, eco->eco_deleted);
                 return (0);
         }
@@ -345,7 +351,7 @@ echo_get_object (struct ec_object **ecop, struct obd_device *obd,
                         eco2, eco2->eco_id,
                         eco2->eco_lsm->lsm_stripe_size,
                         eco2->eco_lsm->lsm_stripe_count,
-                        eco2->eco_lsm->lsm_oinfo[0].loi_ost_idx,
+                        eco2->eco_lsm->lsm_oinfo[0]->loi_ost_idx,
                         eco2->eco_refcount, eco2->eco_deleted);
         }
 
@@ -374,7 +380,7 @@ echo_put_object (struct ec_object *eco)
                eco, eco->eco_id,
                eco->eco_lsm->lsm_stripe_size,
                eco->eco_lsm->lsm_stripe_count,
-               eco->eco_lsm->lsm_oinfo[0].loi_ost_idx,
+               eco->eco_lsm->lsm_oinfo[0]->loi_ost_idx,
                eco->eco_refcount, eco->eco_deleted);
 
         if (eco->eco_refcount != 0 || !eco->eco_deleted) {
@@ -425,13 +431,13 @@ 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;
+        *idp = lsm->lsm_oinfo[stripe_index]->loi_id;
         *offp = offset * stripe_size + woffset % stripe_size;
 }
 
-static void 
-echo_client_page_debug_setup(struct lov_stripe_md *lsm, 
-                             cfs_page_t *page, int rw, obd_id id, 
+static void
+echo_client_page_debug_setup(struct lov_stripe_md *lsm,
+                             cfs_page_t *page, int rw, obd_id id,
                              obd_off offset, obd_off count)
 {
         char    *addr;
@@ -453,17 +459,16 @@ echo_client_page_debug_setup(struct lov_stripe_md *lsm,
                         stripe_off = 0xdeadbeef00c0ffeeULL;
                         stripe_id = 0xdeadbeef00c0ffeeULL;
                 }
-                block_debug_setup(addr + delta, OBD_ECHO_BLOCK_SIZE, 
+                block_debug_setup(addr + delta, OBD_ECHO_BLOCK_SIZE,
                                   stripe_off, stripe_id);
         }
 
         cfs_kunmap(page);
 }
 
-static int
-echo_client_page_debug_check(struct lov_stripe_md *lsm, 
-                             cfs_page_t *page, obd_id id, 
-                             obd_off offset, obd_off count)
+static int echo_client_page_debug_check(struct lov_stripe_md *lsm,
+                                        cfs_page_t *page, obd_id id,
+                                        obd_off offset, obd_off count)
 {
         obd_off stripe_off;
         obd_id  stripe_id;
@@ -482,8 +487,8 @@ echo_client_page_debug_check(struct lov_stripe_md *lsm,
                 stripe_id = id;
                 echo_get_stripe_off_id (lsm, &stripe_off, &stripe_id);
 
-                rc2 = block_debug_check("test_brw", 
-                                        addr + delta, OBD_ECHO_BLOCK_SIZE, 
+                rc2 = block_debug_check("test_brw",
+                                        addr + delta, OBD_ECHO_BLOCK_SIZE,
                                         stripe_off, stripe_id);
                 if (rc2 != 0) {
                         CERROR ("Error in echo object "LPX64"\n", id);
@@ -538,7 +543,7 @@ static int echo_client_kbrw(struct obd_device *obd, int rw, struct obdo *oa,
                 LASSERT (pgp->pg == NULL);      /* for cleanup */
 
                 rc = -ENOMEM;
-                pgp->pg = cfs_alloc_page (gfp_mask);
+                OBD_PAGE_ALLOC(pgp->pg, gfp_mask);
                 if (pgp->pg == NULL)
                         goto out;
 
@@ -570,95 +575,11 @@ static int echo_client_kbrw(struct obd_device *obd, int rw, struct obdo *oa,
                         if (vrc != 0 && rc == 0)
                                 rc = vrc;
                 }
-                cfs_free_page(pgp->pg);
-        }
-        OBD_FREE(pga, npages * sizeof(*pga));
-        return (rc);
-}
-
-#ifdef __KERNEL__
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-#include <linux/iobuf.h>
-
-static int echo_client_ubrw(struct obd_device *obd, int rw,
-                            struct obdo *oa, struct lov_stripe_md *lsm,
-                            obd_off offset, obd_size count, char *buffer,
-                            struct obd_trans_info *oti)
-{
-        struct echo_client_obd *ec = &obd->u.echo_client;
-        struct obd_info         oinfo = { { { 0 } } };
-        obd_count               npages;
-        struct brw_page        *pga;
-        struct brw_page        *pgp;
-        obd_off                 off;
-        struct kiobuf          *kiobuf;
-        int                     i;
-        int                     rc;
-
-        LASSERT (rw == OBD_BRW_WRITE || rw == OBD_BRW_READ);
-
-        /* NB: for now, only whole pages, page aligned */
-
-        if (count <= 0 ||
-            ((long)buffer & (~CFS_PAGE_MASK)) != 0 ||
-            (count & (~CFS_PAGE_MASK)) != 0 ||
-            (lsm != NULL && lsm->lsm_object_id != oa->o_id))
-                return (-EINVAL);
-
-        /* XXX think again with misaligned I/O */
-        npages = count >> CFS_PAGE_SHIFT;
-
-        OBD_ALLOC(pga, npages * sizeof(*pga));
-        if (pga == NULL)
-                return (-ENOMEM);
-
-        rc = alloc_kiovec (1, &kiobuf);
-        if (rc != 0)
-                goto out_1;
-
-        rc = map_user_kiobuf ((rw == OBD_BRW_READ) ? READ : WRITE,
-                              kiobuf, (unsigned long)buffer, count);
-        if (rc != 0)
-                goto out_2;
-
-        LASSERT (kiobuf->offset == 0);
-        LASSERT (kiobuf->nr_pages == npages);
-
-        for (i = 0, off = offset, pgp = pga;
-             i < npages;
-             i++, off += CFS_PAGE_SIZE, pgp++) {
-                pgp->off = off;
-                pgp->pg = kiobuf->maplist[i];
-                pgp->count = CFS_PAGE_SIZE;
-                pgp->flag = 0;
+                OBD_PAGE_FREE(pgp->pg);
         }
-
-        oinfo.oi_oa = oa;
-        oinfo.oi_md = lsm;
-        rc = obd_brw(rw, ec->ec_exp, &oinfo, npages, pga, oti);
-
-        //        if (rw == OBD_BRW_READ)
-        //                mark_dirty_kiobuf (kiobuf, count);
-
-        unmap_kiobuf (kiobuf);
- out_2:
-        free_kiovec (1, &kiobuf);
- out_1:
         OBD_FREE(pga, npages * sizeof(*pga));
         return (rc);
 }
-#else
-static int echo_client_ubrw(struct obd_device *obd, int rw,
-                            struct obdo *oa, struct lov_stripe_md *lsm,
-                            obd_off offset, obd_size count, char *buffer,
-                            struct obd_trans_info *oti)
-{
-        /* echo_client_ubrw() needs to be ported on 2.6 yet */
-        LBUG();
-        return 0;
-}
-#endif
-#endif
 
 struct echo_async_state;
 
@@ -729,7 +650,7 @@ static int ec_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
             eas->eas_oa.o_id != ECHO_PERSISTENT_OBJID &&
             (eas->eas_oa.o_valid & OBD_MD_FLFLAGS) != 0 &&
             (eas->eas_oa.o_flags & OBD_FL_DEBUG_CHECK) != 0)
-                echo_client_page_debug_check(eas->eas_lsm, eap->eap_page, 
+                echo_client_page_debug_check(eas->eas_lsm, eap->eap_page,
                                              eas->eas_oa.o_id, eap->eap_off,
                                              CFS_PAGE_SIZE);
 
@@ -801,13 +722,14 @@ static int echo_client_async_page(struct obd_export *exp, int rw,
         /* prepare the group of pages that we're going to be keeping
          * in flight */
         for (i = 0; i < npages; i++) {
-                cfs_page_t *page = cfs_alloc_page(CFS_ALLOC_STD);
+                cfs_page_t *page;
+                OBD_PAGE_ALLOC(page, CFS_ALLOC_STD);
                 if (page == NULL)
                         GOTO(out, rc = -ENOMEM);
 
                 OBD_ALLOC(eap, sizeof(*eap));
                 if (eap == NULL) {
-                        cfs_free_page(page);
+                        OBD_PAGE_FREE(page);
                         GOTO(out, rc = -ENOMEM);
                 }
 
@@ -825,7 +747,7 @@ static int echo_client_async_page(struct obd_export *exp, int rw,
 
                 /* sleep until we have a page to send */
                 spin_unlock(&eas.eas_lock);
-                rc = wait_event_interruptible(eas.eas_waitq, 
+                rc = wait_event_interruptible(eas.eas_waitq,
                                               eas_should_wake(&eas));
                 spin_lock(&eas.eas_lock);
                 if (rc && !eas.eas_rc)
@@ -841,7 +763,7 @@ static int echo_client_async_page(struct obd_export *exp, int rw,
 
                 /* unbind the eap from its old page offset */
                 if (eap->eap_cookie != NULL) {
-                        obd_teardown_async_page(exp, lsm, NULL, 
+                        obd_teardown_async_page(exp, lsm, NULL,
                                                 eap->eap_cookie);
                         eap->eap_cookie = NULL;
                 }
@@ -851,7 +773,7 @@ static int echo_client_async_page(struct obd_export *exp, int rw,
 
                 rc = obd_prep_async_page(exp, lsm, NULL, eap->eap_page,
                                          eap->eap_off, &ec_async_page_ops,
-                                         eap, &eap->eap_cookie);
+                                         eap, &eap->eap_cookie, 1, NULL);
                 if (rc) {
                         spin_lock(&eas.eas_lock);
                         eas.eas_rc = rc;
@@ -861,8 +783,8 @@ static int echo_client_async_page(struct obd_export *exp, int rw,
                 if (oa->o_id != ECHO_PERSISTENT_OBJID &&
                     (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
                     (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0)
-                        echo_client_page_debug_setup(lsm, eap->eap_page, rw, 
-                                                     oa->o_id, 
+                        echo_client_page_debug_setup(lsm, eap->eap_page, rw,
+                                                     oa->o_id,
                                                      eap->eap_off, CFS_PAGE_SIZE);
 
                 /* always asserts urgent, which isn't quite right */
@@ -878,14 +800,14 @@ static int echo_client_async_page(struct obd_export *exp, int rw,
                 eas.eas_in_flight++;
                 if (eas.eas_next_offset == eas.eas_end_offset)
                         break;
-        } 
+        }
 
         /* still hold the eas_lock here.. */
 
         /* now we just spin waiting for all the rpcs to complete */
         while(eas.eas_in_flight) {
                 spin_unlock(&eas.eas_lock);
-                wait_event_interruptible(eas.eas_waitq, 
+                wait_event_interruptible(eas.eas_waitq,
                                          eas.eas_in_flight == 0);
                 spin_lock(&eas.eas_lock);
         }
@@ -902,7 +824,7 @@ out:
                                 obd_teardown_async_page(exp, lsm, NULL,
                                                         eap->eap_cookie);
                         OBD_FREE(eap, sizeof(*eap));
-                        cfs_free_page(page);
+                        OBD_PAGE_FREE(page);
                 }
                 OBD_FREE(aps, npages * sizeof aps[0]);
         }
@@ -912,7 +834,7 @@ out:
 
 static int echo_client_prep_commit(struct obd_export *exp, int rw,
                                    struct obdo *oa, struct lov_stripe_md *lsm,
-                                   obd_off offset, obd_size count,  
+                                   obd_off offset, obd_size count,
                                    obd_size batch, struct obd_trans_info *oti)
 {
         struct obd_ioobj ioo;
@@ -952,7 +874,8 @@ static int echo_client_prep_commit(struct obd_export *exp, int rw,
                 ioo.ioo_bufcnt = npages;
                 oti->oti_transno = 0;
 
-                ret = obd_preprw(rw, exp, oa, 1, &ioo, npages, rnb, lnb, oti);
+                ret = obd_preprw(rw, exp, oa, 1, &ioo, npages, rnb, lnb, oti,
+                                 NULL);
                 if (ret != 0)
                         GOTO(out, ret);
 
@@ -1013,18 +936,9 @@ int echo_client_brw_ioctl(int rw, struct obd_export *exp,
 
         switch((long)data->ioc_pbuf1) {
         case 1:
-                if (data->ioc_pbuf2 == NULL) { // NULL user data pointer
-                        rc = echo_client_kbrw(obd, rw, &data->ioc_obdo1,
+                rc = echo_client_kbrw(obd, rw, &data->ioc_obdo1,
                                               eco->eco_lsm, data->ioc_offset,
                                               data->ioc_count, &dummy_oti);
-                } else {
-#ifdef __KERNEL__
-                        rc = echo_client_ubrw(obd, rw, &data->ioc_obdo1,
-                                              eco->eco_lsm, data->ioc_offset,
-                                              data->ioc_count, data->ioc_pbuf2,
-                                              &dummy_oti);
-#endif
-                }
                 break;
         case 2:
                 rc = echo_client_async_page(ec->ec_exp, rw, &data->ioc_obdo1,
@@ -1096,7 +1010,7 @@ echo_client_enqueue(struct obd_export *exp, struct obdo *oa,
         struct obd_device      *obd = exp->exp_obd;
         struct echo_client_obd *ec = &obd->u.echo_client;
         struct lustre_handle   *ulh = obdo_handle (oa);
-        struct obd_enqueue_info einfo = { 0 };
+        struct ldlm_enqueue_info einfo = { 0 };
         struct obd_info oinfo = { { { 0 } } };
         struct ec_object       *eco;
         struct ec_lock         *ecl;
@@ -1134,7 +1048,7 @@ echo_client_enqueue(struct obd_export *exp, struct obdo *oa,
         oinfo.oi_policy = ecl->ecl_policy;
         oinfo.oi_lockh = &ecl->ecl_lock_handle;
         oinfo.oi_md = eco->eco_lsm;
-        rc = obd_enqueue(ec->ec_exp, &oinfo, &einfo);
+        rc = obd_enqueue(ec->ec_exp, &oinfo, &einfo, NULL);
         if (rc != 0)
                 goto failed_1;
 
@@ -1233,6 +1147,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp,
         case OBD_IOC_DESTROY:
                 if (!capable (CAP_SYS_ADMIN))
                         GOTO (out, rc = -EPERM);
+
                 rc = echo_get_object (&eco, obd, &data->ioc_obdo1);
                 if (rc == 0) {
                         oa = &data->ioc_obdo1;
@@ -1330,7 +1245,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp,
  out:
 
         /* XXX this should be in a helper also called by target_send_reply */
-        for (ack_lock = dummy_oti.oti_ack_locks, i = 0; i < 4; 
+        for (ack_lock = dummy_oti.oti_ack_locks, i = 0; i < 4;
              i++, ack_lock++) {
                 if (!ack_lock->mode)
                         break;
@@ -1342,10 +1257,8 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp,
         return rc;
 }
 
-static int
-echo_client_setup(struct obd_device *obddev, obd_count len, void *buf)
+static int echo_client_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
 {
-        struct lustre_cfg* lcfg = buf;
         struct echo_client_obd *ec = &obddev->u.echo_client;
         struct obd_device *tgt;
         struct lustre_handle conn = {0, };
@@ -1377,10 +1290,11 @@ echo_client_setup(struct obd_device *obddev, obd_count len, void *buf)
                 return -ENOMEM;
         }
 
-        ocd->ocd_connect_flags = OBD_CONNECT_VERSION;
+        ocd->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_REQPORTAL;
         ocd->ocd_version = LUSTRE_VERSION_CODE;
+        ocd->ocd_group = FILTER_GROUP_ECHO;
 
-        rc = obd_connect(&conn, tgt, &echo_uuid, ocd);
+        rc = obd_connect(NULL, &conn, tgt, &echo_uuid, ocd, NULL);
 
         OBD_FREE(ocd, sizeof(*ocd));
 
@@ -1425,9 +1339,10 @@ static int echo_client_cleanup(struct obd_device *obddev)
         RETURN(rc);
 }
 
-static int echo_client_connect(struct lustre_handle *conn,
+static int echo_client_connect(const struct lu_env *env,
+                               struct lustre_handle *conn,
                                struct obd_device *src, struct obd_uuid *cluuid,
-                               struct obd_connect_data *data)
+                               struct obd_connect_data *data, void *localdata)
 {
         struct obd_export *exp;
         int                rc;
@@ -1490,11 +1405,11 @@ static struct obd_ops echo_obd_ops = {
 
 int echo_client_init(void)
 {
-        struct lprocfs_static_vars lvars;
+        struct lprocfs_static_vars lvars = { 0 };
 
-        lprocfs_init_vars(echo, &lvars);
-        return class_register_type(&echo_obd_ops, lvars.module_vars,
-                                   LUSTRE_ECHO_CLIENT_NAME);
+        lprocfs_echo_init_vars(&lvars);
+        return class_register_type(&echo_obd_ops, NULL, lvars.module_vars,
+                                   LUSTRE_ECHO_CLIENT_NAME, NULL);
 }
 
 void echo_client_exit(void)