From 0999c8fc9497381685d7190793f5432b1d71ce7c Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 22 Aug 2008 17:40:48 +0000 Subject: [PATCH] b=15899 i=nathan i=adilger add OST pools --- lustre/mgs/mgs_handler.c | 175 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 152 insertions(+), 23 deletions(-) diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 62d333e..7f8d5c6 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -333,6 +333,21 @@ static int mgs_put_cfg_lock(struct lustre_handle *lockh) RETURN(0); } +static void mgs_revoke_lock(struct obd_device *obd, char *fsname, + struct lustre_handle *lockh) +{ + int lockrc; + + if (fsname[0]) { + lockrc = mgs_get_cfg_lock(obd, fsname, lockh); + if (lockrc != ELDLM_OK) + CERROR("lock error %d for fs %s\n", lockrc, + fsname); + else + mgs_put_cfg_lock(lockh); + } +} + /* rc=0 means ok 1 means update <0 means error */ @@ -484,7 +499,7 @@ static int mgs_set_info_rpc(struct ptlrpc_request *req) struct mgs_send_param *msp, *rep_msp; struct lustre_handle lockh; int rep_size[] = { sizeof(struct ptlrpc_body), sizeof(*msp) }; - int lockrc, rc; + int rc; struct lustre_cfg_bufs bufs; struct lustre_cfg *lcfg; char fsname[MTI_NAME_MAXLEN]; @@ -503,19 +518,9 @@ static int mgs_set_info_rpc(struct ptlrpc_request *req) RETURN(rc); } - /* Revoke lock so everyone updates. Should be alright if - * someone was already reading while we were updating the logs, - * so we don't really need to hold the lock while we're - * writing. - */ - if (fsname[0]) { - lockrc = mgs_get_cfg_lock(obd, fsname, &lockh); - if (lockrc != ELDLM_OK) - CERROR("lock error %d for fs %s\n", lockrc, - fsname); - else - mgs_put_cfg_lock(&lockh); - } + /* request for update */ + mgs_revoke_lock(obd, fsname, &lockh); + lustre_cfg_free(lcfg); lustre_pack_reply(req, 2, rep_size, NULL); @@ -661,6 +666,134 @@ static inline int mgs_destroy_export(struct obd_export *exp) RETURN(0); } +static int mgs_extract_fs_pool(char * arg, char *fsname, char *poolname) +{ + char *ptr; + + ENTRY; + for (ptr = arg; (*ptr != '\0') && (*ptr != '.'); ptr++ ) { + *fsname = *ptr; + fsname++; + } + if (*ptr == '\0') + return -EINVAL; + *fsname = '\0'; + ptr++; + strcpy(poolname, ptr); + + RETURN(0); +} + +static int mgs_iocontrol_pool(struct obd_device *obd, + struct obd_ioctl_data *data) +{ + int rc; + struct lustre_handle lockh; + struct lustre_cfg *lcfg = NULL; + struct llog_rec_hdr rec; + char *fsname = NULL; + char *poolname = NULL; + ENTRY; + + OBD_ALLOC(fsname, MTI_NAME_MAXLEN); + if (fsname == NULL) + RETURN(-ENOMEM); + + OBD_ALLOC(poolname, MAXPOOLNAME + 1); + if (poolname == NULL) { + rc = -ENOMEM; + GOTO(out_pool, rc); + } + rec.lrh_len = llog_data_len(data->ioc_plen1); + + if (data->ioc_type == LUSTRE_CFG_TYPE) { + rec.lrh_type = OBD_CFG_REC; + } else { + CERROR("unknown cfg record type:%d \n", data->ioc_type); + rc = -EINVAL; + GOTO(out_pool, rc); + } + + if (data->ioc_plen1 > CFS_PAGE_SIZE) { + rc = -E2BIG; + GOTO(out_pool, rc); + } + + OBD_ALLOC(lcfg, data->ioc_plen1); + if (lcfg == NULL) { + rc = -ENOMEM; + GOTO(out_pool, rc); + } + rc = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1); + if (rc) + GOTO(out_pool, rc); + + if (lcfg->lcfg_bufcount < 2) { + rc = -EINVAL; + GOTO(out_pool, rc); + } + + /* first arg is always . */ + mgs_extract_fs_pool(lustre_cfg_string(lcfg, 1), fsname, + poolname); + + switch (lcfg->lcfg_command) { + case LCFG_POOL_NEW: { + if (lcfg->lcfg_bufcount != 2) + RETURN(-EINVAL); + rc = mgs_pool_cmd(obd, LCFG_POOL_NEW, fsname, + poolname, NULL); + break; + } + case LCFG_POOL_ADD: { + if (lcfg->lcfg_bufcount != 3) + RETURN(-EINVAL); + rc = mgs_pool_cmd(obd, LCFG_POOL_ADD, fsname, poolname, + lustre_cfg_string(lcfg, 2)); + break; + } + case LCFG_POOL_REM: { + if (lcfg->lcfg_bufcount != 3) + RETURN(-EINVAL); + rc = mgs_pool_cmd(obd, LCFG_POOL_REM, fsname, poolname, + lustre_cfg_string(lcfg, 2)); + break; + } + case LCFG_POOL_DEL: { + if (lcfg->lcfg_bufcount != 2) + RETURN(-EINVAL); + rc = mgs_pool_cmd(obd, LCFG_POOL_DEL, fsname, + poolname, NULL); + break; + } + default: { + rc = -EINVAL; + GOTO(out_pool, rc); + } + } + + if (rc) { + CERROR("OBD_IOC_POOL err %d, cmd %X for pool %s.%s\n", + rc, lcfg->lcfg_command, fsname, poolname); + GOTO(out_pool, rc); + } + + /* request for update */ + mgs_revoke_lock(obd, fsname, &lockh); + +out_pool: + if (lcfg != NULL) + OBD_FREE(lcfg, data->ioc_plen1); + + if (fsname != NULL) + OBD_FREE(fsname, MTI_NAME_MAXLEN); + + if (poolname != NULL) + OBD_FREE(poolname, MAXPOOLNAME + 1); + + RETURN(rc); +} + /* from mdt_iocontrol */ int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg) @@ -680,7 +813,6 @@ int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, struct lustre_cfg *lcfg; struct llog_rec_hdr rec; char fsname[MTI_NAME_MAXLEN]; - int lockrc; rec.lrh_len = llog_data_len(data->ioc_plen1); @@ -711,20 +843,17 @@ int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len, someone was already reading while we were updating the logs, so we don't really need to hold the lock while we're writing (above). */ - if (fsname[0]) { - lockrc = mgs_get_cfg_lock(obd, fsname, &lockh); - if (lockrc != ELDLM_OK) - CERROR("lock error %d for fs %s\n", lockrc, - fsname); - else - mgs_put_cfg_lock(&lockh); - } + mgs_revoke_lock(obd, fsname, &lockh); out_free: OBD_FREE(lcfg, data->ioc_plen1); RETURN(rc); } + case OBD_IOC_POOL: { + RETURN(mgs_iocontrol_pool(obd, data)); + } + case OBD_IOC_DUMP_LOG: { struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT); -- 1.8.3.1