*
* Copyright (C) 2006 Cluster File Systems, Inc.
* Author: WangDi <wangdi@clusterfs.com>
+ * Yury Umanets <umka@clusterfs.com>
*
* This file is part of the Lustre file system, http://www.lustre.org
* Lustre is a trademark of Cluster File Systems, Inc.
#ifndef EXPORT_SYMTAB
# define EXPORT_SYMTAB
#endif
-#define DEBUG_SUBSYSTEM S_LLITE
-
-#include <linux/module.h>
-#include <linux/jbd.h>
+#define DEBUG_SUBSYSTEM S_FLD
+
+#ifdef __KERNEL__
+# include <libcfs/libcfs.h>
+# include <linux/module.h>
+# include <linux/jbd.h>
+#else /* __KERNEL__ */
+# include <liblustre.h>
+# include <libcfs/list.h>
+#endif
#include <obd.h>
#include <obd_class.h>
#include <dt_object.h>
#include <md_object.h>
-#include <lustre_mdc.h>
#include <lustre_fld.h>
#include "fld_internal.h"
-static int fld_handle(const struct lu_context *ctx,
- struct lu_fld *fld, __u32 opts, struct md_fld *mf);
-
-/*XXX maybe these 2 items should go to sbi*/
-struct fld_cache_info *fld_cache = NULL;
-
static int dht_mdt_hash(__u64 seq)
{
return 0;
}
-struct obd_export* get_fld_exp(struct obd_export *exp, __u64 seq)
+
+struct obd_export *
+get_fld_exp(struct obd_export *exp, __u64 seq)
{
int seq_mds;
seq_mds = dht_mdt_hash(seq);
CDEBUG(D_INFO, "mds number %d\n", seq_mds);
- /*get exp according to lu_seq*/
+ /* get exp according to lu_seq */
return exp;
}
+#ifdef __KERNEL__
+static int fld_handle(const struct lu_context *ctx,
+ struct lu_fld *fld, __u32 opts,
+ struct md_fld *mf);
+
+/* XXX: maybe these 2 items should go to sbi */
+struct fld_cache_info *fld_cache = NULL;
+
enum {
FLD_HTABLE_BITS = 8,
FLD_HTABLE_SIZE = (1 << FLD_HTABLE_BITS),
return lu_seq;
}
-
-static int fld_cache_insert(struct fld_cache_info *fld_cache, __u64 lu_seq,
- __u64 mds_num)
+static int
+fld_cache_insert(struct fld_cache_info *fld_cache,
+ __u64 lu_seq, __u64 mds_num)
{
struct fld_cache *fld;
struct hlist_head *bucket;
RETURN(rc);
}
-static struct fld_cache*
+static struct fld_cache *
fld_cache_lookup(struct fld_cache_info *fld_cache, __u64 lu_seq)
{
struct hlist_head *bucket;
RETURN(NULL);
}
-static void fld_cache_delete(struct fld_cache_info *fld_cache, __u64 lu_seq)
+static void
+fld_cache_delete(struct fld_cache_info *fld_cache, __u64 lu_seq)
{
struct hlist_head *bucket;
struct hlist_node *scan;
spin_unlock(&fld_cache->fld_lock);
return;
}
+#endif
-int fld_create(struct obd_export *exp, __u64 seq, __u64 mds_num)
+static int fld_rpc(struct obd_export *exp, struct md_fld *mf, __u32 fld_op)
+{
+ struct ptlrpc_request *req;
+ struct md_fld *pmf;
+ int mf_size = sizeof(*mf);
+ __u32 *op;
+ int size[2] = {sizeof(*op), mf_size}, rc;
+ ENTRY;
+
+ req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
+ FLD_QUERY, 2, size, NULL);
+ if (req == NULL)
+ RETURN(-ENOMEM);
+
+ op = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*op));
+ *op = fld_op;
+
+ pmf = lustre_msg_buf(req->rq_reqmsg, 1, sizeof (*pmf));
+ memcpy(pmf, mf, sizeof(*mf));
+
+ req->rq_replen = lustre_msg_size(1, &mf_size);
+ req->rq_request_portal = MDS_FLD_PORTAL;
+ rc = ptlrpc_queue_wait(req);
+ if (rc)
+ GOTO(out_req, rc);
+
+ pmf = lustre_swab_repbuf(req, 0, sizeof(*pmf), lustre_swab_md_fld);
+ *mf = *pmf;
+out_req:
+ ptlrpc_req_finished(req);
+ RETURN(rc);
+}
+
+int
+fld_create(struct obd_export *exp, __u64 seq, __u64 mds_num)
{
struct obd_export *fld_exp;
struct md_fld md_fld;
fld_exp = get_fld_exp(exp, seq);
if (!fld_exp)
RETURN(-EINVAL);
-
+
md_fld.mf_seq = seq;
md_fld.mf_mds = mds_num;
- rc = mdc_fld(fld_exp, &md_fld, FLD_CREATE);
+ rc = fld_rpc(fld_exp, &md_fld, FLD_CREATE);
+
+#ifdef __KERNEL__
fld_cache_insert(fld_cache, seq, mds_num);
-
+#endif
+
RETURN(rc);
}
-int fld_delete(struct obd_export *exp, __u64 seq, __u64 mds_num)
+int
+fld_delete(struct obd_export *exp, __u64 seq, __u64 mds_num)
{
struct obd_export *fld_exp;
struct md_fld md_fld;
__u32 rc;
+#ifdef __KERNEL__
fld_cache_delete(fld_cache, seq);
-
+#endif
+
fld_exp = get_fld_exp(exp, seq);
if (!fld_exp)
RETURN(-EINVAL);
md_fld.mf_seq = seq;
md_fld.mf_mds = mds_num;
- rc = mdc_fld(fld_exp, &md_fld, FLD_DELETE);
-
+ rc = fld_rpc(fld_exp, &md_fld, FLD_DELETE);
RETURN(rc);
}
-int fld_get(struct obd_export *exp, __u64 lu_seq, __u64 *mds_num)
+int
+fld_get(struct obd_export *exp, __u64 lu_seq, __u64 *mds_num)
{
struct obd_export *fld_exp;
struct md_fld md_fld;
RETURN(-EINVAL);
md_fld.mf_seq = lu_seq;
-
vallen = sizeof(struct md_fld);
- rc = mdc_fld(fld_exp, &md_fld, FLD_GET);
-
- *mds_num = md_fld.mf_mds;
+ rc = fld_rpc(fld_exp, &md_fld, FLD_GET);
+ if (rc == 0)
+ *mds_num = md_fld.mf_mds;
RETURN(rc);
}
-/*lookup fid in the namespace of pfid according to the name*/
-int fld_lookup(struct obd_export *exp, __u64 lu_seq, __u64 *mds_num)
+/* lookup fid in the namespace of pfid according to the name */
+int
+fld_lookup(struct obd_export *exp, __u64 lu_seq, __u64 *mds_num)
{
struct fld_cache *fld;
int rc;
ENTRY;
- /*lookup it in the cache*/
+#ifdef __KERNEL__
+ /* lookup it in the cache */
fld = fld_cache_lookup(fld_cache, lu_seq);
if (fld != NULL) {
*mds_num = fld->fld_mds;
RETURN(0);
}
- /*can not find it in the cache*/
+#endif
+
+ /* can not find it in the cache */
rc = fld_get(exp, lu_seq, mds_num);
if (rc)
RETURN(rc);
+#ifdef __KERNEL__
rc = fld_cache_insert(fld_cache, lu_seq, *mds_num);
-
+#endif
+
RETURN(rc);
}
+#ifdef __KERNEL__
static int fld_init(void)
{
ENTRY;
if (fld_cache == NULL)
RETURN(-ENOMEM);
- /*init fld cache info*/
+ /* init fld cache info */
fld_cache->fld_hash_mask = FLD_HTABLE_MASK;
OBD_ALLOC(fld_cache->fld_hash, FLD_HTABLE_SIZE *
- sizeof fld_cache->fld_hash[0]);
+ sizeof fld_cache->fld_hash[0]);
spin_lock_init(&fld_cache->fld_lock);
RETURN(0);
{
if (fld_cache != NULL) {
OBD_FREE(fld_cache->fld_hash, FLD_HTABLE_SIZE *
- sizeof fld_cache->fld_hash[0]);
+ sizeof fld_cache->fld_hash[0]);
OBD_FREE_PTR(fld_cache);
}
return 0;
}
-struct fld_list fld_list_head;
+static struct fld_list fld_list_head;
-static int fld_req_handle0(const struct lu_context *ctx,
- struct lu_fld *fld, struct ptlrpc_request *req)
+static int
+fld_req_handle0(const struct lu_context *ctx,
+ struct lu_fld *fld, struct ptlrpc_request *req)
{
struct md_fld *in;
struct md_fld *out;
*out = *in;
rc = fld_handle(ctx, fld, *opt, out);
- } else
+ } else {
CERROR("Cannot unpack mf\n");
- } else
+ }
+ } else {
CERROR("Cannot unpack option\n");
+ }
RETURN(rc);
}
static int fld_req_handle(struct ptlrpc_request *req)
{
- int result;
+ int fail = OBD_FAIL_FLD_ALL_REPLY_NET;
const struct lu_context *ctx;
struct lu_site *site;
-
+ int result;
ENTRY;
+ OBD_FAIL_RETURN(OBD_FAIL_FLD_ALL_REPLY_NET | OBD_FAIL_ONCE, 0);
+
ctx = req->rq_svc_thread->t_ctx;
LASSERT(ctx != NULL);
LASSERT(ctx->lc_thread == req->rq_svc_thread);
site = req->rq_export->exp_obd->obd_lu_dev->ld_site;
LASSERT(site != NULL);
result = fld_req_handle0(ctx, site->ls_fld, req);
- } else
+ } else {
CERROR("Unconnected request\n");
- } else
+ req->rq_status = -ENOTCONN;
+ GOTO(out, result = -ENOTCONN);
+ }
+ } else {
CERROR("Wrong opcode: %d\n", req->rq_reqmsg->opc);
+ req->rq_status = -ENOTSUPP;
+ result = ptlrpc_error(req);
+ RETURN(result);
+ }
- RETURN(result);
+ EXIT;
+out:
+ target_send_reply(req, result, fail);
+ return 0;
}
-int fld_server_init(const struct lu_context *ctx, struct lu_fld *fld,
- struct dt_device *dt)
+int
+fld_server_init(const struct lu_context *ctx,
+ struct lu_fld *fld,
+ struct dt_device *dt)
{
int result;
struct ptlrpc_service_conf fld_conf = {
}
EXPORT_SYMBOL(fld_server_init);
-void fld_server_fini(const struct lu_context *ctx, struct lu_fld *fld)
+void
+fld_server_fini(const struct lu_context *ctx,
+ struct lu_fld *fld)
{
struct list_head *pos, *n;
}
EXPORT_SYMBOL(fld_server_fini);
-static int fld_handle(const struct lu_context *ctx,
- struct lu_fld *fld, __u32 opts, struct md_fld *mf)
+static int
+fld_handle(const struct lu_context *ctx,
+ struct lu_fld *fld, __u32 opts, struct md_fld *mf)
{
int rc;
ENTRY;
MODULE_DESCRIPTION("Lustre fld Prototype");
MODULE_LICENSE("GPL");
-cfs_module(mdd, "0.0.2", fld_mod_init, fld_mod_exit);
+cfs_module(mdd, "0.0.3", fld_mod_init, fld_mod_exit);
+#endif