* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2015, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
*/
#define DEBUG_SUBSYSTEM S_ECHO
-#ifdef __KERNEL__
-#include <libcfs/libcfs.h>
-#else
-#include <liblustre.h>
+
+#include <linux/user_namespace.h>
+#ifdef HAVE_UIDGID_HEADER
+# include <linux/uidgid.h>
#endif
+#include <libcfs/libcfs.h>
#include <obd.h>
#include <obd_support.h>
#include <cl_object.h>
#include <lustre_fid.h>
#include <lustre_acl.h>
+#include <lustre_ioctl.h>
#include <lustre_net.h>
-#include <obd_lov.h>
+#ifdef HAVE_SERVER_SUPPORT
+# include <md_object.h>
+#endif /* HAVE_SERVER_SUPPORT */
#include "echo_internal.h"
*/
struct echo_device {
- struct cl_device ed_cl;
- struct echo_client_obd *ed_ec;
-
- struct cl_site ed_site_myself;
- struct cl_site *ed_site;
- struct lu_device *ed_next;
- int ed_next_islov;
- int ed_next_ismd;
- struct lu_client_seq *ed_cl_seq;
+ struct cl_device ed_cl;
+ struct echo_client_obd *ed_ec;
+
+ struct cl_site ed_site_myself;
+ struct lu_site *ed_site;
+ struct lu_device *ed_next;
+ int ed_next_ismd;
+ struct lu_client_seq *ed_cl_seq;
+#ifdef HAVE_SERVER_SUPPORT
+ struct local_oid_storage *ed_los;
+ struct lu_fid ed_root_fid;
+#endif /* HAVE_SERVER_SUPPORT */
};
struct echo_object {
- struct cl_object eo_cl;
- struct cl_object_header eo_hdr;
-
- struct echo_device *eo_dev;
- cfs_list_t eo_obj_chain;
- struct lov_stripe_md *eo_lsm;
- cfs_atomic_t eo_npages;
- int eo_deleted;
+ struct cl_object eo_cl;
+ struct cl_object_header eo_hdr;
+ struct echo_device *eo_dev;
+ struct list_head eo_obj_chain;
+ struct lov_oinfo *eo_oinfo;
+ atomic_t eo_npages;
+ int eo_deleted;
};
struct echo_object_conf {
- struct cl_object_conf eoc_cl;
- struct lov_stripe_md **eoc_md;
+ struct cl_object_conf eoc_cl;
+ struct lov_oinfo **eoc_oinfo;
};
struct echo_page {
- struct cl_page_slice ep_cl;
+ struct cl_page_slice ep_cl;
struct mutex ep_lock;
- cfs_page_t *ep_vmpage;
};
struct echo_lock {
- struct cl_lock_slice el_cl;
- cfs_list_t el_chain;
- struct echo_object *el_object;
- __u64 el_cookie;
- cfs_atomic_t el_refcount;
+ struct cl_lock_slice el_cl;
+ struct list_head el_chain;
+ struct echo_object *el_object;
+ __u64 el_cookie;
+ atomic_t el_refcount;
};
-struct echo_io {
- struct cl_io_slice ei_cl;
-};
+#ifdef HAVE_SERVER_SUPPORT
+static const char echo_md_root_dir_name[] = "ROOT_ECHO";
-#if 0
-struct echo_req {
- struct cl_req_slice er_cl;
+/**
+ * In order to use the values of members in struct mdd_device,
+ * we define an alias structure here.
+ */
+struct echo_md_device {
+ struct md_device emd_md_dev;
+ struct obd_export *emd_child_exp;
+ struct dt_device *emd_child;
+ struct dt_device *emd_bottom;
+ struct lu_fid emd_root_fid;
+ struct lu_fid emd_local_root_fid;
};
-#endif
+#endif /* HAVE_SERVER_SUPPORT */
static int echo_client_setup(const struct lu_env *env,
struct obd_device *obddev,
return container_of(c, struct echo_object_conf, eoc_cl);
}
-static inline void lsm2fid(struct lov_stripe_md *lsm, struct lu_fid *fid)
+#ifdef HAVE_SERVER_SUPPORT
+static inline struct echo_md_device *lu2emd_dev(struct lu_device *d)
+{
+ return container_of0(d, struct echo_md_device, emd_md_dev.md_lu_dev);
+}
+
+static inline struct lu_device *emd2lu_dev(struct echo_md_device *d)
+{
+ return &d->emd_md_dev.md_lu_dev;
+}
+
+static inline struct seq_server_site *echo_md_seq_site(struct echo_md_device *d)
+{
+ return emd2lu_dev(d)->ld_site->ld_seq_site;
+}
+
+static inline struct obd_device *emd2obd_dev(struct echo_md_device *d)
{
- 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;
+ return d->emd_md_dev.md_lu_dev.ld_obd;
}
+#endif /* HAVE_SERVER_SUPPORT */
+
/** @} echo_helpers */
-static struct echo_object *cl_echo_object_find(struct echo_device *d,
- struct lov_stripe_md **lsm);
static int cl_echo_object_put(struct echo_object *eco);
-static int cl_echo_enqueue (struct echo_object *eco, obd_off start,
- obd_off end, int mode, __u64 *cookie);
-static int cl_echo_cancel (struct echo_device *d, __u64 cookie);
-static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
- cfs_page_t **pages, int npages, int async);
-
-static struct echo_thread_info *echo_env_info(const struct lu_env *env);
+static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset,
+ struct page **pages, int npages, int async);
struct echo_thread_info {
- struct echo_object_conf eti_conf;
- struct lustre_md eti_md;
+ struct echo_object_conf eti_conf;
+ struct lustre_md eti_md;
- struct cl_2queue eti_queue;
- struct cl_io eti_io;
- struct cl_lock_descr eti_descr;
- struct lu_fid eti_fid;
+ struct cl_2queue eti_queue;
+ struct cl_io eti_io;
+ struct cl_lock eti_lock;
+ struct lu_fid eti_fid;
struct lu_fid eti_fid2;
- struct md_op_spec eti_spec;
- struct lov_mds_md_v3 eti_lmm;
- struct lov_user_md_v3 eti_lum;
- struct md_attr eti_ma;
- struct lu_name eti_lname;
+#ifdef HAVE_SERVER_SUPPORT
+ struct md_op_spec eti_spec;
+ struct lov_mds_md_v3 eti_lmm;
+ struct lov_user_md_v3 eti_lum;
+ struct md_attr eti_ma;
+ struct lu_name eti_lname;
/* per-thread values, can be re-used */
- void *eti_big_lmm;
+ void *eti_big_lmm; /* may be vmalloc'd */
int eti_big_lmmsize;
- char eti_name[20];
- struct lu_buf eti_buf;
- char eti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
+ char eti_name[20];
+ struct lu_buf eti_buf;
+ char eti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
+#endif
};
/* No session used right now */
unsigned long dummy;
};
-static cfs_mem_cache_t *echo_page_kmem;
-static cfs_mem_cache_t *echo_lock_kmem;
-static cfs_mem_cache_t *echo_object_kmem;
-static cfs_mem_cache_t *echo_thread_kmem;
-static cfs_mem_cache_t *echo_session_kmem;
-//static cfs_mem_cache_t *echo_req_kmem;
+static struct kmem_cache *echo_lock_kmem;
+static struct kmem_cache *echo_object_kmem;
+static struct kmem_cache *echo_thread_kmem;
+static struct kmem_cache *echo_session_kmem;
+/* static struct kmem_cache *echo_req_kmem; */
static struct lu_kmem_descr echo_caches[] = {
{
- .ckd_cache = &echo_page_kmem,
- .ckd_name = "echo_page_kmem",
- .ckd_size = sizeof (struct echo_page)
- },
- {
.ckd_cache = &echo_lock_kmem,
.ckd_name = "echo_lock_kmem",
.ckd_size = sizeof (struct echo_lock)
.ckd_name = "echo_session_kmem",
.ckd_size = sizeof (struct echo_session_info)
},
-#if 0
- {
- .ckd_cache = &echo_req_kmem,
- .ckd_name = "echo_req_kmem",
- .ckd_size = sizeof (struct echo_req)
- },
-#endif
{
.ckd_cache = NULL
}
*
* @{
*/
-static cfs_page_t *echo_page_vmpage(const struct lu_env *env,
- const struct cl_page_slice *slice)
-{
- return cl2echo_page(slice)->ep_vmpage;
-}
-
static int echo_page_own(const struct lu_env *env,
const struct cl_page_slice *slice,
struct cl_io *io, int nonblock)
}
static void echo_page_fini(const struct lu_env *env,
- struct cl_page_slice *slice)
+ struct cl_page_slice *slice)
{
- struct echo_page *ep = cl2echo_page(slice);
- struct echo_object *eco = cl2echo_obj(slice->cpl_obj);
- cfs_page_t *vmpage = ep->ep_vmpage;
- ENTRY;
+ struct echo_object *eco = cl2echo_obj(slice->cpl_obj);
+ ENTRY;
- cfs_atomic_dec(&eco->eo_npages);
- page_cache_release(vmpage);
- OBD_SLAB_FREE_PTR(ep, echo_page_kmem);
- EXIT;
+ atomic_dec(&eco->eo_npages);
+ page_cache_release(slice->cpl_page->cp_vmpage);
+ EXIT;
}
static int echo_page_prep(const struct lu_env *env,
const struct cl_page_slice *slice,
void *cookie, lu_printer_t printer)
{
- struct echo_page *ep = cl2echo_page(slice);
+ struct echo_page *ep = cl2echo_page(slice);
- (*printer)(env, cookie, LUSTRE_ECHO_CLIENT_NAME"-page@%p %d vm@%p\n",
- ep, mutex_is_locked(&ep->ep_lock), ep->ep_vmpage);
- return 0;
+ (*printer)(env, cookie, LUSTRE_ECHO_CLIENT_NAME"-page@%p %d vm@%p\n",
+ ep, mutex_is_locked(&ep->ep_lock),
+ slice->cpl_page->cp_vmpage);
+ return 0;
}
static const struct cl_page_operations echo_page_ops = {
.cpo_own = echo_page_own,
.cpo_disown = echo_page_disown,
.cpo_discard = echo_page_discard,
- .cpo_vmpage = echo_page_vmpage,
.cpo_fini = echo_page_fini,
.cpo_print = echo_page_print,
.cpo_is_vmlocked = echo_page_is_vmlocked,
{
struct echo_lock *ecl = cl2echo_lock(slice);
- LASSERT(cfs_list_empty(&ecl->el_chain));
+ LASSERT(list_empty(&ecl->el_chain));
OBD_SLAB_FREE_PTR(ecl, echo_lock_kmem);
}
-static void echo_lock_delete(const struct lu_env *env,
- const struct cl_lock_slice *slice)
-{
- struct echo_lock *ecl = cl2echo_lock(slice);
-
- LASSERT(cfs_list_empty(&ecl->el_chain));
-}
-
-static int echo_lock_fits_into(const struct lu_env *env,
- const struct cl_lock_slice *slice,
- const struct cl_lock_descr *need,
- const struct cl_io *unused)
-{
- return 1;
-}
-
static struct cl_lock_operations echo_lock_ops = {
.clo_fini = echo_lock_fini,
- .clo_delete = echo_lock_delete,
- .clo_fits_into = echo_lock_fits_into
};
/** @} echo_lock */
*
* @{
*/
-static struct cl_page *echo_page_init(const struct lu_env *env,
- struct cl_object *obj,
- struct cl_page *page, cfs_page_t *vmpage)
+static int echo_page_init(const struct lu_env *env, struct cl_object *obj,
+ struct cl_page *page, pgoff_t index)
{
- struct echo_page *ep;
- ENTRY;
+ struct echo_page *ep = cl_object_page_slice(obj, page);
+ struct echo_object *eco = cl2echo_obj(obj);
+ ENTRY;
- OBD_SLAB_ALLOC_PTR_GFP(ep, echo_page_kmem, CFS_ALLOC_IO);
- if (ep != NULL) {
- struct echo_object *eco = cl2echo_obj(obj);
- ep->ep_vmpage = vmpage;
- page_cache_get(vmpage);
- mutex_init(&ep->ep_lock);
- cl_page_slice_add(page, &ep->ep_cl, obj, &echo_page_ops);
- cfs_atomic_inc(&eco->eo_npages);
- }
- RETURN(ERR_PTR(ep ? 0 : -ENOMEM));
+ page_cache_get(page->cp_vmpage);
+ mutex_init(&ep->ep_lock);
+ cl_page_slice_add(page, &ep->ep_cl, obj, index, &echo_page_ops);
+ atomic_inc(&eco->eo_npages);
+ RETURN(0);
}
static int echo_io_init(const struct lu_env *env, struct cl_object *obj,
}
static int echo_lock_init(const struct lu_env *env,
- struct cl_object *obj, struct cl_lock *lock,
- const struct cl_io *unused)
+ struct cl_object *obj, struct cl_lock *lock,
+ const struct cl_io *unused)
{
- struct echo_lock *el;
- ENTRY;
+ struct echo_lock *el;
+ ENTRY;
- OBD_SLAB_ALLOC_PTR_GFP(el, echo_lock_kmem, CFS_ALLOC_IO);
- if (el != NULL) {
- cl_lock_slice_add(lock, &el->el_cl, obj, &echo_lock_ops);
- el->el_object = cl2echo_obj(obj);
- CFS_INIT_LIST_HEAD(&el->el_chain);
- cfs_atomic_set(&el->el_refcount, 0);
- }
- RETURN(el == NULL ? -ENOMEM : 0);
+ OBD_SLAB_ALLOC_PTR_GFP(el, echo_lock_kmem, GFP_NOFS);
+ if (el != NULL) {
+ cl_lock_slice_add(lock, &el->el_cl, obj, &echo_lock_ops);
+ el->el_object = cl2echo_obj(obj);
+ INIT_LIST_HEAD(&el->el_chain);
+ atomic_set(&el->el_refcount, 0);
+ }
+ RETURN(el == NULL ? -ENOMEM : 0);
}
static int echo_conf_set(const struct lu_env *env, struct cl_object *obj,
const struct cl_object_conf *cconf = lu2cl_conf(conf);
struct echo_object_conf *econf = cl2echo_conf(cconf);
- LASSERT(econf->eoc_md);
- eco->eo_lsm = *econf->eoc_md;
- /* clear the lsm pointer so that it won't get freed. */
- *econf->eoc_md = NULL;
- } else {
- eco->eo_lsm = NULL;
- }
+ LASSERT(econf->eoc_oinfo != NULL);
+
+ /* Transfer the oinfo pointer to eco that it won't be
+ * freed. */
+ eco->eo_oinfo = *econf->eoc_oinfo;
+ *econf->eoc_oinfo = NULL;
+ } else {
+ eco->eo_oinfo = NULL;
+ }
eco->eo_dev = ed;
- cfs_atomic_set(&eco->eo_npages, 0);
+ atomic_set(&eco->eo_npages, 0);
+ cl_object_page_init(lu2cl(obj), sizeof(struct echo_page));
spin_lock(&ec->ec_lock);
- cfs_list_add_tail(&eco->eo_obj_chain, &ec->ec_objects);
+ list_add_tail(&eco->eo_obj_chain, &ec->ec_objects);
spin_unlock(&ec->ec_lock);
RETURN(0);
}
-/* taken from osc_unpackmd() */
-static int echo_alloc_memmd(struct echo_device *ed,
- struct lov_stripe_md **lsmp)
-{
- int lsm_size;
-
- ENTRY;
-
- /* If export is lov/osc then use their obd method */
- if (ed->ed_next != NULL)
- return obd_alloc_memmd(ed->ed_ec->ec_exp, lsmp);
- /* OFD has no unpackmd method, do everything here */
- lsm_size = lov_stripe_md_size(1);
-
- LASSERT(*lsmp == NULL);
- OBD_ALLOC(*lsmp, lsm_size);
- if (*lsmp == NULL)
- RETURN(-ENOMEM);
-
- OBD_ALLOC((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
- if ((*lsmp)->lsm_oinfo[0] == NULL) {
- OBD_FREE(*lsmp, lsm_size);
- RETURN(-ENOMEM);
- }
-
- loi_init((*lsmp)->lsm_oinfo[0]);
- (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
-
- RETURN(lsm_size);
-}
-
-static int echo_free_memmd(struct echo_device *ed, struct lov_stripe_md **lsmp)
-{
- int lsm_size;
-
- ENTRY;
-
- /* If export is lov/osc then use their obd method */
- if (ed->ed_next != NULL)
- return obd_free_memmd(ed->ed_ec->ec_exp, lsmp);
- /* OFD has no unpackmd method, do everything here */
- lsm_size = lov_stripe_md_size(1);
-
- LASSERT(*lsmp != NULL);
- OBD_FREE((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));
- OBD_FREE(*lsmp, lsm_size);
- *lsmp = NULL;
- RETURN(0);
-}
-
static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
{
struct echo_object *eco = cl2echo_obj(lu2cl(obj));
struct echo_client_obd *ec = eco->eo_dev->ed_ec;
ENTRY;
- LASSERT(cfs_atomic_read(&eco->eo_npages) == 0);
+ LASSERT(atomic_read(&eco->eo_npages) == 0);
spin_lock(&ec->ec_lock);
- cfs_list_del_init(&eco->eo_obj_chain);
+ list_del_init(&eco->eo_obj_chain);
spin_unlock(&ec->ec_lock);
lu_object_fini(obj);
lu_object_header_fini(obj->lo_header);
- if (eco->eo_lsm)
- echo_free_memmd(eco->eo_dev, &eco->eo_lsm);
+ if (eco->eo_oinfo != NULL)
+ OBD_FREE_PTR(eco->eo_oinfo);
+
OBD_SLAB_FREE_PTR(eco, echo_object_kmem);
EXIT;
}
* @{
*/
static struct lu_object *echo_object_alloc(const struct lu_env *env,
- const struct lu_object_header *hdr,
- struct lu_device *dev)
+ const struct lu_object_header *hdr,
+ struct lu_device *dev)
{
- struct echo_object *eco;
- struct lu_object *obj = NULL;
- ENTRY;
+ struct echo_object *eco;
+ struct lu_object *obj = NULL;
+ ENTRY;
- /* we're the top dev. */
- LASSERT(hdr == NULL);
- OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, CFS_ALLOC_IO);
- if (eco != NULL) {
- struct cl_object_header *hdr = &eco->eo_hdr;
+ /* we're the top dev. */
+ LASSERT(hdr == NULL);
+ OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, GFP_NOFS);
+ if (eco != NULL) {
+ struct cl_object_header *hdr = &eco->eo_hdr;
- obj = &echo_obj2cl(eco)->co_lu;
- cl_object_header_init(hdr);
- lu_object_init(obj, &hdr->coh_lu, dev);
- lu_object_add_top(&hdr->coh_lu, obj);
+ obj = &echo_obj2cl(eco)->co_lu;
+ cl_object_header_init(hdr);
+ hdr->coh_page_bufsize = cfs_size_round(sizeof(struct cl_page));
- eco->eo_cl.co_ops = &echo_cl_obj_ops;
- obj->lo_ops = &echo_lu_obj_ops;
- }
- RETURN(obj);
+ lu_object_init(obj, &hdr->coh_lu, dev);
+ lu_object_add_top(&hdr->coh_lu, obj);
+
+ eco->eo_cl.co_ops = &echo_cl_obj_ops;
+ obj->lo_ops = &echo_lu_obj_ops;
+ }
+ RETURN(obj);
}
static struct lu_device_operations echo_device_lu_ops = {
/** @} echo_lu_dev_ops */
-static struct cl_device_operations echo_device_cl_ops = {
-};
-
/** \defgroup echo_init Setup and teardown
*
* Init and fini functions for echo client.
struct cl_site *site = &ed->ed_site_myself;
int rc;
- /* initialize site */
+ /* initialize site */
rc = cl_site_init(site, &ed->ed_cl);
if (rc) {
- CERROR("Cannot initilize site for echo client(%d)\n", rc);
+ CERROR("Cannot initialize site for echo client(%d)\n", rc);
return rc;
}
- rc = lu_site_init_finish(&site->cs_lu);
- if (rc)
- return rc;
+ rc = lu_site_init_finish(&site->cs_lu);
+ if (rc) {
+ cl_site_fini(site);
+ return rc;
+ }
- ed->ed_site = site;
- return 0;
+ ed->ed_site = &site->cs_lu;
+ return 0;
}
static void echo_site_fini(const struct lu_env *env, struct echo_device *ed)
{
- if (ed->ed_site) {
- if (!ed->ed_next_ismd)
- cl_site_fini(ed->ed_site);
- ed->ed_site = NULL;
- }
+ if (ed->ed_site) {
+ if (!ed->ed_next_ismd)
+ lu_site_fini(ed->ed_site);
+ ed->ed_site = NULL;
+ }
}
static void *echo_thread_key_init(const struct lu_context *ctx,
- struct lu_context_key *key)
+ struct lu_context_key *key)
{
- struct echo_thread_info *info;
+ struct echo_thread_info *info;
- OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, CFS_ALLOC_IO);
- if (info == NULL)
- info = ERR_PTR(-ENOMEM);
- return info;
+ OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, GFP_NOFS);
+ if (info == NULL)
+ info = ERR_PTR(-ENOMEM);
+ return info;
}
static void echo_thread_key_fini(const struct lu_context *ctx,
};
static void *echo_session_key_init(const struct lu_context *ctx,
- struct lu_context_key *key)
+ struct lu_context_key *key)
{
- struct echo_session_info *session;
+ struct echo_session_info *session;
- OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, CFS_ALLOC_IO);
- if (session == NULL)
- session = ERR_PTR(-ENOMEM);
- return session;
+ OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, GFP_NOFS);
+ if (session == NULL)
+ session = ERR_PTR(-ENOMEM);
+ return session;
}
static void echo_session_key_fini(const struct lu_context *ctx,
LU_TYPE_INIT_FINI(echo, &echo_thread_key, &echo_session_key);
-#define ECHO_SEQ_WIDTH 0xffffffff
+#ifdef HAVE_SERVER_SUPPORT
+# define ECHO_SEQ_WIDTH 0xffffffff
static int echo_fid_init(struct echo_device *ed, char *obd_name,
- struct md_site *ms)
+ struct seq_server_site *ss)
{
char *prefix;
int rc;
snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s", obd_name);
- /* Init client side sequence-manager */
- rc = seq_client_init(ed->ed_cl_seq, NULL,
- LUSTRE_SEQ_METADATA,
- prefix, ms->ms_server_seq);
+ /* Init client side sequence-manager */
+ rc = seq_client_init(ed->ed_cl_seq, NULL,
+ LUSTRE_SEQ_METADATA,
+ prefix, ss->ss_server_seq);
ed->ed_cl_seq->lcs_width = ECHO_SEQ_WIDTH;
OBD_FREE(prefix, MAX_OBD_NAME + 5);
if (rc)
RETURN(0);
}
+static void echo_ed_los_fini(const struct lu_env *env, struct echo_device *ed)
+{
+ ENTRY;
+
+ if (ed != NULL && ed->ed_next_ismd && ed->ed_los != NULL) {
+ local_oid_storage_fini(env, ed->ed_los);
+ ed->ed_los = NULL;
+ }
+}
+
+static int
+echo_md_local_file_create(const struct lu_env *env, struct echo_md_device *emd,
+ struct local_oid_storage *los,
+ const struct lu_fid *pfid, const char *name,
+ __u32 mode, struct lu_fid *fid)
+{
+ struct dt_object *parent = NULL;
+ struct dt_object *dto = NULL;
+ int rc = 0;
+ ENTRY;
+
+ LASSERT(!fid_is_zero(pfid));
+ parent = dt_locate(env, emd->emd_bottom, pfid);
+ if (unlikely(IS_ERR(parent)))
+ RETURN(PTR_ERR(parent));
+
+ /* create local file with @fid */
+ dto = local_file_find_or_create_with_fid(env, emd->emd_bottom, fid,
+ parent, name, mode);
+ if (IS_ERR(dto))
+ GOTO(out_put, rc = PTR_ERR(dto));
+
+ *fid = *lu_object_fid(&dto->do_lu);
+ /* since stack is not fully set up the local_storage uses own stack
+ * and we should drop its object from cache */
+ lu_object_put_nocache(env, &dto->do_lu);
+
+ EXIT;
+out_put:
+ lu_object_put(env, &parent->do_lu);
+ RETURN(rc);
+}
+
+static int
+echo_md_root_get(const struct lu_env *env, struct echo_md_device *emd,
+ struct echo_device *ed)
+{
+ struct lu_fid fid;
+ int rc = 0;
+ ENTRY;
+
+ /* Setup local dirs */
+ fid.f_seq = FID_SEQ_LOCAL_NAME;
+ fid.f_oid = 1;
+ fid.f_ver = 0;
+ rc = local_oid_storage_init(env, emd->emd_bottom, &fid, &ed->ed_los);
+ if (rc != 0)
+ RETURN(rc);
+
+ lu_echo_root_fid(&fid);
+ if (echo_md_seq_site(emd)->ss_node_id == 0) {
+ rc = echo_md_local_file_create(env, emd, ed->ed_los,
+ &emd->emd_local_root_fid,
+ echo_md_root_dir_name, S_IFDIR |
+ S_IRUGO | S_IWUSR | S_IXUGO,
+ &fid);
+ if (rc != 0) {
+ CERROR("%s: create md echo root fid failed: rc = %d\n",
+ emd2obd_dev(emd)->obd_name, rc);
+ GOTO(out_los, rc);
+ }
+ }
+ ed->ed_root_fid = fid;
+
+ RETURN(0);
+out_los:
+ echo_ed_los_fini(env, ed);
+
+ RETURN(rc);
+}
+#endif /* HAVE_SERVER_SUPPORT */
+
static struct lu_device *echo_device_alloc(const struct lu_env *env,
struct lu_device_type *t,
struct lustre_cfg *cfg)
GOTO(out, rc);
cd->cd_lu_dev.ld_ops = &echo_device_lu_ops;
- cd->cd_ops = &echo_device_cl_ops;
cleanup = 2;
obd = class_name2obd(lustre_cfg_string(cfg, 0));
}
next = tgt->obd_lu_dev;
- if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
- ed->ed_next_ismd = 1;
- } else {
- ed->ed_next_ismd = 0;
- rc = echo_site_init(env, ed);
- if (rc)
- GOTO(out, rc);
- }
+
+ if (strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
+ ed->ed_next_ismd = 1;
+ } else if (strcmp(tgt->obd_type->typ_name, LUSTRE_OST_NAME) == 0 ||
+ strcmp(tgt->obd_type->typ_name, LUSTRE_OSC_NAME) == 0) {
+ ed->ed_next_ismd = 0;
+ rc = echo_site_init(env, ed);
+ if (rc)
+ GOTO(out, rc);
+ } else {
+ GOTO(out, rc = -EINVAL);
+ }
+
cleanup = 3;
rc = echo_client_setup(env, obd, cfg);
cleanup = 4;
if (ed->ed_next_ismd) {
- /* Suppose to connect to some Metadata layer */
- struct lu_site *ls;
- struct lu_device *ld;
- int found = 0;
+#ifdef HAVE_SERVER_SUPPORT
+ /* Suppose to connect to some Metadata layer */
+ struct lu_site *ls = NULL;
+ struct lu_device *ld = NULL;
+ struct md_device *md = NULL;
+ struct echo_md_device *emd = NULL;
+ int found = 0;
if (next == NULL) {
CERROR("%s is not lu device type!\n",
ls = next->ld_site;
spin_lock(&ls->ls_ld_lock);
- cfs_list_for_each_entry(ld, &ls->ls_ld_linkage, ld_linkage) {
+ list_for_each_entry(ld, &ls->ls_ld_linkage, ld_linkage) {
if (strcmp(ld->ld_type->ldt_name, tgt_type_name) == 0) {
found = 1;
break;
GOTO(out, rc = -EINVAL);
}
- next = ld;
- /* For MD echo client, it will use the site in MDS stack */
- ed->ed_site_myself.cs_lu = *ls;
- ed->ed_site = &ed->ed_site_myself;
- ed->ed_cl.cd_lu_dev.ld_site = &ed->ed_site_myself.cs_lu;
- rc = echo_fid_init(ed, obd->obd_name, lu_site2md(ls));
- if (rc) {
- CERROR("echo fid init error %d\n", rc);
- GOTO(out, rc);
- }
+ next = ld;
+ /* For MD echo client, it will use the site in MDS stack */
+ ed->ed_site = ls;
+ ed->ed_cl.cd_lu_dev.ld_site = ls;
+ rc = echo_fid_init(ed, obd->obd_name, lu_site2seq(ls));
+ if (rc) {
+ CERROR("echo fid init error %d\n", rc);
+ GOTO(out, rc);
+ }
+
+ md = lu2md_dev(next);
+ emd = lu2emd_dev(&md->md_lu_dev);
+ rc = echo_md_root_get(env, emd, ed);
+ if (rc != 0) {
+ CERROR("%s: get root error: rc = %d\n",
+ emd2obd_dev(emd)->obd_name, rc);
+ GOTO(out, rc);
+ }
+#else /* !HAVE_SERVER_SUPPORT */
+ CERROR("Local operations are NOT supported on client side. "
+ "Only remote operations are supported. Metadata client "
+ "must be run on server side.\n");
+ GOTO(out, rc = -EOPNOTSUPP);
+#endif /* HAVE_SERVER_SUPPORT */
} else {
/* if echo client is to be stacked upon ost device, the next is
* NULL since ost is not a clio device so far */
if (next->ld_site != NULL)
GOTO(out, rc = -EBUSY);
- next->ld_site = &ed->ed_site->cs_lu;
+ next->ld_site = ed->ed_site;
rc = next->ld_type->ldt_ops->ldto_device_init(env, next,
next->ld_type->ldt_name,
NULL);
if (rc)
GOTO(out, rc);
-
- /* Tricky case, I have to determine the obd type since
- * CLIO uses the different parameters to initialize
- * objects for lov & osc. */
- if (strcmp(tgt_type_name, LUSTRE_LOV_NAME) == 0)
- ed->ed_next_islov = 1;
- else
- LASSERT(strcmp(tgt_type_name,
- LUSTRE_OSC_NAME) == 0);
} else
LASSERT(strcmp(tgt_type_name, LUSTRE_OST_NAME) == 0);
}
struct echo_lock *ecl,
int still_used)
{
- struct cl_lock *clk = echo_lock2cl(ecl);
+ struct cl_lock *clk = echo_lock2cl(ecl);
- cl_lock_get(clk);
- cl_unuse(env, clk);
- cl_lock_release(env, clk, "ec enqueue", ecl->el_object);
- if (!still_used) {
- cl_lock_mutex_get(env, clk);
- cl_lock_cancel(env, clk);
- cl_lock_delete(env, clk);
- cl_lock_mutex_put(env, clk);
- }
- cl_lock_put(env, clk);
+ cl_lock_release(env, clk);
}
static struct lu_device *echo_device_free(const struct lu_env *env,
CDEBUG(D_INFO, "echo device:%p is going to be freed, next = %p\n",
ed, next);
- lu_site_purge(env, &ed->ed_site->cs_lu, -1);
+ lu_site_purge(env, ed->ed_site, -1);
/* check if there are objects still alive.
* It shouldn't have any object because lu_site_purge would cleanup
* parallelly accessed.
*/
spin_lock(&ec->ec_lock);
- cfs_list_for_each_entry(eco, &ec->ec_objects, eo_obj_chain)
+ list_for_each_entry(eco, &ec->ec_objects, eo_obj_chain)
eco->eo_deleted = 1;
spin_unlock(&ec->ec_lock);
/* purge again */
- lu_site_purge(env, &ed->ed_site->cs_lu, -1);
+ lu_site_purge(env, ed->ed_site, -1);
CDEBUG(D_INFO,
"Waiting for the reference of echo object to be dropped\n");
/* Wait for the last reference to be dropped. */
spin_lock(&ec->ec_lock);
- while (!cfs_list_empty(&ec->ec_objects)) {
+ while (!list_empty(&ec->ec_objects)) {
spin_unlock(&ec->ec_lock);
CERROR("echo_client still has objects at cleanup time, "
"wait for 1 second\n");
- cfs_schedule_timeout_and_set_state(CFS_TASK_UNINT,
- cfs_time_seconds(1));
- lu_site_purge(env, &ed->ed_site->cs_lu, -1);
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ schedule_timeout(cfs_time_seconds(1));
+ lu_site_purge(env, ed->ed_site, -1);
spin_lock(&ec->ec_lock);
}
spin_unlock(&ec->ec_lock);
- LASSERT(cfs_list_empty(&ec->ec_locks));
+ LASSERT(list_empty(&ec->ec_locks));
- CDEBUG(D_INFO, "No object exists, exiting...\n");
+ CDEBUG(D_INFO, "No object exists, exiting...\n");
- echo_client_cleanup(d->ld_obd);
- echo_fid_fini(d->ld_obd);
- while (next && !ed->ed_next_ismd)
- next = next->ld_type->ldt_ops->ldto_device_free(env, next);
+ echo_client_cleanup(d->ld_obd);
+#ifdef HAVE_SERVER_SUPPORT
+ echo_fid_fini(d->ld_obd);
+ echo_ed_los_fini(env, ed);
+#endif
+ while (next && !ed->ed_next_ismd)
+ next = next->ld_type->ldt_ops->ldto_device_free(env, next);
- LASSERT(ed->ed_site == lu2cl_site(d->ld_site));
+ LASSERT(ed->ed_site == d->ld_site);
echo_site_fini(env, ed);
cl_device_fini(&ed->ed_cl);
OBD_FREE_PTR(ed);
*/
/* Interfaces to echo client obd device */
-static struct echo_object *cl_echo_object_find(struct echo_device *d,
- struct lov_stripe_md **lsmp)
+static struct echo_object *
+cl_echo_object_find(struct echo_device *d, const struct ost_id *oi)
{
- struct lu_env *env;
- struct echo_thread_info *info;
- struct echo_object_conf *conf;
- struct lov_stripe_md *lsm;
- struct echo_object *eco;
- struct cl_object *obj;
- struct lu_fid *fid;
- int refcheck;
- ENTRY;
+ struct lu_env *env;
+ struct echo_thread_info *info;
+ struct echo_object_conf *conf;
+ struct echo_object *eco;
+ struct cl_object *obj;
+ struct lov_oinfo *oinfo = NULL;
+ struct lu_fid *fid;
+ __u16 refcheck;
+ int rc;
+ ENTRY;
- LASSERT(lsmp);
- lsm = *lsmp;
- LASSERT(lsm);
- LASSERT(lsm->lsm_object_id);
+ LASSERTF(ostid_id(oi) != 0, DOSTID"\n", POSTID(oi));
+ LASSERTF(ostid_seq(oi) == FID_SEQ_ECHO, DOSTID"\n", POSTID(oi));
/* Never return an object if the obd is to be freed. */
if (echo_dev2cl(d)->cd_lu_dev.ld_obd->obd_stopping)
info = echo_env_info(env);
conf = &info->eti_conf;
if (d->ed_next) {
- 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;
- conf->eoc_cl.u.coc_oinfo = oinfo;
- } else {
- struct lustre_md *md;
- md = &info->eti_md;
- memset(md, 0, sizeof *md);
- md->lsm = lsm;
- conf->eoc_cl.u.coc_md = md;
- }
- }
- conf->eoc_md = lsmp;
+ OBD_ALLOC_PTR(oinfo);
+ if (oinfo == NULL)
+ GOTO(out, eco = ERR_PTR(-ENOMEM));
- fid = &info->eti_fid;
- lsm2fid(lsm, fid);
+ oinfo->loi_oi = *oi;
+ conf->eoc_cl.u.coc_oinfo = oinfo;
+ }
+
+ /* If echo_object_init() is successful then ownership of oinfo
+ * is transferred to the object. */
+ conf->eoc_oinfo = &oinfo;
+
+ fid = &info->eti_fid;
+ rc = ostid_to_fid(fid, oi, 0);
+ if (rc != 0)
+ GOTO(out, eco = ERR_PTR(rc));
/* In the function below, .hs_keycmp resolves to
* lu_obj_hop_keycmp() */
}
out:
+ if (oinfo != NULL)
+ OBD_FREE_PTR(oinfo);
+
cl_env_put(env, &refcheck);
RETURN(eco);
}
{
struct lu_env *env;
struct cl_object *obj = echo_obj2cl(eco);
- int refcheck;
+ __u16 refcheck;
ENTRY;
env = cl_env_get(&refcheck);
}
static int cl_echo_enqueue0(struct lu_env *env, struct echo_object *eco,
- obd_off start, obd_off end, int mode,
- __u64 *cookie , __u32 enqflags)
+ u64 start, u64 end, int mode,
+ __u64 *cookie , __u32 enqflags)
{
struct cl_io *io;
struct cl_lock *lck;
info = echo_env_info(env);
io = &info->eti_io;
- descr = &info->eti_descr;
- obj = echo_obj2cl(eco);
+ lck = &info->eti_lock;
+ obj = echo_obj2cl(eco);
+ memset(lck, 0, sizeof(*lck));
+ descr = &lck->cll_descr;
descr->cld_obj = obj;
descr->cld_start = cl_index(obj, start);
descr->cld_end = cl_index(obj, end);
descr->cld_enq_flags = enqflags;
io->ci_obj = obj;
- lck = cl_lock_request(env, io, descr, "ec enqueue", eco);
- if (lck) {
- struct echo_client_obd *ec = eco->eo_dev->ed_ec;
- struct echo_lock *el;
+ rc = cl_lock_request(env, io, lck);
+ if (rc == 0) {
+ struct echo_client_obd *ec = eco->eo_dev->ed_ec;
+ struct echo_lock *el;
- rc = cl_wait(env, lck);
- if (rc == 0) {
- el = cl2echo_lock(cl_lock_at(lck, &echo_device_type));
- spin_lock(&ec->ec_lock);
- if (cfs_list_empty(&el->el_chain)) {
- cfs_list_add(&el->el_chain, &ec->ec_locks);
- el->el_cookie = ++ec->ec_unique;
- }
- cfs_atomic_inc(&el->el_refcount);
- *cookie = el->el_cookie;
- spin_unlock(&ec->ec_lock);
- } else {
- cl_lock_release(env, lck, "ec enqueue", cfs_current());
+ el = cl2echo_lock(cl_lock_at(lck, &echo_device_type));
+ spin_lock(&ec->ec_lock);
+ if (list_empty(&el->el_chain)) {
+ list_add(&el->el_chain, &ec->ec_locks);
+ el->el_cookie = ++ec->ec_unique;
}
+ atomic_inc(&el->el_refcount);
+ *cookie = el->el_cookie;
+ spin_unlock(&ec->ec_lock);
}
RETURN(rc);
}
-static int cl_echo_enqueue(struct echo_object *eco, obd_off start, obd_off end,
- int mode, __u64 *cookie)
-{
- struct echo_thread_info *info;
- struct lu_env *env;
- struct cl_io *io;
- int refcheck;
- int result;
- ENTRY;
-
- env = cl_env_get(&refcheck);
- if (IS_ERR(env))
- RETURN(PTR_ERR(env));
-
- info = echo_env_info(env);
- io = &info->eti_io;
-
- io->ci_ignore_layout = 1;
- result = cl_io_init(env, io, CIT_MISC, echo_obj2cl(eco));
- if (result < 0)
- GOTO(out, result);
- LASSERT(result == 0);
-
- result = cl_echo_enqueue0(env, eco, start, end, mode, cookie, 0);
- cl_io_fini(env, io);
-
- EXIT;
-out:
- cl_env_put(env, &refcheck);
- return result;
-}
-
static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
__u64 cookie)
{
struct echo_client_obd *ec = ed->ed_ec;
struct echo_lock *ecl = NULL;
- cfs_list_t *el;
+ struct list_head *el;
int found = 0, still_used = 0;
ENTRY;
LASSERT(ec != NULL);
spin_lock(&ec->ec_lock);
- cfs_list_for_each (el, &ec->ec_locks) {
- ecl = cfs_list_entry (el, struct echo_lock, el_chain);
+ list_for_each(el, &ec->ec_locks) {
+ ecl = list_entry(el, struct echo_lock, el_chain);
CDEBUG(D_INFO, "ecl: %p, cookie: "LPX64"\n", ecl, ecl->el_cookie);
found = (ecl->el_cookie == cookie);
if (found) {
- if (cfs_atomic_dec_and_test(&ecl->el_refcount))
- cfs_list_del_init(&ecl->el_chain);
+ if (atomic_dec_and_test(&ecl->el_refcount))
+ list_del_init(&ecl->el_chain);
else
still_used = 1;
break;
RETURN(0);
}
-static int cl_echo_cancel(struct echo_device *ed, __u64 cookie)
+static void echo_commit_callback(const struct lu_env *env, struct cl_io *io,
+ struct cl_page *page)
{
- struct lu_env *env;
- int refcheck;
- int rc;
- ENTRY;
-
- env = cl_env_get(&refcheck);
- if (IS_ERR(env))
- RETURN(PTR_ERR(env));
-
- rc = cl_echo_cancel0(env, ed, cookie);
-
- cl_env_put(env, &refcheck);
- RETURN(rc);
-}
+ struct echo_thread_info *info;
+ struct cl_2queue *queue;
-static int cl_echo_async_brw(const struct lu_env *env, struct cl_io *io,
- enum cl_req_type unused, struct cl_2queue *queue)
-{
- struct cl_page *clp;
- struct cl_page *temp;
- int result = 0;
- ENTRY;
+ info = echo_env_info(env);
+ LASSERT(io == &info->eti_io);
- cl_page_list_for_each_safe(clp, temp, &queue->c2_qin) {
- int rc;
- rc = cl_page_cache_add(env, io, clp, CRT_WRITE);
- if (rc == 0)
- continue;
- result = result ?: rc;
- }
- RETURN(result);
+ queue = &info->eti_queue;
+ cl_page_list_add(&queue->c2_qout, page);
}
-static int cl_echo_object_brw(struct echo_object *eco, int rw, obd_off offset,
- cfs_page_t **pages, int npages, int async)
+static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset,
+ struct page **pages, int npages, int async)
{
struct lu_env *env;
struct echo_thread_info *info;
struct cl_page *clp;
struct lustre_handle lh = { 0 };
int page_size = cl_page_size(obj);
- int refcheck;
int rc;
int i;
+ __u16 refcheck;
ENTRY;
- LASSERT((offset & ~CFS_PAGE_MASK) == 0);
+ LASSERT((offset & ~PAGE_MASK) == 0);
LASSERT(ed->ed_next != NULL);
env = cl_env_get(&refcheck);
if (IS_ERR(env))
rc = cl_echo_enqueue0(env, eco, offset,
- offset + npages * CFS_PAGE_SIZE - 1,
+ offset + npages * PAGE_CACHE_SIZE - 1,
rw == READ ? LCK_PR : LCK_PW, &lh.cookie,
CEF_NEVER);
if (rc < 0)
async = async && (typ == CRT_WRITE);
if (async)
- rc = cl_echo_async_brw(env, io, typ, queue);
- else
+ rc = cl_io_commit_async(env, io, &queue->c2_qin,
+ 0, PAGE_SIZE,
+ echo_commit_callback);
+ else
rc = cl_io_submit_sync(env, io, typ, queue, 0);
CDEBUG(D_INFO, "echo_client %s write returns %d\n",
async ? "async" : "sync", rc);
/** @} echo_exports */
-static obd_id last_object_id;
-
-static int
-echo_copyout_lsm (struct lov_stripe_md *lsm, void *_ulsm, int ulsm_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 (cfs_copy_to_user (ulsm, lsm, sizeof(ulsm)))
- return (-EFAULT);
-
- for (i = 0; i < lsm->lsm_stripe_count; i++) {
- if (cfs_copy_to_user (ulsm->lsm_oinfo[i], lsm->lsm_oinfo[i],
- sizeof(lsm->lsm_oinfo[0])))
- return (-EFAULT);
- }
- return 0;
-}
-
-static int
-echo_copyin_lsm (struct echo_device *ed, struct lov_stripe_md *lsm,
- void *ulsm, int ulsm_nob)
-{
- struct echo_client_obd *ec = ed->ed_ec;
- int i;
-
- if (ulsm_nob < sizeof (*lsm))
- return (-EINVAL);
-
- if (cfs_copy_from_user (lsm, ulsm, sizeof (*lsm)))
- return (-EFAULT);
-
- 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);
-
-
- for (i = 0; i < lsm->lsm_stripe_count; i++) {
- if (cfs_copy_from_user(lsm->lsm_oinfo[i],
- ((struct lov_stripe_md *)ulsm)-> \
- lsm_oinfo[i],
- sizeof(lsm->lsm_oinfo[0])))
- return (-EFAULT);
- }
- return (0);
-}
+static u64 last_object_id;
+#ifdef HAVE_SERVER_SUPPORT
static inline void echo_md_build_name(struct lu_name *lname, char *name,
__u64 id)
{
RETURN(0);
}
-int echo_attr_get_complex(const struct lu_env *env, struct md_object *next,
- struct md_attr *ma)
+static int echo_attr_get_complex(const struct lu_env *env,
+ struct md_object *next,
+ struct md_attr *ma)
{
struct echo_thread_info *info = echo_env_info(env);
struct lu_buf *buf = &info->eti_buf;
- cfs_umode_t mode = lu_object_attr(&next->mo_lu);
+ umode_t mode = lu_object_attr(&next->mo_lu);
int need = ma->ma_need;
int rc = 0, rc2;
ENTRY;
+ if (ec_parent == NULL)
+ return -1;
parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
if (parent == NULL)
RETURN(-ENXIO);
RETURN(ERR_PTR(rc));
}
+ /* In the function below, .hs_keycmp resolves to
+ * lu_obj_hop_keycmp() */
+ /* coverity[overrun-buffer-val] */
child = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, fid, NULL);
RETURN(child);
ENTRY;
+ if (ec_parent == NULL)
+ return -1;
parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
if (parent == NULL)
RETURN(-ENXIO);
ENTRY;
+ if (ec_parent == NULL)
+ return -1;
parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
if (parent == NULL)
RETURN(-ENXIO);
int rc = 0;
int i;
+ if (ec_parent == NULL)
+ return -1;
parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
if (parent == NULL)
return -ENXIO;
GOTO(out_put, rc = -EINVAL);
}
+ if (lu_object_remote(child)) {
+ CERROR("Can not destroy remote object %s: rc = %d\n",
+ lname->ln_name, -EPERM);
+ GOTO(out_put, rc = -EPERM);
+ }
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:
struct echo_device *ed, char *path,
int path_len)
{
- struct lu_device *ld = ed->ed_next;
- struct md_device *md = lu2md_dev(ld);
- struct echo_thread_info *info = echo_env_info(env);
- struct lu_fid *fid = &info->eti_fid;
- struct lu_name *lname = &info->eti_lname;
- struct lu_object *parent = NULL;
- struct lu_object *child = NULL;
- int rc = 0;
- ENTRY;
+ struct lu_device *ld = ed->ed_next;
+ struct echo_thread_info *info = echo_env_info(env);
+ struct lu_fid *fid = &info->eti_fid;
+ struct lu_name *lname = &info->eti_lname;
+ struct lu_object *parent = NULL;
+ struct lu_object *child = NULL;
+ int rc = 0;
+ ENTRY;
- /*Only support MDD layer right now*/
- rc = md->md_ops->mdo_root_get(env, md, fid);
- if (rc) {
- CERROR("get root error: rc = %d\n", rc);
- RETURN(ERR_PTR(rc));
- }
+ *fid = ed->ed_root_fid;
+ /* In the function below, .hs_keycmp resolves to
+ * lu_obj_hop_keycmp() */
+ /* coverity[overrun-buffer-val] */
parent = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, fid, NULL);
if (IS_ERR(parent)) {
CERROR("Can not find the parent "DFID": rc = %ld\n",
RETURN(parent);
}
+static void echo_ucred_init(struct lu_env *env)
+{
+ struct lu_ucred *ucred = lu_ucred(env);
+
+ ucred->uc_valid = UCRED_INVALID;
+
+ ucred->uc_suppgids[0] = -1;
+ ucred->uc_suppgids[1] = -1;
+
+ ucred->uc_uid = ucred->uc_o_uid =
+ from_kuid(&init_user_ns, current_uid());
+ ucred->uc_gid = ucred->uc_o_gid =
+ from_kgid(&init_user_ns, current_gid());
+ ucred->uc_fsuid = ucred->uc_o_fsuid =
+ from_kuid(&init_user_ns, current_fsuid());
+ ucred->uc_fsgid = ucred->uc_o_fsgid =
+ from_kgid(&init_user_ns, current_fsgid());
+ ucred->uc_cap = cfs_curproc_cap_pack();
+
+ /* remove fs privilege for non-root user. */
+ if (ucred->uc_fsuid)
+ ucred->uc_cap &= ~CFS_CAP_FS_MASK;
+ ucred->uc_valid = UCRED_NEW;
+}
+
+static void echo_ucred_fini(struct lu_env *env)
+{
+ struct lu_ucred *ucred = lu_ucred(env);
+ ucred->uc_valid = UCRED_INIT;
+}
+
#define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
-#define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION)
+#define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION | LCT_SERVER_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;
struct lu_env *env;
- int refcheck;
+ __u16 refcheck;
struct lu_object *parent;
char *name = NULL;
int namelen = data->ioc_plen2;
OBD_ALLOC(name, namelen + 1);
if (name == NULL)
GOTO(out_put, rc = -ENOMEM);
- if (cfs_copy_from_user(name, data->ioc_pbuf2, namelen))
+ if (copy_from_user(name, data->ioc_pbuf2, namelen))
GOTO(out_name, rc = -EFAULT);
}
+ echo_ucred_init(env);
+
switch (command) {
case ECHO_MD_CREATE:
case ECHO_MD_MKDIR: {
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] */
rc = -EINVAL;
break;
}
+ echo_ucred_fini(env);
+
out_name:
if (name != NULL)
OBD_FREE(name, namelen + 1);
cl_env_put(env, &refcheck);
return rc;
}
+#endif /* HAVE_SERVER_SUPPORT */
static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
- int on_target, struct obdo *oa, void *ulsm,
- int ulsm_nob, struct obd_trans_info *oti)
+ struct obdo *oa)
{
- struct echo_object *eco;
- struct echo_client_obd *ec = ed->ed_ec;
- struct lov_stripe_md *lsm = NULL;
- int rc;
- int created = 0;
- ENTRY;
-
- if ((oa->o_valid & OBD_MD_FLID) == 0 && /* no obj id */
- (on_target || /* set_stripe */
- ec->ec_nstripes != 0)) { /* LOV */
- CERROR ("No valid oid\n");
- RETURN(-EINVAL);
- }
-
- rc = echo_alloc_memmd(ed, &lsm);
- if (rc < 0) {
- CERROR("Cannot allocate md: rc = %d\n", rc);
- GOTO(failed, rc);
- }
-
- if (ulsm != NULL) {
- int i, idx;
-
- rc = echo_copyin_lsm (ed, lsm, ulsm, ulsm_nob);
- if (rc != 0)
- GOTO(failed, rc);
-
- if (lsm->lsm_stripe_count == 0)
- lsm->lsm_stripe_count = ec->ec_nstripes;
-
- if (lsm->lsm_stripe_size == 0)
- lsm->lsm_stripe_size = CFS_PAGE_SIZE;
-
- 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;
+ struct echo_object *eco;
+ struct echo_client_obd *ec = ed->ed_ec;
+ int created = 0;
+ int rc;
+ ENTRY;
- lsm->lsm_oinfo[i]->loi_ost_idx =
- (idx + i) % ec->ec_nstripes;
- }
- }
+ if (!(oa->o_valid & OBD_MD_FLID) ||
+ !(oa->o_valid & OBD_MD_FLGROUP) ||
+ !fid_seq_is_echo(ostid_seq(&oa->o_oi))) {
+ CERROR("invalid oid "DOSTID"\n", POSTID(&oa->o_oi));
+ RETURN(-EINVAL);
+ }
- /* setup object ID here for !on_target and LOV hint */
- if (oa->o_valid & OBD_MD_FLID)
- lsm->lsm_object_id = oa->o_id;
+ if (ostid_id(&oa->o_oi) == 0)
+ ostid_set_id(&oa->o_oi, ++last_object_id);
- if (lsm->lsm_object_id == 0)
- lsm->lsm_object_id = ++last_object_id;
+ rc = obd_create(env, ec->ec_exp, oa);
+ if (rc != 0) {
+ CERROR("Cannot create objects: rc = %d\n", rc);
+ GOTO(failed, rc);
+ }
- 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;
- }
+ created = 1;
- /* See what object ID we were given */
- oa->o_id = lsm->lsm_object_id;
- oa->o_valid |= OBD_MD_FLID;
+ oa->o_valid |= OBD_MD_FLID;
- eco = cl_echo_object_find(ed, &lsm);
+ eco = cl_echo_object_find(ed, &oa->o_oi);
if (IS_ERR(eco))
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:
- if (created && rc)
- obd_destroy(env, ec->ec_exp, oa, lsm, oti, NULL, NULL);
- if (lsm)
- echo_free_memmd(ed, &lsm);
- if (rc)
- CERROR("create object failed with: rc = %d\n", rc);
- return (rc);
+failed:
+ if (created && rc != 0)
+ obd_destroy(env, ec->ec_exp, oa);
+
+ if (rc != 0)
+ CERROR("create object failed with: rc = %d\n", rc);
+
+ return rc;
}
static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
- struct obdo *oa)
+ struct obdo *oa)
{
- struct lov_stripe_md *lsm = NULL;
- struct echo_object *eco;
- int rc;
- ENTRY;
+ struct echo_object *eco;
+ int rc;
+ ENTRY;
- if ((oa->o_valid & OBD_MD_FLID) == 0 ||
- oa->o_id == 0) /* disallow use of object id 0 */
- {
- CERROR ("No valid oid\n");
- RETURN(-EINVAL);
- }
+ if (!(oa->o_valid & OBD_MD_FLID) ||
+ !(oa->o_valid & OBD_MD_FLGROUP) ||
+ ostid_id(&oa->o_oi) == 0) {
+ CERROR("invalid oid "DOSTID"\n", POSTID(&oa->o_oi));
+ RETURN(-EINVAL);
+ }
- rc = echo_alloc_memmd(ed, &lsm);
- if (rc < 0)
- RETURN(rc);
+ rc = 0;
+ eco = cl_echo_object_find(ed, &oa->o_oi);
+ if (!IS_ERR(eco))
+ *ecop = eco;
+ else
+ rc = PTR_ERR(eco);
- 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;
-
- rc = 0;
- eco = cl_echo_object_find(ed, &lsm);
- if (!IS_ERR(eco))
- *ecop = eco;
- else
- rc = PTR_ERR(eco);
- if (lsm)
- echo_free_memmd(ed, &lsm);
- RETURN(rc);
+ RETURN(rc);
}
static void echo_put_object(struct echo_object *eco)
{
- if (cl_echo_object_put(eco))
- CERROR("echo client: drop an object failed");
-}
-
-static void
-echo_get_stripe_off_id (struct lov_stripe_md *lsm, obd_off *offp, obd_id *idp)
-{
- unsigned long stripe_count;
- unsigned long stripe_size;
- unsigned long width;
- unsigned long woffset;
- int stripe_index;
- obd_off offset;
+ int rc;
- if (lsm->lsm_stripe_count <= 1)
- return;
-
- offset = *offp;
- stripe_size = lsm->lsm_stripe_size;
- stripe_count = lsm->lsm_stripe_count;
-
- /* width = # bytes in all stripes */
- width = stripe_size * stripe_count;
-
- /* woffset = offset within a width; offset = whole number of widths */
- woffset = do_div (offset, width);
-
- stripe_index = woffset / stripe_size;
-
- *idp = lsm->lsm_oinfo[stripe_index]->loi_id;
- *offp = offset * stripe_size + woffset % stripe_size;
+ rc = cl_echo_object_put(eco);
+ if (rc)
+ CERROR("%s: echo client drop an object failed: rc = %d\n",
+ eco->eo_dev->ed_ec->ec_exp->exp_obd->obd_name, rc);
}
-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)
+static void echo_client_page_debug_setup(struct page *page, int rw, u64 id,
+ u64 offset, u64 count)
{
- char *addr;
- obd_off stripe_off;
- obd_id stripe_id;
- int delta;
+ char *addr;
+ u64 stripe_off;
+ u64 stripe_id;
+ int delta;
/* no partial pages on the client */
- LASSERT(count == CFS_PAGE_SIZE);
+ LASSERT(count == PAGE_CACHE_SIZE);
- addr = cfs_kmap(page);
+ addr = kmap(page);
- for (delta = 0; delta < CFS_PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
+ for (delta = 0; delta < PAGE_CACHE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
if (rw == OBD_BRW_WRITE) {
stripe_off = offset + delta;
stripe_id = id;
- echo_get_stripe_off_id(lsm, &stripe_off, &stripe_id);
} else {
stripe_off = 0xdeadbeef00c0ffeeULL;
stripe_id = 0xdeadbeef00c0ffeeULL;
stripe_off, stripe_id);
}
- cfs_kunmap(page);
+ 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 page *page, u64 id, u64 offset, u64 count)
{
- obd_off stripe_off;
- obd_id stripe_id;
+ u64 stripe_off;
+ u64 stripe_id;
char *addr;
int delta;
int rc;
int rc2;
/* no partial pages on the client */
- LASSERT(count == CFS_PAGE_SIZE);
+ LASSERT(count == PAGE_CACHE_SIZE);
- addr = cfs_kmap(page);
+ addr = kmap(page);
- for (rc = delta = 0; delta < CFS_PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
+ for (rc = delta = 0; delta < PAGE_CACHE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
stripe_off = offset + delta;
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,
}
}
- cfs_kunmap(page);
+ kunmap(page);
return rc;
}
static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
- struct echo_object *eco, obd_off offset,
- obd_size count, int async,
- struct obd_trans_info *oti)
+ struct echo_object *eco, u64 offset,
+ u64 count, int async)
{
- struct lov_stripe_md *lsm = eco->eo_lsm;
- obd_count npages;
+ size_t npages;
struct brw_page *pga;
struct brw_page *pgp;
- cfs_page_t **pages;
- obd_off off;
- int i;
+ struct page **pages;
+ u64 off;
+ size_t i;
int rc;
int verify;
- int gfp_mask;
- int brw_flags = 0;
+ gfp_t gfp_mask;
+ u32 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) ? GFP_IOFS : GFP_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);
- if (count <= 0 ||
- (count & (~CFS_PAGE_MASK)) != 0)
- RETURN(-EINVAL);
+ if ((count & (~PAGE_MASK)) != 0)
+ RETURN(-EINVAL);
/* XXX think again with misaligned I/O */
- npages = count >> CFS_PAGE_SHIFT;
+ npages = count >> PAGE_CACHE_SHIFT;
if (rw == OBD_BRW_WRITE)
brw_flags = OBD_BRW_ASYNC;
RETURN(-ENOMEM);
}
- for (i = 0, pgp = pga, off = offset;
- i < npages;
- i++, pgp++, off += CFS_PAGE_SIZE) {
+ for (i = 0, pgp = pga, off = offset;
+ i < npages;
+ i++, pgp++, off += PAGE_CACHE_SIZE) {
- LASSERT (pgp->pg == NULL); /* for cleanup */
+ LASSERT(pgp->pg == NULL); /* for cleanup */
- rc = -ENOMEM;
- OBD_PAGE_ALLOC(pgp->pg, gfp_mask);
- if (pgp->pg == NULL)
- goto out;
+ rc = -ENOMEM;
+ pgp->pg = alloc_page(gfp_mask);
+ if (pgp->pg == NULL)
+ goto out;
- pages[i] = pgp->pg;
- pgp->count = CFS_PAGE_SIZE;
- pgp->off = off;
- pgp->flag = brw_flags;
+ pages[i] = pgp->pg;
+ pgp->count = PAGE_CACHE_SIZE;
+ 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(pgp->pg, rw,
+ ostid_id(&oa->o_oi), off,
+ pgp->count);
+ }
/* brw mode can only be used at client */
LASSERT(ed->ed_next != NULL);
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(pgp->pg,
+ ostid_id(&oa->o_oi),
+ pgp->off, pgp->count);
+ if (vrc != 0 && rc == 0)
+ rc = vrc;
+ }
+ __free_page(pgp->pg);
}
OBD_FREE(pga, npages * sizeof(*pga));
OBD_FREE(pages, npages * sizeof(*pages));
static int echo_client_prep_commit(const struct lu_env *env,
struct obd_export *exp, int rw,
struct obdo *oa, struct echo_object *eco,
- obd_off offset, obd_size count,
- obd_size batch, struct obd_trans_info *oti,
- int async)
-{
- struct lov_stripe_md *lsm = eco->eo_lsm;
- struct obd_ioobj ioo;
- struct niobuf_local *lnb;
- struct niobuf_remote *rnb;
- obd_off off;
- obd_size npages, tot_pages;
+ u64 offset, u64 count,
+ u64 batch, int async)
+{
+ struct obd_ioobj ioo;
+ struct niobuf_local *lnb;
+ struct niobuf_remote rnb;
+ u64 off;
+ u64 npages, tot_pages;
int i, ret = 0, brw_flags = 0;
ENTRY;
- if (count <= 0 || (count & (~CFS_PAGE_MASK)) != 0 ||
- (lsm != NULL && lsm->lsm_object_id != oa->o_id))
- RETURN(-EINVAL);
-
- npages = batch >> CFS_PAGE_SHIFT;
- tot_pages = count >> CFS_PAGE_SHIFT;
+ if (count <= 0 || (count & ~PAGE_CACHE_MASK) != 0)
+ RETURN(-EINVAL);
- OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local));
- OBD_ALLOC(rnb, npages * sizeof(struct niobuf_remote));
+ npages = batch >> PAGE_CACHE_SHIFT;
+ tot_pages = count >> PAGE_CACHE_SHIFT;
- if (lnb == NULL || rnb == NULL)
- GOTO(out, ret = -ENOMEM);
+ OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local));
+ if (lnb == NULL)
+ GOTO(out, ret = -ENOMEM);
if (rw == OBD_BRW_WRITE && async)
brw_flags |= OBD_BRW_ASYNC;
- obdo_to_ioobj(oa, &ioo);
+ obdo_to_ioobj(oa, &ioo);
- off = offset;
+ off = offset;
- for(; tot_pages; tot_pages -= npages) {
- int lpages;
+ for (; tot_pages > 0; tot_pages -= npages) {
+ int lpages;
- if (tot_pages < npages)
- npages = tot_pages;
+ if (tot_pages < npages)
+ npages = tot_pages;
- for (i = 0; i < npages; i++, off += CFS_PAGE_SIZE) {
- rnb[i].offset = off;
- rnb[i].len = CFS_PAGE_SIZE;
- rnb[i].flags = brw_flags;
- }
-
- ioo.ioo_bufcnt = npages;
- oti->oti_transno = 0;
+ rnb.rnb_offset = off;
+ rnb.rnb_len = npages * PAGE_CACHE_SIZE;
+ rnb.rnb_flags = brw_flags;
+ ioo.ioo_bufcnt = 1;
+ off += npages * PAGE_CACHE_SIZE;
lpages = npages;
- ret = obd_preprw(env, rw, exp, oa, 1, &ioo, rnb, &lpages,
- lnb, oti, NULL);
+ ret = obd_preprw(env, rw, exp, oa, 1, &ioo, &rnb, &lpages, lnb);
if (ret != 0)
GOTO(out, ret);
- LASSERT(lpages == npages);
-
- for (i = 0; i < lpages; i++) {
- cfs_page_t *page = lnb[i].page;
-
- /* read past eof? */
- if (page == NULL && lnb[i].rc == 0)
- continue;
- 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);
- }
+ for (i = 0; i < lpages; i++) {
+ struct page *page = lnb[i].lnb_page;
+
+ /* read past eof? */
+ if (page == NULL && lnb[i].lnb_rc == 0)
+ continue;
+
+ if (async)
+ lnb[i].lnb_flags |= OBD_BRW_ASYNC;
+
+ 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(page, rw,
+ ostid_id(&oa->o_oi),
+ lnb[i].lnb_file_offset,
+ lnb[i].lnb_len);
+ else
+ echo_client_page_debug_check(page,
+ ostid_id(&oa->o_oi),
+ lnb[i].lnb_file_offset,
+ lnb[i].lnb_len);
+ }
- ret = obd_commitrw(env, rw, exp, oa, 1, &ioo,
- rnb, npages, lnb, oti, ret);
+ ret = obd_commitrw(env, rw, exp, oa, 1, &ioo, &rnb, npages, lnb,
+ ret);
if (ret != 0)
GOTO(out, ret);
- /* Reset oti otherwise it would confuse ldiskfs. */
- memset(oti, 0, sizeof(*oti));
- }
+ /* Reuse env context. */
+ lu_context_exit((struct lu_context *)&env->le_ctx);
+ lu_context_enter((struct lu_context *)&env->le_ctx);
+ }
out:
- if (lnb)
- OBD_FREE(lnb, npages * sizeof(struct niobuf_local));
- if (rnb)
- OBD_FREE(rnb, npages * sizeof(struct niobuf_remote));
- RETURN(ret);
+ if (lnb)
+ OBD_FREE(lnb, npages * sizeof(struct niobuf_local));
+ RETURN(ret);
}
static int echo_client_brw_ioctl(const struct lu_env *env, int rw,
struct obd_export *exp,
- struct obd_ioctl_data *data,
- struct obd_trans_info *dummy_oti)
+ struct obd_ioctl_data *data)
{
struct obd_device *obd = class_exp2obd(exp);
struct echo_device *ed = obd2echo_dev(obd);
struct obdo *oa = &data->ioc_obdo1;
struct echo_object *eco;
int rc;
- int async = 1;
+ int async = 0;
long test_mode;
ENTRY;
/* OFD/obdfilter works only via prep/commit */
test_mode = (long)data->ioc_pbuf1;
- if (test_mode == 1)
- async = 0;
-
if (ed->ed_next == NULL && test_mode != 3) {
test_mode = 3;
data->ioc_plen1 = data->ioc_count;
}
+ if (test_mode == 3)
+ async = 1;
+
/* Truncate batch size to maximum */
if (data->ioc_plen1 > PTLRPC_MAX_BRW_SIZE)
data->ioc_plen1 = PTLRPC_MAX_BRW_SIZE;
case 1:
/* fall through */
case 2:
- rc = echo_client_kbrw(ed, rw, oa,
- eco, data->ioc_offset,
- data->ioc_count, async, dummy_oti);
- break;
- case 3:
- rc = echo_client_prep_commit(env, ec->ec_exp, rw, oa,
- eco, data->ioc_offset,
- data->ioc_count, data->ioc_plen1,
- dummy_oti, async);
- break;
- default:
- rc = -EINVAL;
- }
- echo_put_object(eco);
- RETURN(rc);
-}
-
-static int
-echo_client_enqueue(struct obd_export *exp, struct obdo *oa,
- int mode, obd_off offset, obd_size nob)
-{
- struct echo_device *ed = obd2echo_dev(exp->exp_obd);
- struct lustre_handle *ulh = &oa->o_handle;
- struct echo_object *eco;
- obd_off end;
- int rc;
- ENTRY;
-
- if (ed->ed_next == NULL)
- RETURN(-EOPNOTSUPP);
-
- if (!(mode == LCK_PR || mode == LCK_PW))
- RETURN(-EINVAL);
-
- if ((offset & (~CFS_PAGE_MASK)) != 0 ||
- (nob & (~CFS_PAGE_MASK)) != 0)
- RETURN(-EINVAL);
-
- rc = echo_get_object (&eco, ed, oa);
- if (rc != 0)
- RETURN(rc);
-
- end = (nob == 0) ? ((obd_off) -1) : (offset + nob - 1);
- rc = cl_echo_enqueue(eco, offset, end, mode, &ulh->cookie);
- if (rc == 0) {
- oa->o_valid |= OBD_MD_FLHANDLE;
- CDEBUG(D_INFO, "Cookie is "LPX64"\n", ulh->cookie);
- }
- echo_put_object(eco);
- RETURN(rc);
-}
-
-static int
-echo_client_cancel(struct obd_export *exp, struct obdo *oa)
-{
- struct echo_device *ed = obd2echo_dev(exp->exp_obd);
- __u64 cookie = oa->o_handle.cookie;
+ rc = echo_client_kbrw(ed, rw, oa, eco, data->ioc_offset,
+ data->ioc_count, async);
+ break;
+ case 3:
+ rc = echo_client_prep_commit(env, ec->ec_exp, rw, oa, eco,
+ data->ioc_offset, data->ioc_count,
+ data->ioc_plen1, async);
+ break;
+ default:
+ rc = -EINVAL;
+ }
- if ((oa->o_valid & OBD_MD_FLHANDLE) == 0)
- return -EINVAL;
+ echo_put_object(eco);
- CDEBUG(D_INFO, "Cookie is "LPX64"\n", cookie);
- return cl_echo_cancel(ed, cookie);
+ RETURN(rc);
}
static int
echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
- void *karg, void *uarg)
+ void *karg, void __user *uarg)
{
+#ifdef HAVE_SERVER_SUPPORT
+ struct tgt_session_info *tsi;
+#endif
struct obd_device *obd = exp->exp_obd;
struct echo_device *ed = obd2echo_dev(obd);
struct echo_client_obd *ec = ed->ed_ec;
struct echo_object *eco;
struct obd_ioctl_data *data = karg;
- struct obd_trans_info dummy_oti;
struct lu_env *env;
- struct oti_req_ack_lock *ack_lock;
struct obdo *oa;
struct lu_fid fid;
int rw = OBD_BRW_READ;
int rc = 0;
- int i;
+#ifdef HAVE_SERVER_SUPPORT
+ struct lu_context echo_session;
+#endif
ENTRY;
- 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);
if (env == NULL)
RETURN(-ENOMEM);
- rc = lu_env_init(env, LCT_DT_THREAD);
- if (rc)
- GOTO(out, rc = -ENOMEM);
+ rc = lu_env_init(env, LCT_DT_THREAD);
+ if (rc)
+ GOTO(out_alloc, rc = -ENOMEM);
+#ifdef HAVE_SERVER_SUPPORT
+ env->le_ses = &echo_session;
+ rc = lu_context_init(env->le_ses, LCT_SERVER_SESSION | LCT_NOREF);
+ if (unlikely(rc < 0))
+ GOTO(out_env, rc);
+ lu_context_enter(env->le_ses);
+
+ tsi = tgt_ses_info(env);
+ tsi->tsi_exp = ec->ec_exp;
+ tsi->tsi_jobid = NULL;
+#endif
switch (cmd) {
case OBD_IOC_CREATE: /* may create echo object */
if (!cfs_capable(CFS_CAP_SYS_ADMIN))
GOTO (out, rc = -EPERM);
- rc = echo_create_object(env, ed, 1, oa, data->ioc_pbuf1,
- data->ioc_plen1, &dummy_oti);
+ rc = echo_create_object(env, ed, oa);
GOTO(out, rc);
- 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);
-
- count = data->ioc_count;
- cmd = data->ioc_command;
-
- id = data->ioc_obdo2.o_id;
-
- 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);
- }
+#ifdef HAVE_SERVER_SUPPORT
+ 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);
+
+ count = data->ioc_count;
+ cmd = data->ioc_command;
+
+ id = data->ioc_obdo2.o_oi.oi.oi_id;
+ dirlen = data->ioc_plen1;
+ OBD_ALLOC(dir, dirlen + 1);
+ if (dir == NULL)
+ GOTO(out, rc = -ENOMEM);
+
+ if (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;
+ __u16 refcheck;
__u64 seq;
int max_count;
GOTO(out, rc);
}
- if (cfs_copy_to_user(data->ioc_pbuf1, &seq, data->ioc_plen1))
+ if (copy_to_user(data->ioc_pbuf1, &seq, data->ioc_plen1))
return -EFAULT;
- max_count = LUSTRE_SEQ_MAX_WIDTH;
- if (cfs_copy_to_user(data->ioc_pbuf2, &max_count,
- data->ioc_plen2))
- return -EFAULT;
- GOTO(out, rc);
+ max_count = LUSTRE_METADATA_SEQ_MAX_WIDTH;
+ if (copy_to_user(data->ioc_pbuf2, &max_count,
+ data->ioc_plen2))
+ return -EFAULT;
+ GOTO(out, rc);
}
+#endif /* HAVE_SERVER_SUPPORT */
case OBD_IOC_DESTROY:
if (!cfs_capable(CFS_CAP_SYS_ADMIN))
GOTO (out, rc = -EPERM);
rc = echo_get_object(&eco, ed, oa);
if (rc == 0) {
- rc = obd_destroy(env, ec->ec_exp, oa, eco->eo_lsm,
- &dummy_oti, NULL, NULL);
+ rc = obd_destroy(env, ec->ec_exp, oa);
if (rc == 0)
eco->eo_deleted = 1;
echo_put_object(eco);
case OBD_IOC_GETATTR:
rc = echo_get_object(&eco, ed, oa);
if (rc == 0) {
- struct obd_info oinfo = { { { 0 } } };
- oinfo.oi_md = eco->eo_lsm;
- oinfo.oi_oa = oa;
- rc = obd_getattr(env, ec->ec_exp, &oinfo);
+ rc = obd_getattr(env, ec->ec_exp, oa);
echo_put_object(eco);
}
GOTO(out, rc);
rc = echo_get_object(&eco, ed, oa);
if (rc == 0) {
- struct obd_info oinfo = { { { 0 } } };
- oinfo.oi_oa = oa;
- oinfo.oi_md = eco->eo_lsm;
-
- rc = obd_setattr(env, ec->ec_exp, &oinfo, NULL);
+ rc = obd_setattr(env, ec->ec_exp, oa);
echo_put_object(eco);
}
GOTO(out, rc);
rw = OBD_BRW_WRITE;
/* fall through */
case OBD_IOC_BRW_READ:
- rc = echo_client_brw_ioctl(env, rw, exp, data, &dummy_oti);
+ rc = echo_client_brw_ioctl(env, rw, exp, data);
GOTO(out, rc);
- case ECHO_IOC_GET_STRIPE:
- rc = echo_get_object(&eco, ed, oa);
- if (rc == 0) {
- rc = echo_copyout_lsm(eco->eo_lsm, data->ioc_pbuf1,
- data->ioc_plen1);
- echo_put_object(eco);
- }
- GOTO(out, rc);
-
- case ECHO_IOC_SET_STRIPE:
- if (!cfs_capable(CFS_CAP_SYS_ADMIN))
- GOTO (out, rc = -EPERM);
-
- if (data->ioc_pbuf1 == NULL) { /* unset */
- rc = echo_get_object(&eco, ed, oa);
- if (rc == 0) {
- eco->eo_deleted = 1;
- echo_put_object(eco);
- }
- } else {
- rc = echo_create_object(env, ed, 0, oa,
- data->ioc_pbuf1,
- data->ioc_plen1, &dummy_oti);
- }
- GOTO (out, rc);
-
- case ECHO_IOC_ENQUEUE:
- if (!cfs_capable(CFS_CAP_SYS_ADMIN))
- GOTO (out, rc = -EPERM);
-
- rc = echo_client_enqueue(exp, oa,
- data->ioc_conn1, /* lock mode */
- data->ioc_offset,
- data->ioc_count);/*extent*/
- GOTO (out, rc);
-
- case ECHO_IOC_CANCEL:
- rc = echo_client_cancel(exp, oa);
- GOTO (out, rc);
-
default:
CERROR ("echo_ioctl(): unrecognised ioctl %#x\n", cmd);
GOTO (out, rc = -ENOTTY);
EXIT;
out:
+#ifdef HAVE_SERVER_SUPPORT
+ lu_context_exit(env->le_ses);
+ lu_context_fini(env->le_ses);
+out_env:
+#endif
lu_env_fini(env);
+out_alloc:
OBD_FREE_PTR(env);
- /* 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;
- i++, ack_lock++) {
- if (!ack_lock->mode)
- break;
- ldlm_lock_decref(&ack_lock->lock, ack_lock->mode);
- }
-
return rc;
}
}
spin_lock_init(&ec->ec_lock);
- CFS_INIT_LIST_HEAD (&ec->ec_objects);
- CFS_INIT_LIST_HEAD (&ec->ec_locks);
+ INIT_LIST_HEAD(&ec->ec_objects);
+ INIT_LIST_HEAD(&ec->ec_locks);
ec->ec_unique = 0;
- ec->ec_nstripes = 0;
- if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
- lu_context_tags_update(ECHO_MD_CTX_TAG);
- lu_session_tags_update(ECHO_MD_SES_TAG);
- RETURN(0);
- }
+ if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
+#ifdef HAVE_SERVER_SUPPORT
+ lu_context_tags_update(ECHO_MD_CTX_TAG);
+ lu_session_tags_update(ECHO_MD_SES_TAG);
+#else
+ CERROR("Local operations are NOT supported on client side. "
+ "Only remote operations are supported. Metadata client "
+ "must be run on server side.\n");
+#endif
+ RETURN(0);
+ }
OBD_ALLOC(ocd, sizeof(*ocd));
if (ocd == NULL) {
}
ocd->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_REQPORTAL |
+ OBD_CONNECT_BRW_SIZE |
OBD_CONNECT_GRANT | OBD_CONNECT_FULL20 |
- OBD_CONNECT_64BITHASH;
+ OBD_CONNECT_64BITHASH | OBD_CONNECT_LVB_TYPE |
+ OBD_CONNECT_FID;
+ ocd->ocd_brw_size = DT_MAX_BRW_SIZE;
ocd->ocd_version = LUSTRE_VERSION_CODE;
ocd->ocd_group = FID_SEQ_ECHO;
if (rc == 0) {
/* Turn off pinger because it connects to tgt obd directly. */
spin_lock(&tgt->obd_dev_lock);
- cfs_list_del_init(&ec->ec_exp->exp_obd_chain_timed);
+ list_del_init(&ec->ec_exp->exp_obd_chain_timed);
spin_unlock(&tgt->obd_dev_lock);
}
RETURN(0);
if (ed->ed_next_ismd) {
- lu_context_tags_clear(ECHO_MD_CTX_TAG);
- lu_session_tags_clear(ECHO_MD_SES_TAG);
+#ifdef HAVE_SERVER_SUPPORT
+ lu_context_tags_clear(ECHO_MD_CTX_TAG);
+ lu_session_tags_clear(ECHO_MD_SES_TAG);
+#else
+ CERROR("This is client-side only module, does not support "
+ "metadata echo client.\n");
+#endif
RETURN(0);
}
- if (!cfs_list_empty(&obddev->obd_exports)) {
+ if (!list_empty(&obddev->obd_exports)) {
CERROR("still has clients!\n");
RETURN(-EBUSY);
}
- LASSERT(cfs_atomic_read(&ec->ec_exp->exp_refcount) > 0);
+ LASSERT(atomic_read(&ec->ec_exp->exp_refcount) > 0);
rc = obd_disconnect(ec->ec_exp);
if (rc != 0)
CERROR("fail to disconnect device: %d\n", rc);
static int echo_client_disconnect(struct obd_export *exp)
{
-#if 0
- struct obd_device *obd;
- struct echo_client_obd *ec;
- struct ec_lock *ecl;
-#endif
int rc;
ENTRY;
if (exp == NULL)
GOTO(out, rc = -EINVAL);
-#if 0
- obd = exp->exp_obd;
- ec = &obd->u.echo_client;
-
- /* no more contention on export's lock list */
- while (!cfs_list_empty (&exp->exp_ec_data.eced_locks)) {
- ecl = cfs_list_entry (exp->exp_ec_data.eced_locks.next,
- struct ec_lock, ecl_exp_chain);
- cfs_list_del (&ecl->ecl_exp_chain);
-
- rc = obd_cancel(ec->ec_exp, ecl->ecl_object->eco_lsm,
- ecl->ecl_mode, &ecl->ecl_lock_handle);
-
- CDEBUG (D_INFO, "Cancel lock on object "LPX64" on disconnect "
- "(%d)\n", ecl->ecl_object->eco_id, rc);
-
- echo_put_object (ecl->ecl_object);
- OBD_FREE (ecl, sizeof (*ecl));
- }
-#endif
-
rc = class_disconnect(exp);
GOTO(out, rc);
out:
static struct obd_ops echo_client_obd_ops = {
.o_owner = THIS_MODULE,
-
-#if 0
- .o_setup = echo_client_setup,
- .o_cleanup = echo_client_cleanup,
-#endif
-
.o_iocontrol = echo_client_iocontrol,
.o_connect = echo_client_connect,
.o_disconnect = echo_client_disconnect
};
-int echo_client_init(void)
-{
- struct lprocfs_static_vars lvars = { 0 };
- int rc;
-
- lprocfs_echo_init_vars(&lvars);
-
- rc = lu_kmem_init(echo_caches);
- if (rc == 0) {
- rc = class_register_type(&echo_client_obd_ops, NULL,
- lvars.module_vars,
- LUSTRE_ECHO_CLIENT_NAME,
- &echo_device_type);
- if (rc)
- lu_kmem_fini(echo_caches);
- }
- return rc;
-}
-
-void echo_client_exit(void)
-{
- class_unregister_type(LUSTRE_ECHO_CLIENT_NAME);
- lu_kmem_fini(echo_caches);
-}
-
-#ifdef __KERNEL__
static int __init obdecho_init(void)
{
- struct lprocfs_static_vars lvars;
int rc;
ENTRY;
LCONSOLE_INFO("Echo OBD driver; http://www.lustre.org/\n");
- LASSERT(CFS_PAGE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
-
- lprocfs_echo_init_vars(&lvars);
+ LASSERT(PAGE_CACHE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
# ifdef HAVE_SERVER_SUPPORT
rc = echo_persistent_pages_init();
if (rc != 0)
goto failed_0;
- rc = class_register_type(&echo_obd_ops, NULL, lvars.module_vars,
- LUSTRE_ECHO_NAME, NULL);
- if (rc != 0)
- goto failed_1;
+ rc = class_register_type(&echo_obd_ops, NULL, true, NULL,
+ LUSTRE_ECHO_NAME, NULL);
+ if (rc != 0)
+ goto failed_1;
# endif
- rc = echo_client_init();
+ rc = lu_kmem_init(echo_caches);
+ if (rc == 0) {
+ rc = class_register_type(&echo_client_obd_ops, NULL, true, NULL,
+ LUSTRE_ECHO_CLIENT_NAME,
+ &echo_device_type);
+ if (rc)
+ lu_kmem_fini(echo_caches);
+ }
# ifdef HAVE_SERVER_SUPPORT
if (rc == 0)
RETURN(rc);
}
-static void /*__exit*/ obdecho_exit(void)
+static void __exit obdecho_exit(void)
{
- echo_client_exit();
+ class_unregister_type(LUSTRE_ECHO_CLIENT_NAME);
+ lu_kmem_fini(echo_caches);
-# ifdef HAVE_SERVER_SUPPORT
- class_unregister_type(LUSTRE_ECHO_NAME);
- echo_persistent_pages_fini();
-# endif
+#ifdef HAVE_SERVER_SUPPORT
+ class_unregister_type(LUSTRE_ECHO_NAME);
+ echo_persistent_pages_fini();
+#endif
}
-MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
-MODULE_DESCRIPTION("Lustre Testing Echo OBD driver");
+MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
+MODULE_DESCRIPTION("Lustre Echo Client test driver");
+MODULE_VERSION(LUSTRE_VERSION_STRING);
MODULE_LICENSE("GPL");
-cfs_module(obdecho, LUSTRE_VERSION_STRING, obdecho_init, obdecho_exit);
-#endif /* __KERNEL__ */
+module_init(obdecho_init);
+module_exit(obdecho_exit);
/** @} echo_client */