From 83c85b373e646b8e7ea87925a007355db75446e7 Mon Sep 17 00:00:00 2001 From: lincent Date: Wed, 26 Oct 2005 18:58:28 +0000 Subject: [PATCH] Mgs hold on the mgs_open_llog as resources on llog, and each resource will be locked by ldlm_llog. Each different version llog for one filesystem/pool will have same mgs_open_llog, and different version_desc(or llog patch), which descripe llog cmds the client/mds should run to keep up with current llog version. Also, mgs_open_llog will contain current updated llog , and the llog patch just contain the specail llog_hdr_bitmap , which set valid bits to the llog cmds need to run for the client hold the old llog version. --- lustre/include/linux/lustre_idl.h | 10 +- lustre/include/linux/lustre_log.h | 2 + lustre/include/linux/lustre_net.h | 9 + lustre/include/linux/obd.h | 3 +- lustre/mgc/mgc_request.c | 1 - lustre/mgs/Makefile.in | 2 +- lustre/mgs/autoMakefile.am | 2 +- lustre/mgs/mgs_handler.c | 18 +- lustre/mgs/mgs_llog.c | 1135 +++++++++++++++++++++++++++++++++---- lustre/obdclass/llog_lvfs.c | 22 +- 10 files changed, 1055 insertions(+), 149 deletions(-) diff --git a/lustre/include/linux/lustre_idl.h b/lustre/include/linux/lustre_idl.h index 630cd85..4f6717c 100644 --- a/lustre/include/linux/lustre_idl.h +++ b/lustre/include/linux/lustre_idl.h @@ -96,10 +96,10 @@ #define MGMT_REPLY_PORTAL 25 #define MGMT_CLI_REQUEST_PORTAL 26 #define MGMT_CLI_REPLY_PORTAL 27 -//#define MGC_REQUEST_PORTAL 28 +#define MGC_REQUEST_PORTAL 28 #define MGC_REPLY_PORTAL 29 #define MGS_REQUEST_PORTAL 30 -//#define MGS_REPLY_PORTAL 31 +#define MGS_REPLY_PORTAL 31 #define SVC_KILLED 1 @@ -1086,7 +1086,6 @@ struct llog_gen_rec { struct llog_log_hdr { struct llog_rec_hdr llh_hdr; - __u64 llh_version; __u64 llh_timestamp; __u32 llh_count; __u32 llh_bitmap_offset; @@ -1095,7 +1094,8 @@ struct llog_log_hdr { __u32 llh_cat_idx; /* for a catalog the first plain slot is next to it */ struct obd_uuid llh_tgtuuid; - __u32 llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32) - 23]; + __u64 llh_version; + __u32 llh_reserved[LLOG_HEADER_SIZE/sizeof(__u32) - 21]; __u32 llh_bitmap[LLOG_BITMAP_BYTES/sizeof(__u32)]; struct llog_rec_tail llh_tail; } __attribute__((packed)); @@ -1125,13 +1125,13 @@ enum llogd_rpc_ops { struct llogd_body { struct llog_logid lgd_logid; - __u64 lgd_local_version; __u32 lgd_ctxt_idx; __u32 lgd_llh_flags; __u32 lgd_index; __u32 lgd_saved_index; __u32 lgd_len; __u64 lgd_cur_offset; + __u64 lgd_local_version; } __attribute__((packed)); struct llogd_conn_body { diff --git a/lustre/include/linux/lustre_log.h b/lustre/include/linux/lustre_log.h index 02f1e00..a9fe1a2 100644 --- a/lustre/include/linux/lustre_log.h +++ b/lustre/include/linux/lustre_log.h @@ -189,6 +189,8 @@ struct llog_operations { /* llog_lvfs.c */ extern struct llog_operations llog_lvfs_ops; +extern struct llog_operations mgs_llog_lvfs_ops; + int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd, char *name, int count, struct llog_catid *idarray); diff --git a/lustre/include/linux/lustre_net.h b/lustre/include/linux/lustre_net.h index 95567a8..e7602e6 100644 --- a/lustre/include/linux/lustre_net.h +++ b/lustre/include/linux/lustre_net.h @@ -111,6 +111,15 @@ #define MDS_MAXREQSIZE (5 * 1024) #define MDS_MAXREPSIZE (9 * 1024) +#define MGT_MAX_THREADS 32UL +#define MGT_NUM_THREADS max(min_t(unsigned long, num_physpages / 8192, \ + MGT_MAX_THREADS), 2UL) +#define MGS_NBUFS (64 * smp_num_cpus) +#define MGS_BUFSIZE (8 * 1024) + +#define MGS_MAXREQSIZE (5 * 1024) +#define MGS_MAXREPSIZE (9 * 1024) + #define OST_MAX_THREADS 36UL #define OST_NUM_THREADS max(min_t(unsigned long, num_physpages / 8192, \ OST_MAX_THREADS), 2UL) diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h index b690d5c..d37ff36 100644 --- a/lustre/include/linux/obd.h +++ b/lustre/include/linux/obd.h @@ -337,6 +337,7 @@ struct mgs_obd { struct vfsmount *mgs_vfsmnt; struct super_block *mgs_sb; struct dentry *mgs_configs_dir; + struct list_head mgs_open_llogs; }; struct mds_obd { @@ -360,7 +361,7 @@ struct mds_obd { struct dentry *mds_logs_dir; struct dentry *mds_objects_dir; struct llog_handle *mds_cfg_llh; -// struct llog_handle *mds_catalog; + struct llog_handle *mds_catalog; struct obd_device *mds_osc_obd; /* XXX lov_obd */ struct obd_uuid mds_lov_uuid; char *mds_profile; diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index a58c217..859f6e5 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -25,7 +25,6 @@ * requests are coming * in over the wire, so object target modules * do not have a full * method table.) */ - #ifndef EXPORT_SYMTAB # define EXPORT_SYMTAB #endif diff --git a/lustre/mgs/Makefile.in b/lustre/mgs/Makefile.in index 5424c07..f340f73 100644 --- a/lustre/mgs/Makefile.in +++ b/lustre/mgs/Makefile.in @@ -1,4 +1,4 @@ MODULES := mgs -mgs-objs := mgs_handler.o mgs_fs.o +mgs-objs := mgs_handler.o mgs_fs.o mgs_llog.o @INCLUDE_RULES@ diff --git a/lustre/mgs/autoMakefile.am b/lustre/mgs/autoMakefile.am index 8a80652..53734b0 100644 --- a/lustre/mgs/autoMakefile.am +++ b/lustre/mgs/autoMakefile.am @@ -8,4 +8,4 @@ modulefs_DATA = mgs$(KMODEXT) endif MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ -DIST_SOURCES := $(mgs-objs:%.o=%.c) +DIST_SOURCES := $(mgs-objs:%.o=%.c) mgs_internal.h diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 8b1d4e4..3242334 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -154,6 +154,7 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf) struct lprocfs_static_vars lvars; struct lustre_cfg* lcfg = buf; char *options = NULL; + char *ns_name = "MGS"; struct mgs_obd *mgs = &obd->u.mgs; struct vfsmount *mnt; unsigned long page; @@ -196,7 +197,6 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf) CDEBUG(D_SUPER, "%s: mnt = %p\n", lustre_cfg_string(lcfg, 1), mnt); /*namespace for mgs llog */ - sprintf(ns_name, "mgs-%s", obd->obd_uuid.uuid); obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER); if (obd->obd_namespace == NULL) { mgs_cleanup(obd); @@ -213,7 +213,7 @@ static int mgs_setup(struct obd_device *obd, obd_count len, void *buf) } INIT_LIST_HEAD(&mgs->mgs_open_llogs); - INIT_LIST_HEAD(&mgs->mgs_update_llhs); + // INIT_LIST_HEAD(&mgs->mgs_update_llhs); rc = llog_start_commit_thread(); if (rc < 0) @@ -275,7 +275,7 @@ static int mgs_postsetup(struct obd_device *obd) ENTRY; rc = llog_setup(obd, LLOG_CONFIG_ORIG_CTXT, obd, 0, NULL, - &llog_lvfs_ops); + &mgs_llog_lvfs_ops); RETURN(rc); } @@ -509,9 +509,10 @@ static int mgt_setup(struct obd_device *obd, obd_count len, void *buf) mgs->mgs_service = ptlrpc_init_svc(MGS_NBUFS, MGS_BUFSIZE, MGS_MAXREQSIZE, - MGS_REQUEST_PORTAL, MGC_REPLY_PORTAL, - MGS_SERVICE_WATCHDOG_TIMEOUT, - mgs_handle, "mgs", obd->obd_proc_entry, NULL); + MGS_MAXREPSIZE, MGS_REQUEST_PORTAL, + MGC_REPLY_PORTAL, MGS_SERVICE_WATCHDOG_TIMEOUT, + mgs_handle, "mgs", obd->obd_proc_entry, NULL, + MGT_NUM_THREADS); if (!mgs->mgs_service) { CERROR("failed to start service\n"); @@ -532,6 +533,7 @@ err_lprocfs: return rc; } + static int mgt_cleanup(struct obd_device *obd) { struct mgs_obd *mgs = &obd->u.mgs; @@ -545,8 +547,8 @@ static int mgt_cleanup(struct obd_device *obd) } struct lvfs_callback_ops mgs_lvfs_ops = { - l_fid2dentry: mgs_lvfs_fid2dentry, - l_open_llog: mgs_lvfs_open_llog, + // l_fid2dentry: mgs_lvfs_fid2dentry, + // l_open_llog: mgs_lvfs_open_llog, }; /* use obd ops to offer management infrastructure */ diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 7078be5..bc1deee 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -29,101 +29,191 @@ #define DEBUG_SUBSYSTEM S_MGS #ifdef __KERNEL__ -# include -# include +#include +#include +#include #endif +#include #include -#include +#include +#include +#include +#include #include +#include +#include +#include "llog_internal.h" #include "mgs_internal.h" -static struct mgs_update_llh* mgs_get_update_handle(struct obd_device *obd, - char *fsname, char *name) +static struct lustre_cfg_bufs llog_bufs; + +static int record_attach(struct obd_device *obd, struct llog_handle *llh, + char* name, char *type, char *uuid) { - struct mgs_obd *mgs = &obd->u.mgs; - struct mgs_update_llh *mul, *l; - struct list_head *update_llh_list = &mgs->mgs_update_llhs; + struct lustre_cfg *lcfg; + int rc; - list_for_each_entry_safe(mul, l, update_llh_list, mul_list) { - if (!strcmp(mul->mul_name, name) && - !strcmp(mul->mul_fsname, fsname)) - return mul; - } - return NULL; + lustre_cfg_bufs_reset(&llog_bufs, NULL); + + lustre_cfg_bufs_set_string(&llog_bufs, 0, name); + lustre_cfg_bufs_set_string(&llog_bufs, 1, type); + if (uuid) + lustre_cfg_bufs_set_string(&llog_bufs, 2, uuid); + + lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); + + rc = mgs_do_record(obd, llh, lcfg, 0); + + lustre_cfg_free(lcfg); + return rc; } -static int mgs_new_update_handle(struct obd_device *obd, - struct mgs_update_llh *mul, - char *fsname, char *name) +static int record_add_uuid(struct obd_device *obd, struct llog_handl *llh, + uint64_t nid, char *uuid) { - struct mgs_obd *mgs = &obd->u.mgs; - struct list_head *update_llh_list = &mgs->mgs_update_llhs; - int rc = 0; + struct lustre_cfg *lcfg; + int rc; - if(mgs_get_update_handle(obd, fsname, name)) - GOTO(out, rc = -EBUSY); + lustre_cfg_bufs_reset(&llog_bufs, NULL); + if (uuid) + lustre_cfg_bufs_set_string(&llog_bufs, 1, uuid); - OBD_ALLOC(mul, sizeof(*mul)); - if (!mul) { - CERROR("Can not allocate memory for update_llh.\n"); - GOTO(out, rc = -ENOMEM); - } - strncpy(mul->mul_name, name, sizeof mul->mul_name); - strncpy(mul->mul_fsname, fsname, sizeof mul->mul_fsname); + lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs); + lcfg->lcfg_nid = nid; - spin_lock(&mgs->mgs_llh_lock); - /*seach again, in case of race.*/ - if (mgs_get_update_handle(obd, fsname, name)) - spin_unlock(&mgs->mgs_llh_lock); - GOTO(out_free, rc = -EBUSY); - } - list_add(&mul->mul_list, &mgs->mgs_update_llhs); - spin_unlock(&mgs->mgs_llh_lock); + rc = mgs_do_record(obd, llh, lcfg, 0); -out: + lustre_cfg_free(lcfg); return rc; - -out_free: - OBD_FREE(mul, sizeof(*mul)); - goto out; } -static void mgs_free_update_handle(struct obd_device *obd, - struct mgs_update_llh *mul) +static int record_lov_setup(struct obd_device *obd, struct llog_handle *llh, + char *device_name, struct *lov_desc) { - struct mgs_obd *mgs = &obd->u.mgs; + struct lustre_cfg *lcfg; + int rc; + + lustre_cfg_bufs_reset(&llog_bufs, device_name); + + lustre_cfg_bufs_set(&llog_bufs, 1, desc, sizeof(*desc)); + + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + + rc = mgs_do_record(obd, llh, lcfg, 0); + + lustre_cfg_free(lcfg); + return rc; + +} +static int record_setup(struct obd_device *obd, struct llog_handle *llh, + char *device_name, int args, char**argv) +{ + struct lustre_cfg *lcfg; + int rc; + + lustre_cfg_bufs_reset(&llog_bufs, device_name); + + for(i = 1; i < args ; i++) + lustre_cfg_bufs_set_string(&llog_bufs, i, argv[i-1]); - spin_lock(&mgs->mgs_llh_lock); - list_del(&mul->mul_list); - spin_unlock(&mgs->mgs_llh_lock); - - return; + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + + rc = mgs_do_record(obd, llh, lcfg, 0); + + lustre_cfg_free(lcfg); + return rc; +} + +static int record_lov_modify_tgts(struct obd_device *obd, + struct llog_handle *llh, + char *device_name, char *op, char *uuid, + char *index, char *gen) +{ + struct lustre_cfg *lcfg; + int cmd, rc; + + lustre_cfg_bufs_reset(&llog_bufs, device_name); + + if (!strncmp(op, "add", 4)) { + cmd = LCFG_LOV_ADD_OBD; + } else if (!strncmp(op, "del", 4)) { + cmd = LCFG_LOV_DEL_OBD; + } + + lustre_cfg_bufs_set_string(&llog_bufs, 1, uuid); + lustre_cfg_bufs_set_string(&llog_bufs, 2, index); + lustre_cfg_bufs_set_string(&llog_bufs, 3, gen); + + lcfg = lustre_cfg_new(cmd, &bufs); + + rc = mgs_do_record(obd, llh, lcfg, 0); + + lustre_cfg_free(lcfg); + return rc; +} + +static int record_mount_point(struct obd_device *obd, struct llog_handle *llh, + char *mds_name, char *lov_name, char *mdc_name) +{ + struct lustre_cfg *lcfg; + int cmd, rc; + + lustre_cfg_bufs_reset(&llog_bufs, NULL); + + lustre_cfg_bufs_set_string(&llog_bufs, 1, mds_name); + lustre_cfg_bufs_set_string(&llog_bufs, 2, lov_name); + if (mdc_name) + lustre_cfg_bufs_set_string(&llog_bufs, 2, mdc_name); + + lcfg = lustre_cfg_new(cmd, &bufs); + + rc = mgs_do_record(obd, llh, lcfg, 0); + + lustre_cfg_free(lcfg); + return rc; +} + +struct mgs_open_llog* mgs_find_open_llog(struct obd_device *obd, char *name) +{ + struct list_head *tmp; + struct mgc_open_llog *mol; + char fsname[40]; + char *p; + + p = strrchr(name, '/') + if (p != NULL) + strncpy(fsname, name, p - name); + else + return NULL; + + list_for_each(tmp, &mgc->mgc_open_llogs) { + mol = list_entry(tmp, struct mgc_open_llog, mol_list); + if !strcmp(mol->name, fsname) + return mol; + } + return NULL; } static int mgs_start_record(struct obd_device *obd, - struct obd_ioctl_data *data) + struct llog_handle *llh, char *name) { static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" }; - struct mgs_obd *mgs = &obd->u.mgs; struct lvfs_run_ctxt saved; - struct mgs_update_llh *mul; struct llog_handle **llh_res; - char *name = data->ioc_inlbuf1; - char *fsname = data->ioc_inlbuf2; int rc = 0; + + if (llh) + RETURN(-EBUSY); - rc = mgs_new_update_handle(obd, mul, fsname, name); - if (rc) - RETURN(rc); + llh_res = &llh; - llh_res = &mul->mul_llh; push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT), - llh_res, NULL, fsname, name); + llh_res, NULL, name); if (rc == 0) - llog_init_handle(mul->mul_llh, LLOG_F_IS_PLAIN, &cfg_uuid); + llog_init_handle(llh, LLOG_F_IS_PLAIN, &cfg_uuid); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); @@ -136,75 +226,54 @@ static int mgs_end_record(struct obd_device *obd, static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" }; struct mgs_obd *mgs = &obd->u.mgs; struct lvfs_run_ctxt saved; - struct mgs_update_llh *mul; + struct mgs_open_llog *mol; char *name = data->ioc_inlbuf1; - char *fsname = data->ioc_inlbuf2; int rc = 0; - mul = mgs_get_update_handle(obd, fsname, name); - if (!mul) { - CERROR("Can not get update handle for %s:%s \n", - fsname, name); - return -EINVAL; - } + mol = mgs_find_open_llog(obd, name); + if (!mol) + RETURN(-EINVAL); push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - rc = llog_close(mul->mul_llh); + rc = llog_close(mol->mol_cfg_llh); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); RETURN(rc); } static int mgs_clear_record(struct obd_device *obd, - struct obd_ioctl_data *data) + struct llog_handle *llh, char *name) { static struct obd_uuid cfg_uuid = { .uuid = "config_uuid" }; struct mgs_obd *mgs = &obd->u.mgs; struct lvfs_run_ctxt saved; - struct mgs_update_llh *mul; struct llog_handel **llh_res; - char *name = data->ioc_inlbuf1; - char *fsname = data->ioc_inlbuf2; int rc = 0; - rc = mgs_new_update_handle(obd, mul, fsname, name); - if (rc) - RETURN(rc); + if (llh) + RETURN(-EBUSY); + llh_res = &llh; - llh_res = &mul->mul_llh; push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); rc = llog_create(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT), llh_res, NULL, name); if (rc == 0) { - llog_init_handle(mul->mul_llh, LLOG_F_IS_PLAIN, NULL); - rc = llog_destroy(mul->mul_llh); - llog_free_handle(mul->mul_llh); + llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL); + rc = llog_destroy(llh); + llog_free_handle(llh); } pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - mgs_free_update_handle(obd, mul); - RETURN(rc); } -static int mgs_do_record(struct obd_device *obd, - struct obd_ioctl_data *data, - int from_user) +static int mgs_do_record(struct obd_device *obd, struct llog_handle *llh, + struct obd_ioctl_data *data, int from_user) { - struct mgs_obd *mgs = &obd->u.mgs; - struct mgs_update_llh *mul; char *name = data->ioc_inlbuf1; - char *fsname = data->ioc_inlbuf2; char *cfg_buf; struct llog_rec_hdr rec; int rc = 0; - - mul = mgs_get_update_handle(obd, fsname, name); - if (!mul) { - CERROR("Can not get update handle for %s:%s \n", - fsname, name); - return -EINVAL; - } rec.lrh_len = llog_data_len(data->ioc_plen1); @@ -228,44 +297,140 @@ static int mgs_do_record(struct obd_device *obd, cfg_buf = data->ioc_bulk; push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - rc = llog_write_rec(mul->mul_llh, &rec, NULL, 0, cfg_buf, -1); + rc = llog_write_rec(llh, &rec, NULL, 0, cfg_buf, -1); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); OBD_FREE(cfg_buf, data->ioc_plen1); RETURN(rc); } -int mgs_update_llog(struct obd_device *obd, - struct obd_ioctl_data *data) +static int mgs_write_mds_llog(struct obd_device *obd, char* logname) +{ + struct mgs_open_llog *mol; + struct llog_handle *llh; + struct system_db *db; + struct ost_info *oinfo; + int i, rc = 0; + + mol = find_mgs_open_llog(obd, name); + if (!mol) + RETURN(-EINVAL); + + db = mol->mol_db; + if(!db) + RETURN(-EINVAL); + + llh = mol->mol_llh; + rc = mgs_clear_record(obd, llh, name); + if (rc) { + CERROR("failed to clear log %s: %d\n", name, rc); + RETURN(rc); + } + + rc = mgs_start_record(obd, llh, name); + if (rc) { + CERROR("failed to record log %s: %d\n", name, rc); + RETURN(rc); + } + + rc = record_attach(obd, llh, db->mds_name, "lov", db->mds_uuid); + if (rc) { + CERROR("failed to record log(attach lov) %s: %d\n", name, rc); + RETURN(rc); + } + + rc = record_lov_setup(obd, llh, db->mds_name, &db->lov_desc); + if (rc) { + CERROR("failed to record log(setup) %s: %d\n", name, rc); + RETURN(rc); + } + + rc = record_add_uuid(obd, llh, db->mds_nid, db->mds_uuid); + if (rc) { + CERROR("failed to record log(add uuid) %s: %d\n", name, rc); + RETURN(rc); + } + + i = 0; + list_for_each(oinfo, &db->ost_infos) { + char ostuuid[64]; + char nodeuuid[64]; + sprintf(ostuuid, "%s_UUID", oinfo->osi_ostname); + sprintf(nodeuuid, "%s_UUID", oinfo->osi_nodename); + + rc = record_add_uuid(obd, llh, oinfo->osi_nid, nodeuuid); + if (rc) { + CERROR("failed to record log(add_uuid) %s: %d\n", + logname, rc); + RETURN(rc); + } + + rc = record_attach(obd, llh, oinfo->osi_ostname, + "osc", db->mds_uuid); + if (rc) { + CERROR("failed to record log(attach_uuid) %s: %d\n", + logname, rc); + RETURN(rc); + } + + sprintf(devname,"OSC_%s_%s_%s", + db->mgs_nodename, oinfo->osi_ostname, db->mds_name); + + rc = record_setup(obd, llh, devname, 2, ostuuid, nodeuuid); + if (rc) { + CERROR("failed to record log(setup) %s: %d\n", + name, rc); + RETURN(rc); + } + + rc = record_lov_modify_tgts(obd, llh, db->mds_name, "add", ostuuid, + atoi(oinfo->osi_stripe_index), "1"); + if (rc) { + CERROR("failed to record log(lov_modify_tgts) %s: %d\n", + name, rc); + RETURN(rc); + } + } + + rc = record_mount_point(obd, llh, db->mgs_name, db->lov_name); + if (rc) { + CERROR("failed to record log(lov_modify_tgts) %s: %d\n", + name, rc); + RETURN(rc); + } + + RETURN(rc); +} + +int mgs_update_llog(struct obd_device *obd, char *name) { - struct mgs_obd *mgs = &obd->u.mgs; - struct mgs_update_llh *mul; - char *name = data->ioc_inlbuf1; - char *fsname = data->ioc_inlbuf2; - int rc; + char logname[64]; + int rc = 0; + + /* Two phases: 1. writing mds log. + 2. writing client log + */ /*First phase: writing mds log */ - logname = name; - data->ioc_inlbuf1 = logname; - data->ioc_inllen1 = strlen(data->ioc_inlbuf1) + 1; - data->ioc_inlbuf2 = fsname; - data->ioc_inllen2 = strlen(data->ioc_inlbuf2) + 1; - - rc = mgs_clear_record(obd, data); + sprintf(logname, "%s/mds1", name); + rc = mgs_write_mds_llog(obd, logname); if (rc) { - CERROR("failed to clear log %s: %d\n", logname, rc); + CERROR("failed to write log %s: %d\n", logname, rc); RETURN(rc); } - rc = mgs_start_record(obd, data); + /*Second phase: writing client log */ + sprintf(logname, "%s/client", name); + rc = mgs_write_client_llog(obd, logname); if (rc) { - CERROR("failed to record log %s: %d\n", logname, rc); + CERROR("failed to write log %s: %d\n", logname, rc); RETURN(rc); } - sprintf(lovuuid, "lov_%s_%s", fsname, name); - + + return rc; } + int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg) { @@ -388,3 +553,741 @@ int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, } RETURN(0); } + + +#ifdef __KERNEL__ + +static int mgs_llog_lvfs_pad(struct obd_device *obd, struct l_file *file, + int len, int index) +{ + struct llog_rec_hdr rec = { 0 }; + struct llog_rec_tail tail; + int rc; + ENTRY; + + LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0x7) == 0); + + tail.lrt_len = rec.lrh_len = len; + tail.lrt_index = rec.lrh_index = index; + rec.lrh_type = LLOG_PAD_MAGIC; + + rc = fsfilt_write_record(obd, file, &rec, sizeof(rec), &file->f_pos, 0); + if (rc) { + CERROR("error writing padding record: rc %d\n", rc); + goto out; + } + + file->f_pos += len - sizeof(rec) - sizeof(tail); + rc = fsfilt_write_record(obd, file, &tail, sizeof(tail),&file->f_pos,0); + if (rc) { + CERROR("error writing padding record: rc %d\n", rc); + goto out; + } + + out: + RETURN(rc); +} + +static int mgs_llog_lvfs_write_blob(struct obd_device *obd, struct l_file *file, + struct llog_rec_hdr *rec, void *buf, loff_t off) +{ + int rc; + struct llog_rec_tail end; + loff_t saved_off = file->f_pos; + int buflen = rec->lrh_len; + + ENTRY; + file->f_pos = off; + + if (!buf) { + rc = fsfilt_write_record(obd, file, rec, buflen,&file->f_pos,0); + if (rc) { + CERROR("error writing log record: rc %d\n", rc); + goto out; + } + GOTO(out, rc = 0); + } + + /* the buf case */ + rec->lrh_len = sizeof(*rec) + buflen + sizeof(end); + rc = fsfilt_write_record(obd, file, rec, sizeof(*rec), &file->f_pos, 0); + if (rc) { + CERROR("error writing log hdr: rc %d\n", rc); + goto out; + } + + rc = fsfilt_write_record(obd, file, buf, buflen, &file->f_pos, 0); + if (rc) { + CERROR("error writing log buffer: rc %d\n", rc); + goto out; + } + + end.lrt_len = rec->lrh_len; + end.lrt_index = rec->lrh_index; + rc = fsfilt_write_record(obd, file, &end, sizeof(end), &file->f_pos, 0); + if (rc) { + CERROR("error writing log tail: rc %d\n", rc); + goto out; + } + + rc = 0; + out: + if (saved_off > file->f_pos) + file->f_pos = saved_off; + LASSERT(rc <= 0); + RETURN(rc); +} + +static int mgs_llog_lvfs_read_blob(struct obd_device *obd, struct l_file *file, + void *buf, int size, loff_t off) +{ + loff_t offset = off; + int rc; + ENTRY; + + rc = fsfilt_read_record(obd, file, buf, size, &offset); + if (rc) { + CERROR("error reading log record: rc %d\n", rc); + RETURN(rc); + } + RETURN(0); +} + +static int mgs_llog_lvfs_read_header(struct llog_handle *handle) +{ + struct obd_device *obd; + int rc; + ENTRY; + + LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE); + + obd = handle->lgh_ctxt->loc_exp->exp_obd; + + if (handle->lgh_file->f_dentry->d_inode->i_size == 0) { + CDEBUG(D_HA, "not reading header from 0-byte log\n"); + RETURN(LLOG_EEMPTY); + } + + rc = mgs_llog_lvfs_read_blob(obd, handle->lgh_file, handle->lgh_hdr, + LLOG_CHUNK_SIZE, 0); + if (rc) { + CERROR("error reading log header from %.*s\n", + handle->lgh_file->f_dentry->d_name.len, + handle->lgh_file->f_dentry->d_name.name); + } else { + struct llog_rec_hdr *llh_hdr = &handle->lgh_hdr->llh_hdr; + + if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr)) + lustre_swab_llog_hdr(handle->lgh_hdr); + + if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) { + CERROR("bad log %.*s header magic: %#x (expected %#x)\n", + handle->lgh_file->f_dentry->d_name.len, + handle->lgh_file->f_dentry->d_name.name, + llh_hdr->lrh_type, LLOG_HDR_MAGIC); + rc = -EIO; + } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) { + CERROR("incorrectly sized log %.*s header: %#x " + "(expected %#x)\n", + handle->lgh_file->f_dentry->d_name.len, + handle->lgh_file->f_dentry->d_name.name, + llh_hdr->lrh_len, LLOG_CHUNK_SIZE); + CERROR("you may need to re-run lconf --write_conf.\n"); + rc = -EIO; + } + } + + handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index; + handle->lgh_file->f_pos = handle->lgh_file->f_dentry->d_inode->i_size; + + RETURN(rc); +} + +/* returns negative in on error; 0 if success && reccookie == 0; 1 otherwise */ +/* appends if idx == -1, otherwise overwrites record idx. */ +static int mgs_llog_lvfs_write_rec(struct llog_handle *loghandle, + struct llog_rec_hdr *rec, + struct llog_cookie *reccookie, int cookiecount, + void *buf, int idx) +{ + struct llog_log_hdr *llh; + int reclen = rec->lrh_len, index, rc; + struct llog_rec_tail *lrt; + struct obd_device *obd; + struct file *file; + size_t left; + ENTRY; + + llh = loghandle->lgh_hdr; + file = loghandle->lgh_file; + obd = loghandle->lgh_ctxt->loc_exp->exp_obd; + + /* record length should not bigger than LLOG_CHUNK_SIZE */ + if (buf) + rc = (reclen > LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) - + sizeof(struct llog_rec_tail)) ? -E2BIG : 0; + else + rc = (reclen > LLOG_CHUNK_SIZE) ? -E2BIG : 0; + if (rc) + RETURN(rc); + + if (idx != -1) { + loff_t saved_offset; + + /* no header: only allowed to insert record 1 */ + if (idx != 1 && !file->f_dentry->d_inode->i_size) { + CERROR("idx != -1 in empty log\n"); + LBUG(); + } + + if (idx && llh->llh_size && llh->llh_size != reclen) + RETURN(-EINVAL); + + rc = mgs_llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0); + /* we are done if we only write the header or on error */ + if (rc || idx == 0) + RETURN(rc); + + saved_offset = sizeof(*llh) + (idx-1)*rec->lrh_len; + rc = mgs_llog_lvfs_write_blob(obd, file, rec, buf, saved_offset); + if (rc == 0 && reccookie) { + reccookie->lgc_lgl = loghandle->lgh_id; + reccookie->lgc_index = idx; + rc = 1; + } + RETURN(rc); + } + + /* Make sure that records don't cross a chunk boundary, so we can + * process them page-at-a-time if needed. If it will cross a chunk + * boundary, write in a fake (but referenced) entry to pad the chunk. + * + * We know that llog_current_log() will return a loghandle that is + * big enough to hold reclen, so all we care about is padding here. + */ + left = LLOG_CHUNK_SIZE - (file->f_pos & (LLOG_CHUNK_SIZE - 1)); + if (buf) + reclen = sizeof(*rec) + rec->lrh_len + + sizeof(struct llog_rec_tail); + + /* NOTE: padding is a record, but no bit is set */ + if (left != 0 && left != reclen && + left < (reclen + LLOG_MIN_REC_SIZE)) { + loghandle->lgh_last_idx++; + rc = mgs_llog_lvfs_pad(obd, file, left, loghandle->lgh_last_idx); + if (rc) + RETURN(rc); + /* if it's the last idx in log file, then return -ENOSPC */ + if (loghandle->lgh_last_idx == LLOG_BITMAP_SIZE(llh) - 1) + RETURN(-ENOSPC); + } + + loghandle->lgh_last_idx++; + index = loghandle->lgh_last_idx; + LASSERT(index < LLOG_BITMAP_SIZE(llh)); + rec->lrh_index = index; + if (buf == NULL) { + lrt = (struct llog_rec_tail *) + ((char *)rec + rec->lrh_len - sizeof(*lrt)); + lrt->lrt_len = rec->lrh_len; + lrt->lrt_index = rec->lrh_index; + } + if (ext2_set_bit(index, llh->llh_bitmap)) { + CERROR("argh, index %u already set in log bitmap?\n", index); + LBUG(); /* should never happen */ + } + llh->llh_count++; + llh->llh_tail.lrt_index = index; + + rc = mgs_llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0); + if (rc) + RETURN(rc); + + rc = mgs_llog_lvfs_write_blob(obd, file, rec, buf, file->f_pos); + if (rc) + RETURN(rc); + + CDEBUG(D_HA, "added record "LPX64": idx: %u, %u bytes\n", + loghandle->lgh_id.lgl_oid, index, rec->lrh_len); + if (rc == 0 && reccookie) { + reccookie->lgc_lgl = loghandle->lgh_id; + reccookie->lgc_index = index; + if ((rec->lrh_type == MDS_UNLINK_REC) || + (rec->lrh_type == MDS_SETATTR_REC)) + reccookie->lgc_subsys = LLOG_MDS_OST_ORIG_CTXT; + else if (rec->lrh_type == OST_SZ_REC) + reccookie->lgc_subsys = LLOG_SIZE_ORIG_CTXT; + else if (rec->lrh_type == OST_RAID1_REC) + reccookie->lgc_subsys = LLOG_RD1_ORIG_CTXT; + else + reccookie->lgc_subsys = -1; + rc = 1; + } + if (rc == 0 && rec->lrh_type == LLOG_GEN_REC) + rc = 1; + + RETURN(rc); +} + +/* We can skip reading at least as many log blocks as the number of +* minimum sized log records we are skipping. If it turns out +* that we are not far enough along the log (because the +* actual records are larger than minimum size) we just skip +* some more records. */ + +static void llog_skip_over(__u64 *off, int curr, int goal) +{ + if (goal <= curr) + return; + *off = (*off + (goal-curr-1) * LLOG_MIN_REC_SIZE) & + ~(LLOG_CHUNK_SIZE - 1); +} + + +/* sets: + * - cur_offset to the furthest point read in the log file + * - cur_idx to the log index preceeding cur_offset + * returns -EIO/-EINVAL on error + */ +static int mgs_llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx, + int next_idx, __u64 *cur_offset, void *buf, + int len) +{ + int rc; + ENTRY; + + if (len == 0 || len & (LLOG_CHUNK_SIZE - 1)) + RETURN(-EINVAL); + + CDEBUG(D_OTHER, "looking for log index %u (cur idx %u off "LPU64")\n", + next_idx, *cur_idx, *cur_offset); + + while (*cur_offset < loghandle->lgh_file->f_dentry->d_inode->i_size) { + struct llog_rec_hdr *rec; + struct llog_rec_tail *tail; + loff_t ppos; + + llog_skip_over(cur_offset, *cur_idx, next_idx); + + ppos = *cur_offset; + rc = fsfilt_read_record(loghandle->lgh_ctxt->loc_exp->exp_obd, + loghandle->lgh_file, buf, len, + &ppos); + + if (rc) { + CERROR("Cant read llog block at log id "LPU64 + "/%u offset "LPU64"\n", + loghandle->lgh_id.lgl_oid, + loghandle->lgh_id.lgl_ogen, + *cur_offset); + RETURN(rc); + } + + /* put number of bytes read into rc to make code simpler */ + rc = ppos - *cur_offset; + *cur_offset = ppos; + + if (rc == 0) /* end of file, nothing to do */ + RETURN(0); + + if (rc < sizeof(*tail)) { + CERROR("Invalid llog block at log id "LPU64"/%u offset " + LPU64"\n", loghandle->lgh_id.lgl_oid, + loghandle->lgh_id.lgl_ogen, *cur_offset); + RETURN(-EINVAL); + } + + rec = buf; + tail = (struct llog_rec_tail *)((char *)buf + rc - + sizeof(struct llog_rec_tail)); + + if (LLOG_REC_HDR_NEEDS_SWABBING(rec)) { + lustre_swab_llog_rec(rec, tail); + } + + *cur_idx = tail->lrt_index; + + /* this shouldn't happen */ + if (tail->lrt_index == 0) { + CERROR("Invalid llog tail at log id "LPU64"/%u offset " + LPU64"\n", loghandle->lgh_id.lgl_oid, + loghandle->lgh_id.lgl_ogen, *cur_offset); + RETURN(-EINVAL); + } + if (tail->lrt_index < next_idx) + continue; + + /* sanity check that the start of the new buffer is no farther + * than the record that we wanted. This shouldn't happen. */ + if (rec->lrh_index > next_idx) { + CERROR("missed desired record? %u > %u\n", + rec->lrh_index, next_idx); + RETURN(-ENOENT); + } + RETURN(0); + } + RETURN(-EIO); +} + +static struct file *llog_filp_open(char *name, int flags, int mode) +{ + char *logname; + struct file *filp; + int len; + + OBD_ALLOC(logname, PATH_MAX); + if (logname == NULL) + return ERR_PTR(-ENOMEM); + + len = snprintf(logname, PATH_MAX, "%s/%s", + MOUNT_CONFIGS_DIR, name); + + if (len >= PATH_MAX - 1) { + filp = ERR_PTR(-ENAMETOOLONG); + } else { + CERROR("logname = %s\n", logname); + filp = l_filp_open(logname, flags, mode); + if (IS_ERR(filp)) + CERROR("logfile creation %s: %ld\n", logname, + PTR_ERR(filp)); + } + + OBD_FREE(logname, PATH_MAX); + return filp; +} + +/* This is a callback from the llog_* functions. + * Assumes caller has already pushed us into the kernel context. */ +static int mgs_llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, + struct llog_logid *logid, char *name) +{ + struct llog_handle *handle; + struct obd_device *obd; + struct l_dentry *dchild = NULL; + struct obdo *oa = NULL; + int rc = 0, cleanup_phase = 1; + int open_flags = O_RDWR | O_CREAT | O_LARGEFILE; + ENTRY; + + handle = llog_alloc_handle(); + if (handle == NULL) + RETURN(-ENOMEM); + *res = handle; + + LASSERT(ctxt); + LASSERT(ctxt->loc_exp); + obd = ctxt->loc_exp->exp_obd; + + if (logid != NULL) { + dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, logid->lgl_oid, + logid->lgl_ogen, logid->lgl_ogr); + + if (IS_ERR(dchild)) { + rc = PTR_ERR(dchild); + CERROR("error looking up logfile "LPX64":0x%x: rc %d\n", + logid->lgl_oid, logid->lgl_ogen, rc); + GOTO(cleanup, rc); + } + + cleanup_phase = 2; + if (dchild->d_inode == NULL) { + rc = -ENOENT; + CERROR("nonexistent log file "LPX64":"LPX64": rc %d\n", + logid->lgl_oid, logid->lgl_ogr, rc); + GOTO(cleanup, rc); + } + + handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild, + O_RDWR | O_LARGEFILE); + if (IS_ERR(handle->lgh_file)) { + rc = PTR_ERR(handle->lgh_file); + CERROR("error opening logfile "LPX64"0x%x: rc %d\n", + logid->lgl_oid, logid->lgl_ogen, rc); + GOTO(cleanup, rc); + } + + /* assign the value of lgh_id for handle directly */ + handle->lgh_id = *logid; + + } else if (name) { + handle->lgh_file = llog_filp_open(name, open_flags, 0644); + + if (IS_ERR(handle->lgh_file)) + GOTO(cleanup, rc = PTR_ERR(handle->lgh_file)); + + handle->lgh_id.lgl_ogr = 1; + handle->lgh_id.lgl_oid = + handle->lgh_file->f_dentry->d_inode->i_ino; + handle->lgh_id.lgl_ogen = + handle->lgh_file->f_dentry->d_inode->i_generation; + + } else { + oa = obdo_alloc(); + if (oa == NULL) + GOTO(cleanup, rc = -ENOMEM); + /* XXX get some filter group constants */ + oa->o_gr = 1; + oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP; + rc = obd_create(ctxt->loc_exp, oa, NULL, NULL); + if (rc) + GOTO(cleanup, rc); + + dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, oa->o_id, + oa->o_generation, oa->o_gr); + + if (IS_ERR(dchild)) + GOTO(cleanup, rc = PTR_ERR(dchild)); + cleanup_phase = 2; + handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild, + open_flags); + if (IS_ERR(handle->lgh_file)) + GOTO(cleanup, rc = PTR_ERR(handle->lgh_file)); + + handle->lgh_id.lgl_ogr = oa->o_gr; + handle->lgh_id.lgl_oid = oa->o_id; + handle->lgh_id.lgl_ogen = oa->o_generation; + } + + handle->lgh_ctxt = ctxt; + finish: + if (oa) + obdo_free(oa); + RETURN(rc); +cleanup: + switch (cleanup_phase) { + case 2: + l_dput(dchild); + case 1: + llog_free_handle(handle); + } + goto finish; +} + +static int mgs_llog_lvfs_close(struct llog_handle *handle) +{ + int rc; + ENTRY; + + rc = filp_close(handle->lgh_file, 0); + if (rc) + CERROR("error closing log: rc %d\n", rc); + RETURN(rc); +} + +static int mgs_llog_lvfs_destroy(struct llog_handle *handle) +{ + struct dentry *fdentry; + struct obdo *oa; + int rc; + ENTRY; + + fdentry = handle->lgh_file->f_dentry; + if (strcmp(fdentry->d_parent->d_name.name, MOUNT_CONFIGS_DIR) == 0) { + /* CONFIGS files aren't really "lustre" objects - special case*/ + struct obd_device *obd = handle->lgh_ctxt->loc_exp->exp_obd; + struct inode *inode = fdentry->d_parent->d_inode; + struct lvfs_run_ctxt saved; + + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + dget(fdentry); + rc = mgs_llog_lvfs_close(handle); + + if (rc == 0) { + down(&inode->i_sem); + rc = vfs_unlink(inode, fdentry); + up(&inode->i_sem); + } + + dput(fdentry); + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + RETURN(rc); + } + + oa = obdo_alloc(); + if (oa == NULL) + RETURN(-ENOMEM); + + oa->o_id = handle->lgh_id.lgl_oid; + oa->o_gr = handle->lgh_id.lgl_ogr; + oa->o_generation = handle->lgh_id.lgl_ogen; + oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLGENER; + + rc = mgs_llog_lvfs_close(handle); + if (rc) + GOTO(out, rc); + + rc = obd_destroy(handle->lgh_ctxt->loc_exp, oa, NULL, NULL); + out: + obdo_free(oa); + RETURN(rc); +} + +/* reads the catalog list */ +int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd, + char *name, int count, struct llog_catid *idarray) +{ + struct lvfs_run_ctxt saved; + struct l_file *file; + int rc; + int size = sizeof(*idarray) * count; + loff_t off = 0; + + if (!count) { + CERROR("Empty catalog?\n"); + RETURN(0); + } + + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700); + if (!file || IS_ERR(file)) { + rc = PTR_ERR(file); + CERROR("OBD filter: cannot open/create %s: rc = %d\n", + name, rc); + GOTO(out, rc); + } + + if (!S_ISREG(file->f_dentry->d_inode->i_mode)) { + CERROR("%s is not a regular file!: mode = %o\n", name, + file->f_dentry->d_inode->i_mode); + GOTO(out, rc = -ENOENT); + } + + rc = fsfilt_read_record(disk_obd, file, idarray, size, &off); + if (rc) { + CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n", + name, rc); + GOTO(out, rc); + } + + out: + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + if (file && !IS_ERR(file)) + rc = filp_close(file, 0); + RETURN(rc); +} +EXPORT_SYMBOL(llog_get_cat_list); + +/* writes the cat list */ +int llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd, + char *name, int count, struct llog_catid *idarray) +{ + struct lvfs_run_ctxt saved; + struct l_file *file; + int rc; + int size = sizeof(*idarray) * count; + loff_t off = 0; + + if (!count) { + CERROR("Empty catalog?\n"); + RETURN(0); + } + + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700); + if (!file || IS_ERR(file)) { + rc = PTR_ERR(file); + CERROR("OBD filter: cannot open/create %s: rc = %d\n", + name, rc); + GOTO(out, rc); + } + + if (!S_ISREG(file->f_dentry->d_inode->i_mode)) { + CERROR("%s is not a regular file!: mode = %o\n", name, + file->f_dentry->d_inode->i_mode); + GOTO(out, rc = -ENOENT); + } + + rc = fsfilt_write_record(disk_obd, file, idarray, size, &off, 1); + if (rc) { + CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n", + name, rc); + GOTO(out, rc); + } + + out: + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + if (file && !IS_ERR(file)) + rc = filp_close(file, 0); + RETURN(rc); +} + +struct llog_operations mgs_llog_lvfs_ops = { + lop_write_rec: mgs_llog_lvfs_write_rec, + lop_next_block: mgs_llog_lvfs_next_block, + lop_read_header: mgs_llog_lvfs_read_header, + lop_create: mgs_llog_lvfs_create, + lop_destroy: mgs_llog_lvfs_destroy, + lop_close: mgs_llog_lvfs_close, + // lop_cancel: llog_lvfs_cancel, +}; + +EXPORT_SYMBOL(mgs_llog_lvfs_ops); + +#else /* !__KERNEL__ */ + +static int mgs_llog_lvfs_read_header(struct llog_handle *handle) +{ + LBUG(); + return 0; +} + +static int mgs_llog_lvfs_write_rec(struct llog_handle *loghandle, + struct llog_rec_hdr *rec, + struct llog_cookie *reccookie, int cookiecount, + void *buf, int idx) +{ + LBUG(); + return 0; +} + +static int mgs_llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx, + int next_idx, __u64 *cur_offset, void *buf, + int len) +{ + LBUG(); + return 0; +} + +static int mgs_llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, + struct llog_logid *logid, char *fsname, char *name) +{ + LBUG(); + return 0; +} + +static int mgs_llog_lvfs_close(struct llog_handle *handle) +{ + LBUG(); + return 0; +} + +static int mgs_llog_lvfs_destroy(struct llog_handle *handle) +{ + LBUG(); + return 0; +} + +int mgs_llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd, + char *name, int count, struct llog_catid *idarray) +{ + LBUG(); + return 0; +} + +int mgs_llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd, + char *name, int count, struct llog_catid *idarray) +{ + LBUG(); + return 0; +} + +struct llog_operations mgs_llog_lvfs_ops = { + lop_write_rec: mgs_llog_lvfs_write_rec, + lop_next_block: mgs_llog_lvfs_next_block, + lop_read_header: mgs_llog_lvfs_read_header, + lop_create: mgs_llog_lvfs_create, + lop_destroy: mgs_llog_lvfs_destroy, + lop_close: mgs_llog_lvfs_close, +// lop_cancel: mgs_llog_lvfs_cancel, +}; +#endif diff --git a/lustre/obdclass/llog_lvfs.c b/lustre/obdclass/llog_lvfs.c index df4dc34..2c8d2f3 100644 --- a/lustre/obdclass/llog_lvfs.c +++ b/lustre/obdclass/llog_lvfs.c @@ -425,8 +425,7 @@ static int llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx, RETURN(-EIO); } -static struct file *llog_filp_open(char* fsname, char *name, - int flags, int mode) +static struct file *llog_filp_open(char *name, int flags, int mode) { char *logname; struct file *filp; @@ -435,12 +434,9 @@ static struct file *llog_filp_open(char* fsname, char *name, OBD_ALLOC(logname, PATH_MAX); if (logname == NULL) return ERR_PTR(-ENOMEM); - if (fsname) - len = snprintf(logname, PATH_MAX, "%s/%s/%s", - MOUNT_CONFIGS_DIR, fsname, name); - else - len = snprintf(logname, PATH_MAX, "%s/%s", - MOUNT_CONFIGS_DIR, name); + + len = snprintf(logname, PATH_MAX, "%s/%s", + MOUNT_CONFIGS_DIR, name); if (len >= PATH_MAX - 1) { filp = ERR_PTR(-ENAMETOOLONG); @@ -459,7 +455,7 @@ static struct file *llog_filp_open(char* fsname, char *name, /* This is a callback from the llog_* functions. * Assumes caller has already pushed us into the kernel context. */ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, - struct llog_logid *logid, char* fsname, char *name) + struct llog_logid *logid, char *name) { struct llog_handle *handle; struct obd_device *obd; @@ -510,17 +506,11 @@ static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res, handle->lgh_id = *logid; } else if (name) { - handle->lgh_file = llog_filp_open(fsname, name, open_flags, 0644); + handle->lgh_file = llog_filp_open(name, open_flags, 0644); if (IS_ERR(handle->lgh_file)) GOTO(cleanup, rc = PTR_ERR(handle->lgh_file)); - rc = obd_lvfs_open_llog(ctxt->loc_exp, - handle->lgh_file->f_dentry->d_inode->i_ino, - handle->lgh_file->f_dentry); - if (rc) - GOTO(cleanup, rc); - handle->lgh_id.lgl_ogr = 1; handle->lgh_id.lgl_oid = handle->lgh_file->f_dentry->d_inode->i_ino; -- 1.8.3.1