From 32c30885db351661af525d374d76a64024046a0c Mon Sep 17 00:00:00 2001 From: lincent Date: Tue, 15 Nov 2005 21:09:16 +0000 Subject: [PATCH] ADD MGMT_REGISTER --- lustre/include/linux/lustre_idl.h | 8 ++ lustre/include/linux/lustre_mgs.h | 4 +- lustre/include/linux/obd_support.h | 11 +- lustre/mgc/mgc_request.c | 38 ++++++ lustre/mgs/mgs_handler.c | 17 ++- lustre/mgs/mgs_llog.c | 253 +++++++++++++++++++------------------ lustre/ptlrpc/pack_generic.c | 4 + 7 files changed, 199 insertions(+), 136 deletions(-) diff --git a/lustre/include/linux/lustre_idl.h b/lustre/include/linux/lustre_idl.h index e0b193e..4b0783f 100644 --- a/lustre/include/linux/lustre_idl.h +++ b/lustre/include/linux/lustre_idl.h @@ -946,6 +946,7 @@ typedef enum { MGMT_CONNECT = 250, MGMT_DISCONNECT, MGMT_EXCEPTION, /* node died, etc. */ + MGMT_REGISTER, /* first connect. */ MGMT_OST_ADD, MGMT_OST_DEL, MGMT_LAST_OPC @@ -963,7 +964,14 @@ struct mgmt_ost_info { extern void lustre_swab_mgmt_ost_info(struct mgmt_ost_info *oinfo); struct mgmt_mds_info { + char mmi_fullfsname[64]; + char mmi_mds_name[64]; + char mmi_mds_nodename[64]; __u64 mmi_nid; + __u32 mmi_index; + __u32 mmi_pattern; /* PATTERN_RAID0, PATTERN_RAID1 */ + __u64 mmi_stripe_size; /* in bytes */ + __u64 mmi_stripe_offset; /* in bytes */ }; extern void lustre_swab_mgmt_mds_info(struct mgmt_mds_info *oinfo); diff --git a/lustre/include/linux/lustre_mgs.h b/lustre/include/linux/lustre_mgs.h index 508a27d..b109ae2 100644 --- a/lustre/include/linux/lustre_mgs.h +++ b/lustre/include/linux/lustre_mgs.h @@ -70,7 +70,6 @@ struct mgc_op_data { }; struct system_db { - __u64 version; char fsname[64]; char mds_name[64]; char mds_uuid[64]; @@ -111,6 +110,5 @@ int mgs_fs_cleanup(struct obd_device *obddev); extern int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg); -extern struct mgc_open_llog* - mgc_find_open_llog(struct obd_device *obd, char *name); +extern int mgs_mds_register(struct ptlrpc_request*); #endif diff --git a/lustre/include/linux/obd_support.h b/lustre/include/linux/obd_support.h index bcd700d..b32b6a1 100644 --- a/lustre/include/linux/obd_support.h +++ b/lustre/include/linux/obd_support.h @@ -169,11 +169,12 @@ extern wait_queue_head_t obd_race_waitq; #define OBD_FAIL_MDC_REVALIDATE_PAUSE 0x800 -#define OBD_FAIL_MGS 0x900 -#define OBD_FAIL_MGS_CONNECT_NET 0x117 -#define OBD_FAIL_MGS_DISCONNECT_NET 0x11a -#define OBD_FAIL_MGS_ALL_REPLY_NET 0x122 -#define OBD_FAIL_MGS_ALL_REQUEST_NET 0x123 +#define OBD_FAIL_MGMT 0x900 +#define OBD_FAIL_MGMT_REGISTER 0x901 +#define OBD_FAIL_MGMT_CONNECT_NET 0x117 +#define OBD_FAIL_MGMT_DISCONNECT_NET 0x11a +#define OBD_FAIL_MGMT_ALL_REPLY_NET 0x122 +#define OBD_FAIL_MGMT_ALL_REQUEST_NET 0x123 /* preparation for a more advanced failure testbed (not functional yet) */ #define OBD_FAIL_MASK_SYS 0x0000FF00 diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index cd0a3fb..301dc5d 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -48,6 +48,44 @@ #include "mgc_internal.h" +int mgc_mds_add(struct obd_export *exp, struct mgmt_mds_info *minfo) +{ + struct ptlrpc_request *req; + struct mgmt_mds_info *req_minfo, *rep_minfo; + int size = sizeof(*req_minfo); + int rep_size = sizeof(rep_minfo); + int rc; + ENTRY; + + req = ptlrpc_prep_req(class_exp2cliimp(exp), MGMT_REGISTER, + 1, &size, NULL); + if (!req) + RETURN(rc = -ENOMEM); + + req_minfo = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*req_minfo)); + memcpy(req_minfo, minfo, sizeof(*req_minfo)); + + req->rq_replen = lustre_msg_size(1, &rep_size); + + rc = ptlrpc_queue_wait(req); + if (!rc) { + int index; + rep_minfo = lustre_swab_repbuf(req, 0, sizeof(*rep_minfo), + lustre_swab_mgmt_mds_info); + index = rep_minfo->mmi_index; + if (index < 0) { + CERROR("Register failed. rc = %d\n", index); + GOTO(out, rc = index); + } else + CERROR("Register OK. (index = %d)\n", index); + } +out: + ptlrpc_req_finished(req); + + RETURN(rc); +} +EXPORT_SYMBOL(mgc_mds_add); + int mgc_ost_add(struct obd_export *exp, struct mgmt_ost_info *oinfo, struct mgmt_mds_info *minfo) { diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index c8928c4..d1cbf24 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -284,13 +284,13 @@ static int mgs_cleanup(struct obd_device *obd) int mgs_handle(struct ptlrpc_request *req) { - int fail = OBD_FAIL_MGS_ALL_REPLY_NET; + int fail = OBD_FAIL_MGMT_ALL_REPLY_NET; int rc = 0; struct mgs_obd *mgs = NULL; /* quell gcc overwarning */ struct obd_device *obd = NULL; ENTRY; - OBD_FAIL_RETURN(OBD_FAIL_MGS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0); + OBD_FAIL_RETURN(OBD_FAIL_MGMT_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0); LASSERT(current->journal_info == NULL); /* XXX identical to MDS */ @@ -336,7 +336,7 @@ int mgs_handle(struct ptlrpc_request *req) switch (req->rq_reqmsg->opc) { case MGMT_CONNECT: DEBUG_REQ(D_INODE, req, "connect"); - OBD_FAIL_RETURN(OBD_FAIL_MGS_CONNECT_NET, 0); + OBD_FAIL_RETURN(OBD_FAIL_MGMT_CONNECT_NET, 0); rc = target_handle_connect(req, mgs_handle); if (!rc) { /* Now that we have an export, set mgs. */ @@ -347,7 +347,7 @@ int mgs_handle(struct ptlrpc_request *req) case MGMT_DISCONNECT: DEBUG_REQ(D_INODE, req, "disconnect"); - OBD_FAIL_RETURN(OBD_FAIL_MGS_DISCONNECT_NET, 0); + OBD_FAIL_RETURN(OBD_FAIL_MGMT_DISCONNECT_NET, 0); rc = target_handle_disconnect(req); req->rq_status = rc; /* superfluous? */ break; @@ -377,7 +377,14 @@ int mgs_handle(struct ptlrpc_request *req) OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0); rc = -ENOTSUPP; /* la la la */ break; - + case MGMT_REGISTER: + CDEBUG(D_INODE, "mds/(maybe new filesystem) register\n"); + OBD_FAIL_RETURN(OBD_FAIL_MGMT_REGISTER, 0); + rc = mgs_mds_register(req); + case MGMT_OST_ADD: + CDEBUG(D_INODE, "ost add\n"); + case MGMT_OST_DEL: + CDEBUG(D_INODE, "ost del\n"); case LLOG_ORIGIN_HANDLE_CREATE: DEBUG_REQ(D_INODE, req, "llog_init"); OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0); diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index b0afd3d..8fc2f44 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -48,7 +48,18 @@ static struct lustre_cfg_bufs llog_bufs; static int mgs_do_record(struct obd_device *obd, struct llog_handle *llh, - void *cfg_buf); + void *cfg_buf) +{ + struct lvfs_run_ctxt saved; + struct llog_rec_hdr rec; + int rc = 0; + + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + rc = llog_write_rec(llh, &rec, NULL, 0, cfg_buf, -1); + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + + RETURN(rc); +} static int record_attach(struct obd_device *obd, struct llog_handle *llh, char* name, char *type, char *uuid) @@ -175,92 +186,6 @@ static int record_mount_point(struct obd_device *obd, struct llog_handle *llh, return rc; } -struct mgs_open_llog* find_mgs_open_llog(struct obd_device *obd, char *name) -{ - struct mgs_obd *mgs = &obd->u.mgs; - struct list_head *tmp; - struct mgs_open_llog *mol; - char fsname[64]; - char *p; - - p = strrchr(name, '/'); - if (p != NULL) - strncpy(fsname, name, p - name); - else - return NULL; - - list_for_each(tmp, &mgs->mgs_open_llogs) { - mol = list_entry(tmp, struct mgs_open_llog, mol_list); - if (!strcmp(mol->mol_fsname, fsname)) - return mol; - } - return NULL; -} - -struct mgs_open_llog* create_mgs_open_llog(struct obd_device *obd, char *name) -{ - struct mgs_obd *mgs = &obd->u.mgs; - struct mgs_open_llog *mol, *tmp; - char *p; - - OBD_ALLOC(mol, sizeof(*mol)); - if (!mol) { - CERROR("can not allocate memory for mgs_open_llog.\n"); - return NULL; - } - - p = strrchr(name, '/'); - if (p != NULL) - strncpy(mol->mol_fsname, name, p - name); - else { - CERROR("logname need to include fsname.\n"); - goto cleanup; - } -#if 0 - rc = mgs_load_system_db(obd, name, &mol->mol_system_db); - if (rc) - goto cleanup; -#endif - mol->mol_refs = 1; - - spin_lock_init(&mol->mol_lock); - - spin_lock(&mgs->mgs_open_llogs_lock); - - tmp = find_mgs_open_llog(obd, name); - if(tmp) { - OBD_FREE(mol->mol_system_db, sizeof(struct system_db)); - OBD_FREE(mol, sizeof(*mol)); - mol = tmp; - } else - list_add(&mol->mol_list, &mgs->mgs_open_llogs); - - spin_unlock(&mgs->mgs_open_llogs_lock); - - return mol; - -cleanup: - OBD_FREE(mol, sizeof(*mol)); - return NULL; -} - -struct mgs_open_llog* open_mgs_open_llog(struct obd_device *obd, char *name) -{ - struct mgs_open_llog *mol; - - mol = find_mgs_open_llog(obd, name); - if (!mol) { - mol = create_mgs_open_llog(obd, name); - return mol; - } - - spin_lock(&mol->mol_lock); - mol->mol_refs++; - spin_unlock(&mol->mol_lock); - - return mol; -} - static int mgs_start_record(struct obd_device *obd, struct llog_handle *llh, char *name) { @@ -323,68 +248,64 @@ static int mgs_clear_record(struct obd_device *obd, RETURN(rc); } -static int mgs_do_record(struct obd_device *obd, struct llog_handle *llh, - void *cfg_buf) +static int mgs_write_basic_llog(struct obd_device *obd, + struct mgmt_mds_info *mmi) { - struct lvfs_run_ctxt saved; - struct llog_rec_hdr rec; int rc = 0; - - push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - rc = llog_write_rec(llh, &rec, NULL, 0, cfg_buf, -1); - pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - - RETURN(rc); + CERROR("New basic LLOG.\n"); /*FIXME: add soon*/ + return rc; } - -static int mgs_write_mds_llog(struct obd_device *obd, char* name) +static int mgs_write_mds_llog(struct obd_device *obd, struct mgmt_mds_info *mmi) { struct mgs_open_llog *mol; struct llog_handle *llh; - struct system_db *db; struct list_head *tmp; + char *name = mmi->mmi_fullfsname; + struct lov_desc *lovdesc; char lov_name[64]; char uuid[64]; int i, rc = 0; - mol = find_mgs_open_llog(obd, name); - if (!mol) - RETURN(-EINVAL); + llh = llog_alloc_handle(); + if (llh == NULL) + RETURN(-ENOMEM); - db = mol->mol_system_db; - if(!db) - RETURN(-EINVAL); - - llh = mol->mol_cfg_llh; + OBD_ALLOC(lovdesc, sizeof(*lovdesc)); + if (lovdesc == NULL) + GOTO(cleanup, rc = -ENOMEM); + lovdesc->ld_pattern = mmi->mmi_pattern; + lovdesc->ld_default_stripe_size = mmi->mmi_stripe_size; + lovdesc->ld_default_stripe_offset = mmi->mmi_stripe_offset; rc = mgs_clear_record(obd, llh, name); if (rc) { CERROR("failed to clear log %s: %d\n", name, rc); - RETURN(rc); + GOTO(cleanup, rc); } rc = mgs_start_record(obd, llh, name); if (rc) { CERROR("failed to record log %s: %d\n", name, rc); - RETURN(rc); + GOTO(cleanup, rc); } /* the same uuid for lov and osc */ - sprintf(uuid, "%s_lov_UUID", db->mds_name); - sprintf(lov_name, "lov_%s", db->mds_name); + sprintf(uuid, "%s_lov_UUID", mmi->mmi_mds_name); + sprintf(lov_name, "lov_%s", mmi->mmi_mds_name); + sprintf((char*)lovdesc->ld_uuid.uuid, "%s_UUID", lov_name); rc = record_attach(obd, llh, lov_name, "lov", uuid); if (rc) { CERROR("failed to record log(attach lov) %s: %d\n", name, rc); - RETURN(rc); + GOTO(cleanup, rc); } - rc = record_lov_setup(obd, llh, lov_name, &db->lovdesc); + rc = record_lov_setup(obd, llh, lov_name, lovdesc); if (rc) { CERROR("failed to record log(setup) %s: %d\n", name, rc); - RETURN(rc); + GOTO(cleanup, rc); } - +#if 0 i = 0; list_for_each(tmp, &db->ost_infos) { char ost_node_uuid[64]; @@ -431,21 +352,23 @@ static int mgs_write_mds_llog(struct obd_device *obd, char* name) RETURN(rc); } } - - rc = record_mount_point(obd, llh, db->mds_name, lov_name, NULL); +#endif + rc = record_mount_point(obd, llh, mmi->mmi_mds_name, lov_name, NULL); if (rc) { CERROR("failed to record log(lov_modify_tgts) %s: %d\n", name, rc); - RETURN(rc); + GOTO(cleanup, rc); } rc = mgs_end_record(obd, llh, name); if (rc) { CERROR("failed to record log %s: %d\n", name, rc); - RETURN(rc); + GOTO(cleanup, rc); } - +out: RETURN(rc); +cleanup: + llog_free_handle(llh); } static int mgs_write_client_llog(struct obd_device *obd, char* name) @@ -462,6 +385,7 @@ static int mgs_write_client_llog(struct obd_device *obd, char* name) char *setup_argv[2]; int i, rc = 0; +#if 0 mol = find_mgs_open_llog(obd, name); if (!mol) RETURN(-EINVAL); @@ -587,9 +511,10 @@ static int mgs_write_client_llog(struct obd_device *obd, char* name) CERROR("failed to record log %s: %d\n", name, rc); RETURN(rc); } +#endif RETURN(rc); } - +#if 0 int mgs_update_llog(struct obd_device *obd, char *name) { char logname[64]; @@ -617,6 +542,89 @@ int mgs_update_llog(struct obd_device *obd, char *name) return rc; } +#endif +int decompose_fullfsname(char *fullfsname, char *fsname, char *poolname) +{ + char *p = NULL; + + OBD_ALLOC(fsname, sizeof(*fullfsname)); + if (!fsname) { + CERROR("Can't not copy fsname from request.\n"); + return -ENOMEM; + } + + p = strchr(fsname, '/'); + if (p) { + p = '\0'; + poolname = p++; + } + return 0; +} + +int mgs_mds_register(struct ptlrpc_request *req) +{ + struct obd_export *exp = req->rq_export; + struct obd_device *obd = exp->exp_obd; + struct mgs_obd *mgs = &obd->u.mgs; + struct mgmt_mds_info *mmi, *rep_mmi; + struct lvfs_run_ctxt saved; + struct dentry *fs_dentry, *pool_dentry; + char *fsname = NULL, *poolname = NULL; + int rep_size = sizeof(*rep_mmi); + int index, rc; + + mmi = lustre_swab_reqbuf(req, 0, sizeof(*mmi), + lustre_swab_mgmt_mds_info); + if (mmi == NULL) { + CERROR("Can't unpack mgmt_mds_info\n"); + GOTO(out, rc=-EFAULT); + } + + CDEBUG(D_INODE, "New mds belong to FS/POOL %s\n", mmi->mmi_fullfsname); + + rc = decompose_fullfsname(mmi->mmi_fullfsname, fsname, poolname); + if (rc) + GOTO(out, rc); + + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + + fs_dentry = simple_mkdir(mgs->mgs_configs_dir, fsname, 0777, 1); + if (IS_ERR(fs_dentry)) { + rc = PTR_ERR(fs_dentry); + CERROR("cannot create %s dir : rc = %d\n", fsname, rc); + GOTO(cleanup_pop, rc); + } + + pool_dentry = simple_mkdir(fs_dentry, poolname, 0777, 1); + if (IS_ERR(pool_dentry)) { + rc = PTR_ERR(pool_dentry); + CERROR("cannot create %s dir : rc = %d\n", poolname, rc); + GOTO(cleanup_dput, rc); + } + dput(pool_dentry); + + /*FIXME : change when we can use several mds */ + mmi->mmi_index = 1; + + rc = mgs_write_basic_llog(obd, mmi); +cleanup_dput: + dput(fs_dentry); +cleanup_pop: + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + OBD_FREE(fsname, sizeof(mmi->mmi_fullfsname)); +out: + if (rc) + mmi->mmi_index = rc; + rc = lustre_pack_reply(req, 1, &rep_size, NULL); + if (!rc) { + rep_mmi = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_mmi)); + memcpy(rep_mmi, mmi, sizeof(*mmi)); + } else { + CERROR("lustre_pack_reply failed: rc %d\n", rc); + req->rq_status = rc; + } + return rc; +} int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg) @@ -798,4 +806,3 @@ int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, } RETURN(0); } - diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index d2d0ae5..55fdd42 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -565,6 +565,10 @@ void lustre_swab_mgmt_ost_info(struct mgmt_ost_info *oinfo) void lustre_swab_mgmt_mds_info(struct mgmt_mds_info *minfo) { __swab64s(&minfo->mmi_nid); + __swab32s(&minfo->mmi_index); + __swab32s(&minfo->mmi_pattern); + __swab64s(&minfo->mmi_stripe_size); + __swab64s(&minfo->mmi_stripe_offset); } static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i) -- 1.8.3.1