From: wangdi Date: Thu, 19 May 2005 16:45:33 +0000 (+0000) Subject: Branch: HEAD X-Git-Tag: 1.4.10~1132 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=265debce462205947da4f70a958ae10b3bd73859;p=fs%2Flustre-release.git Branch: HEAD 1.port new lustre_lcfg structure from b1_4 to HEAD 2.some fix on test scripts for WB cache --- diff --git a/lustre/cmobd/cm_obd.c b/lustre/cmobd/cm_obd.c index 5503d0d..ab2a306 100644 --- a/lustre/cmobd/cm_obd.c +++ b/lustre/cmobd/cm_obd.c @@ -120,20 +120,20 @@ static int cmobd_setup(struct obd_device *obd, obd_count len, void *buf) int valsize, rc; ENTRY; - if (lcfg->lcfg_inllen1 == 0 || lcfg->lcfg_inlbuf1 == NULL) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("%s: setup requires master device uuid\n", obd->obd_name); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 == 0 || lcfg->lcfg_inlbuf2 == NULL) { + if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) { CERROR("%s: setup requires cache device uuid\n", obd->obd_name); RETURN(-EINVAL); } - obd_str2uuid(&master_uuid, lcfg->lcfg_inlbuf1); - obd_str2uuid(&cache_uuid, lcfg->lcfg_inlbuf2); + obd_str2uuid(&master_uuid, lustre_cfg_buf(lcfg, 1)); + obd_str2uuid(&cache_uuid, lustre_cfg_buf(lcfg, 2)); /* getting master obd */ cmobd->master_obd = find_master_obd(obd, &master_uuid); diff --git a/lustre/cobd/cache_obd.c b/lustre/cobd/cache_obd.c index 99707ef..939d1f4 100644 --- a/lustre/cobd/cache_obd.c +++ b/lustre/cobd/cache_obd.c @@ -55,43 +55,45 @@ static int cobd_setup(struct obd_device *obd, obd_count len, void *buf) int rc = 0; ENTRY; - if (lcfg->lcfg_inllen1 == 0 || lcfg->lcfg_inlbuf1 == NULL) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 || + lustre_cfg_buf(lcfg, 1) == NULL) { CERROR("%s: setup requires master device name\n", obd->obd_name); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 == 0 || lcfg->lcfg_inlbuf2 == NULL) { + if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1 || + lustre_cfg_buf(lcfg, 2) == NULL) { CERROR("%s: setup requires cache device name\n", obd->obd_name); RETURN(-EINVAL); } - master = class_name2obd(lcfg->lcfg_inlbuf1); + master = class_name2obd(lustre_cfg_string(lcfg, 1)); if (!master) { CERROR("%s: unable to find master: %s\n", - obd->obd_name, lcfg->lcfg_inlbuf1); + obd->obd_name, lustre_cfg_string(lcfg, 1)); RETURN(-EINVAL); } sema_init(&cobd->sem, 1); - OBD_ALLOC(cobd->master_name, lcfg->lcfg_inllen1); + OBD_ALLOC(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1)); if (!cobd->master_name) RETURN(-ENOMEM); - memcpy(cobd->master_name, lcfg->lcfg_inlbuf1, - lcfg->lcfg_inllen1); + memcpy(cobd->master_name, lustre_cfg_string(lcfg, 1), + LUSTRE_CFG_BUFLEN(lcfg, 1)); - OBD_ALLOC(cobd->cache_name, lcfg->lcfg_inllen2); + OBD_ALLOC(cobd->cache_name, LUSTRE_CFG_BUFLEN(lcfg, 2)); if (!cobd->cache_name) GOTO(put_names, rc = -ENOMEM); - memcpy(cobd->cache_name, lcfg->lcfg_inlbuf2, - lcfg->lcfg_inllen2); + memcpy(cobd->cache_name, lustre_cfg_string(lcfg, 2), + LUSTRE_CFG_BUFLEN(lcfg, 2)); EXIT; put_names: if (rc) { - OBD_FREE(cobd->master_name, lcfg->lcfg_inllen1); + OBD_FREE(cobd->master_name, LUSTRE_CFG_BUFLEN(lcfg, 1)); cobd->master_name = NULL; } return rc; diff --git a/lustre/include/linux/lustre_cfg.h b/lustre/include/linux/lustre_cfg.h index 75757b8..ffa86c05 100644 --- a/lustre/include/linux/lustre_cfg.h +++ b/lustre/include/linux/lustre_cfg.h @@ -23,7 +23,11 @@ #ifndef _LUSTRE_CFG_H #define _LUSTRE_CFG_H -#define LUSTRE_CFG_VERSION 0x00010001 +#define LUSTRE_CFG_VERSION 0x1cf60001 +#define LUSTRE_CFG_MAX_BUFCOUNT 8 + +#define LCFG_HDR_SIZE(count) \ + size_round(offsetof (struct lustre_cfg, lcfg_buflens[(count)])) enum lcfg_command_type { LCFG_ATTACH = 0x00cf001, @@ -43,6 +47,12 @@ enum lcfg_command_type { LCFG_SET_SECURITY = 0x00cf00f, }; +struct lustre_cfg_bufs { + void *lcfg_buf[LUSTRE_CFG_MAX_BUFCOUNT]; + uint32_t lcfg_buflen[LUSTRE_CFG_MAX_BUFCOUNT]; + uint32_t lcfg_bufcount; +}; + struct lustre_cfg { uint32_t lcfg_version; uint32_t lcfg_command; @@ -52,223 +62,171 @@ struct lustre_cfg { uint64_t lcfg_nid; uint32_t lcfg_nal; - /* inline buffers for various arguments */ - uint32_t lcfg_dev_namelen; - char *lcfg_dev_name; - uint32_t lcfg_inllen1; - char *lcfg_inlbuf1; - uint32_t lcfg_inllen2; - char *lcfg_inlbuf2; - uint32_t lcfg_inllen3; - char *lcfg_inlbuf3; - uint32_t lcfg_inllen4; - char *lcfg_inlbuf4; - uint32_t lcfg_inllen5; - char *lcfg_inlbuf5; - uint32_t lcfg_inllen6; - char *lcfg_inlbuf6; - - - char lcfg_bulk[0]; + uint32_t lcfg_bufcount; + uint32_t lcfg_buflens[0]; }; -#define LCFG_INIT(l, cmd, name) \ -do { \ - memset(&(l), 0, sizeof(l)); \ - (l).lcfg_version = LUSTRE_CFG_VERSION; \ - (l).lcfg_command = (cmd); \ - if (name) { \ - (l).lcfg_dev_namelen = strlen(name) + 1; \ - (l).lcfg_dev_name = name; \ - } \ - \ -} while (0) - -#ifndef __KERNEL__ -static inline int lustre_cfg_packlen(struct lustre_cfg *lcfg) +#define LUSTRE_CFG_BUFLEN(lcfg, idx) \ + ((lcfg)->lcfg_bufcount <= (idx) \ + ? 0 \ + : (lcfg)->lcfg_buflens[(idx)]) + +static inline void lustre_cfg_bufs_set(struct lustre_cfg_bufs *bufs, + uint32_t index, + void *buf, + uint32_t buflen) { - int len = size_round(sizeof(struct lustre_cfg)); - len += size_round(lcfg->lcfg_dev_namelen); - len += size_round(lcfg->lcfg_inllen1); - len += size_round(lcfg->lcfg_inllen2); - len += size_round(lcfg->lcfg_inllen3); - len += size_round(lcfg->lcfg_inllen4); - len += size_round(lcfg->lcfg_inllen5); - len += size_round(lcfg->lcfg_inllen6); - return size_round(len); + if (index >= LUSTRE_CFG_MAX_BUFCOUNT) + return; + if (bufs == NULL) + return; + + if (bufs->lcfg_bufcount <= index) + bufs->lcfg_bufcount = index + 1; + + bufs->lcfg_buf[index] = buf; + bufs->lcfg_buflen[index] = buflen; } -static inline int lustre_cfg_pack(struct lustre_cfg *data, char **pbuf, - int max, int *plen) +static inline void lustre_cfg_bufs_set_string(struct lustre_cfg_bufs *bufs, + uint32_t index, + char *str) { - char *ptr; - struct lustre_cfg *overlay; - int len; + lustre_cfg_bufs_set(bufs, index, str, str ? strlen(str) + 1 : 0); +} - len = lustre_cfg_packlen(data); +static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs, char *name) +{ + memset((bufs), 0, sizeof(*bufs)); + if (name) + lustre_cfg_bufs_set_string(bufs, 0, name); +} - data->lcfg_version = LUSTRE_CFG_VERSION; +static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, int index) +{ + int i; + int offset; + int bufcount; + LASSERT (lcfg != NULL); + LASSERT (index >= 0); + + bufcount = lcfg->lcfg_bufcount; + if (index >= bufcount) + return NULL; + + offset = LCFG_HDR_SIZE(lcfg->lcfg_bufcount); + for (i = 0; i < index; i++) + offset += size_round(lcfg->lcfg_buflens[i]); + return (char *)lcfg + offset; +} - if (*pbuf && len > max) - return 1; - if (*pbuf == NULL) { - *pbuf = malloc(len); +static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs, + struct lustre_cfg *lcfg) +{ + int i; + bufs->lcfg_bufcount = lcfg->lcfg_bufcount; + for (i = 0; i < bufs->lcfg_bufcount; i++) { + bufs->lcfg_buflen[i] = lcfg->lcfg_buflens[i]; + bufs->lcfg_buf[i] = lustre_cfg_buf(lcfg, i); } - if (!*pbuf) - return 1; - overlay = (struct lustre_cfg *)*pbuf; - memcpy(*pbuf, data, sizeof(*data)); - - ptr = overlay->lcfg_bulk; - if (data->lcfg_dev_name) - LOGL(data->lcfg_dev_name, data->lcfg_dev_namelen, ptr); - if (data->lcfg_inlbuf1) - LOGL(data->lcfg_inlbuf1, data->lcfg_inllen1, ptr); - if (data->lcfg_inlbuf2) - LOGL(data->lcfg_inlbuf2, data->lcfg_inllen2, ptr); - if (data->lcfg_inlbuf3) - LOGL(data->lcfg_inlbuf3, data->lcfg_inllen3, ptr); - if (data->lcfg_inlbuf4) - LOGL(data->lcfg_inlbuf4, data->lcfg_inllen4, ptr); - if (data->lcfg_inlbuf5) - LOGL(data->lcfg_inlbuf5, data->lcfg_inllen5, ptr); - if (data->lcfg_inlbuf6) - LOGL(data->lcfg_inlbuf6, data->lcfg_inllen6, ptr); - - *plen = len; - - return 0; } -static inline int lustre_cfg_unpack(struct lustre_cfg *data, char *pbuf, - int max) +static inline char *lustre_cfg_string(struct lustre_cfg *lcfg, int index) { - char *ptr; - struct lustre_cfg *overlay; - - if (!pbuf) - return 1; - overlay = (struct lustre_cfg *)pbuf; - - /* Preserve the caller's buffer pointers */ - overlay->lcfg_dev_name = data->lcfg_dev_name; - overlay->lcfg_inlbuf1 = data->lcfg_inlbuf1; - overlay->lcfg_inlbuf2 = data->lcfg_inlbuf2; - overlay->lcfg_inlbuf3 = data->lcfg_inlbuf3; - overlay->lcfg_inlbuf4 = data->lcfg_inlbuf4; - overlay->lcfg_inlbuf5 = data->lcfg_inlbuf5; - overlay->lcfg_inlbuf6 = data->lcfg_inlbuf6; - - memcpy(data, pbuf, sizeof(*data)); - - ptr = overlay->lcfg_bulk; - if (data->lcfg_dev_name) - LOGU(data->lcfg_dev_name, data->lcfg_dev_namelen, ptr); - if (data->lcfg_inlbuf1) - LOGU(data->lcfg_inlbuf1, data->lcfg_inllen1, ptr); - if (data->lcfg_inlbuf2) - LOGU(data->lcfg_inlbuf2, data->lcfg_inllen2, ptr); - if (data->lcfg_inlbuf3) - LOGU(data->lcfg_inlbuf3, data->lcfg_inllen3, ptr); - if (data->lcfg_inlbuf4) - LOGU(data->lcfg_inlbuf4, data->lcfg_inllen4, ptr); - if (data->lcfg_inlbuf5) - LOGU(data->lcfg_inlbuf5, data->lcfg_inllen5, ptr); - if (data->lcfg_inlbuf6) - LOGU(data->lcfg_inlbuf6, data->lcfg_inllen6, ptr); - - return 0; -} -#endif + char *s; -#include + if (!lcfg->lcfg_buflens[index]) + return NULL; + + s = lustre_cfg_buf(lcfg, index); + if (!s) + return NULL; -static inline int lustre_cfg_getdata(char **buf, int len, void *arg, int kernel) + /* make sure it's NULL terminated, even if this kills a char + * of data + */ + s[lcfg->lcfg_buflens[index] - 1] = '\0'; + return s; +} + +static inline int lustre_cfg_len(uint32_t bufcount, uint32_t *buflens) { - struct lustre_cfg *lcfg; - int err; - int offset = 0; + int i; + int len; ENTRY; - if (len > OBD_MAX_IOCTL_BUFFER) { - CERROR("User buffer len %d exceeds %d max buffer\n", - len, OBD_MAX_IOCTL_BUFFER); - return -EINVAL; - } - if (len < sizeof(struct lustre_cfg)) { - CERROR("OBD: user buffer too small for lustre_cfg\n"); - return -EINVAL; - } + len = LCFG_HDR_SIZE(bufcount); + for (i = 0; i < bufcount; i++) + len += size_round(buflens[i]); - /* XXX allocate this more intelligently, using kmalloc when - * appropriate */ - OBD_ALLOC(*buf, len); - if (*buf == NULL) { - CERROR("Cannot allocate control buffer of len %d\n", len); - RETURN(-EINVAL); - } + RETURN(size_round(len)); +} - if (kernel) { - memcpy(*buf, (void *)arg, len); - } else { - err = copy_from_user(*buf, (void *)arg, len); - if (err) - RETURN(err); - } - lcfg = (struct lustre_cfg *)*buf; +#include - if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) { - CERROR("Version mismatch kernel: %#x application: %#x\n", - LUSTRE_CFG_VERSION, lcfg->lcfg_version); - return -EINVAL; - } +static inline struct lustre_cfg *lustre_cfg_new(int cmd, + struct lustre_cfg_bufs *bufs) +{ + struct lustre_cfg *lcfg; + char *ptr; + int i; + ENTRY; - if (lcfg->lcfg_dev_name) { - lcfg->lcfg_dev_name = &lcfg->lcfg_bulk[0]; - offset += size_round(lcfg->lcfg_dev_namelen); - } + OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, + bufs->lcfg_buflen)); + if (!lcfg) + RETURN(lcfg); - if (lcfg->lcfg_inllen1) { - lcfg->lcfg_inlbuf1 = &lcfg->lcfg_bulk[0] + offset; - offset += size_round(lcfg->lcfg_inllen1); - } + lcfg->lcfg_version = LUSTRE_CFG_VERSION; + lcfg->lcfg_command = cmd; + lcfg->lcfg_bufcount = bufs->lcfg_bufcount; - if (lcfg->lcfg_inllen2) { - lcfg->lcfg_inlbuf2 = &lcfg->lcfg_bulk[0] + offset; - offset += size_round(lcfg->lcfg_inllen2); + ptr = (char *)lcfg + LCFG_HDR_SIZE(lcfg->lcfg_bufcount); + for (i = 0; i < lcfg->lcfg_bufcount; i++) { + lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i]; + LOGL((char *)bufs->lcfg_buf[i], bufs->lcfg_buflen[i], ptr); } + RETURN(lcfg); +} - if (lcfg->lcfg_inllen3) { - lcfg->lcfg_inlbuf3 = &lcfg->lcfg_bulk[0] + offset; - offset += size_round(lcfg->lcfg_inllen3); - } +static inline void lustre_cfg_free(struct lustre_cfg *lcfg) +{ + int len; - if (lcfg->lcfg_inllen4) { - lcfg->lcfg_inlbuf4 = &lcfg->lcfg_bulk[0] + offset; - offset += size_round(lcfg->lcfg_inllen4); - } + len = lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens); - if (lcfg->lcfg_inllen5) { - lcfg->lcfg_inlbuf5 = &lcfg->lcfg_bulk[0] + offset; - offset += size_round(lcfg->lcfg_inllen5); - } - - if (lcfg->lcfg_inllen6) - lcfg->lcfg_inlbuf6 = &lcfg->lcfg_bulk[0] + offset; - + OBD_FREE(lcfg, len); EXIT; - return 0; + return; } -static inline void lustre_cfg_freedata(char *buf, int len) +static inline int lustre_cfg_sanity_check(void *buf, int len) { + struct lustre_cfg *lcfg = (struct lustre_cfg *)buf; ENTRY; + if (!lcfg) + RETURN(-EINVAL); - OBD_FREE(buf, len); - EXIT; - return; + /* check that the first bits of the struct are valid */ + if (len < LCFG_HDR_SIZE(0)) + RETURN(-EINVAL); + + if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) + RETURN(-EINVAL); + if (lcfg->lcfg_bufcount >= LUSTRE_CFG_MAX_BUFCOUNT) + RETURN(-EINVAL); + + /* check that the buflens are valid */ + if (len < LCFG_HDR_SIZE(lcfg->lcfg_bufcount)) + RETURN(-EINVAL); + + /* make sure all the pointers point inside the data */ + if (len < lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens)) + RETURN(-EINVAL); + + RETURN(0); } #define NOBODY_UID 99 diff --git a/lustre/include/linux/lustre_idl.h b/lustre/include/linux/lustre_idl.h index 1125ccf..0bd16ce 100644 --- a/lustre/include/linux/lustre_idl.h +++ b/lustre/include/linux/lustre_idl.h @@ -1160,6 +1160,9 @@ extern void lustre_swab_llogd_body (struct llogd_body *d); extern void lustre_swab_llog_hdr (struct llog_log_hdr *h); extern void lustre_swab_llogd_conn_body (struct llogd_conn_body *d); +struct lustre_cfg; +extern void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg); + static inline struct lustre_id *obdo_id(struct obdo *oa) { void *raw_id = oa->o_inline + sizeof(struct lustre_handle) + diff --git a/lustre/include/linux/obd_support.h b/lustre/include/linux/obd_support.h index 6653615..0d2d445 100644 --- a/lustre/include/linux/obd_support.h +++ b/lustre/include/linux/obd_support.h @@ -443,7 +443,12 @@ do { # define OBD_GFP_MASK GFP_NOFS #endif +#ifdef __KERNEL__ #define OBD_ALLOC(ptr, size) OBD_ALLOC_GFP(ptr, size, OBD_GFP_MASK) +#else +#define OBD_ALLOC(ptr, size) (ptr = malloc(size)) +#endif + #define OBD_ALLOC_WAIT(ptr, size) OBD_ALLOC_GFP(ptr, size, GFP_KERNEL) #ifdef __arch_um__ @@ -482,6 +487,7 @@ do { #define POISON_PAGE(page, val) do { } while (0) #endif +#ifdef __KERNEL__ #define OBD_FREE(ptr, size) \ do { \ LASSERT(ptr); \ @@ -493,6 +499,9 @@ do { kfree(ptr); \ (ptr) = (void *)0xdeadbeef; \ } while (0) +#else +#define OBD_FREE(ptr, size) ((void)(size), free((ptr))) +#endif #ifdef __arch_um__ # define OBD_VFREE(ptr, size) OBD_FREE(ptr, size) diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 9244c92..dcedbbb 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -205,30 +205,32 @@ int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf) RETURN(-EINVAL); } - if (lcfg->lcfg_inllen1 < 1) { + + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("requires a TARGET UUID\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen1 > 37) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) { CERROR("client UUID must be less than 38 characters\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) { CERROR("setup requires a SERVER UUID\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 > 37) { + if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) { CERROR("target UUID must be less than 38 characters\n"); RETURN(-EINVAL); } sema_init(&cli->cl_sem, 1); cli->cl_conn_count = 0; - memcpy(server_uuid.uuid, lcfg->lcfg_inlbuf2, - min_t(unsigned int, lcfg->lcfg_inllen2, sizeof(server_uuid))); + memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2), + min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2), + sizeof(server_uuid))); cli->cl_dirty = 0; cli->cl_avail_grant = 0; @@ -277,8 +279,8 @@ int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf) imp->imp_generation = 0; imp->imp_initial_recov = 1; INIT_LIST_HEAD(&imp->imp_pinger_chain); - memcpy(imp->imp_target_uuid.uuid, lcfg->lcfg_inlbuf1, - lcfg->lcfg_inllen1); + memcpy(imp->imp_target_uuid.uuid, lustre_cfg_buf(lcfg, 1), + LUSTRE_CFG_BUFLEN(lcfg, 1)); class_import_put(imp); rc = client_import_add_conn(imp, &server_uuid, 1); @@ -292,17 +294,17 @@ int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf) cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie); cli->cl_sandev = to_kdev_t(0); - if (lcfg->lcfg_inllen3 != 0) { - if (!strcmp(lcfg->lcfg_inlbuf3, "inactive")) { + if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) { + if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) { CDEBUG(D_HA, "marking %s %s->%s as inactive\n", name, obddev->obd_name, imp->imp_target_uuid.uuid); imp->imp_invalid = 1; - if (lcfg->lcfg_inllen4 != 0) - mgmt_name = lcfg->lcfg_inlbuf4; + if (LUSTRE_CFG_BUFLEN(lcfg, 4) > 0) + mgmt_name = lustre_cfg_string(lcfg, 4); } else { - mgmt_name = lcfg->lcfg_inlbuf3; + mgmt_name = lustre_cfg_string(lcfg, 3); } } diff --git a/lustre/liblustre/llite_lib.c b/lustre/liblustre/llite_lib.c index 44eb936..c4b00a5 100644 --- a/lustre/liblustre/llite_lib.c +++ b/lustre/liblustre/llite_lib.c @@ -87,7 +87,9 @@ static int lllib_init(void) int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; + char *peer = "MDS_PEER_UUID"; struct obd_device *obd; struct lustre_handle mdc_conn = {0, }; @@ -117,30 +119,31 @@ int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov) CERROR("Can't parse NAL %s\n", nal_name); RETURN(-EINVAL); } - LCFG_INIT(lcfg, LCFG_ADD_UUID, name); - lcfg.lcfg_nid = nid; - lcfg.lcfg_inllen1 = strlen(peer) + 1; - lcfg.lcfg_inlbuf1 = peer; - lcfg.lcfg_nal = nal; + lustre_cfg_bufs_reset(&bufs, NULL); + lustre_cfg_bufs_set_string(&bufs, 1, peer); + lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs); + lcfg->lcfg_nid = nid; + lcfg->lcfg_nal = nal; err = class_process_config(&lcfg); + lustre_cfg_free(lcfg); if (err < 0) GOTO(out, err); - LCFG_INIT(lcfg, LCFG_ATTACH, name); - lcfg.lcfg_inlbuf1 = "mdc"; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = mdc_uuid.uuid; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1; + lustre_cfg_bufs_reset(&bufs, name); + lustre_cfg_bufs_set_string(&bufs, 1, LUSTRE_MDC_NAME); + lustre_cfg_bufs_set_string(&bufs, 2, mdc_uuid.uuid); + lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); err = class_process_config(&lcfg); + lustre_cfg_free(lcfg); if (err < 0) GOTO(out_del_uuid, err); - LCFG_INIT(lcfg, LCFG_SETUP, name); - lcfg.lcfg_inlbuf1 = g_zconf_mdsname; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = peer; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1; + lustre_cfg_bufs_reset(&bufs, name); + lustre_cfg_bufs_set_string(&bufs, 1, g_zconf_mdsname); + lustre_cfg_bufs_set_string(&bufs, 2, peer); + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); err = class_process_config(&lcfg); + lustre_cfg_free(lcfg); if (err < 0) GOTO(out_detach, err); @@ -170,23 +173,27 @@ int liblustre_process_log(struct config_llog_instance *cfg, int allow_recov) err = obd_disconnect(exp, 0); out_cleanup: - LCFG_INIT(lcfg, LCFG_CLEANUP, name); + lustre_cfg_bufs_reset(&bufs, name); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); err = class_process_config(&lcfg); + lustre_cfg_free(lcfg); if (err < 0) GOTO(out, err); out_detach: - LCFG_INIT(lcfg, LCFG_DETACH, name); + lustre_cfg_bufs_reset(&bufs, name); + lcfg = lustre_cfg_new(LCFG_DETACH, &bufs); err = class_process_config(&lcfg); + lustre_cfg_free(lcfg); if (err < 0) GOTO(out, err); out_del_uuid: - LCFG_INIT(lcfg, LCFG_DEL_UUID, name); - lcfg.lcfg_inllen1 = strlen(peer) + 1; - lcfg.lcfg_inlbuf1 = peer; - err = class_process_config(&lcfg); - + lustre_cfg_bufs_reset(&bufs, name); + lustre_cfg_bufs_set_string(&bufs, 1, peer); + lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); out: if (rc == 0) rc = err; diff --git a/lustre/liblustre/super.c b/lustre/liblustre/super.c index 2bd60ac..dec96c3 100644 --- a/lustre/liblustre/super.c +++ b/lustre/liblustre/super.c @@ -91,7 +91,8 @@ static void llu_fsop_gone(struct filesys *fs) { struct llu_sb_info *sbi = (struct llu_sb_info *)fs->fs_private; struct obd_device *obd = class_exp2obd(sbi->ll_md_exp); - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; int next = 0; ENTRY; @@ -102,15 +103,17 @@ static void llu_fsop_gone(struct filesys *fs) while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL) { int err; - - LCFG_INIT(lcfg, LCFG_CLEANUP, obd->obd_name); + + lustre_cfg_bufs_reset(&bufs, obd->obd_name); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); err = class_process_config(&lcfg); if (err) { CERROR("cleanup failed: %s\n", obd->obd_name); } - - LCFG_INIT(lcfg, LCFG_DETACH, obd->obd_name); + + lcfg->lcfg_command = LCFG_DETACH; err = class_process_config(&lcfg); + lustre_cfg_free(lcfg); if (err) { CERROR("detach failed: %s\n", obd->obd_name); } diff --git a/lustre/liblustre/tests/echo_test.c b/lustre/liblustre/tests/echo_test.c index 3ec12e01..a77e951 100644 --- a/lustre/liblustre/tests/echo_test.c +++ b/lustre/liblustre/tests/echo_test.c @@ -95,7 +95,8 @@ static char *echo_dev_name = "ECHO_CLIENT_DEV_NAME"; static int connect_echo_client(void) { - struct lustre_cfg lcfg; + struct lustre_cfg *lcfg; + struct lustre_cfg_bufs bufs; ptl_nid_t nid; char *peer = "ECHO_PEER_NID"; class_uuid_t osc_uuid, echo_uuid; @@ -117,68 +118,65 @@ static int connect_echo_client(void) CERROR("Can't parse NAL tcp\n"); RETURN(-EINVAL); } - - /* add uuid */ - LCFG_INIT(lcfg, LCFG_ADD_UUID, NULL); - lcfg.lcfg_nid = nid; - lcfg.lcfg_inllen1 = strlen(peer) + 1; - lcfg.lcfg_inlbuf1 = peer; - lcfg.lcfg_nal = nal; - err = class_process_config(&lcfg); + /* add uuid */ + lustre_cfg_bufs_reset(&bufs, NULL); + lustre_cfg_bufs_set_string(&bufs, 1, peer); + lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs); + lcfg->lcfg_nid = nid; + lcfg->lcfg_nal = nal; + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) { - CERROR("failed add_uuid\n"); + CERROR("failed add_uuid\n"); RETURN(-EINVAL); - } - - /* attach osc */ - LCFG_INIT(lcfg, LCFG_ATTACH, osc_dev_name); - lcfg.lcfg_inlbuf1 = "osc"; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = osc_uuid_str.uuid; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1; - err = class_process_config(&lcfg); + } + lustre_cfg_bufs_reset(&bufs, LUSTRE_OSC_NAME); + lustre_cfg_bufs_set_string(&bufs, 2, osc_uuid_str.uuid); + lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) { - CERROR("failed attach osc\n"); + CERROR("failed attach osc\n"); RETURN(-EINVAL); - } + } - /* setup osc */ - LCFG_INIT(lcfg, LCFG_SETUP, osc_dev_name); - lcfg.lcfg_inlbuf1 = echo_server_ostname; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = peer; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1; - err = class_process_config(&lcfg); + /* setup osc */ + lustre_cfg_bufs_reset(&bufs, osc_dev_name); + lustre_cfg_bufs_set_string(&bufs, 1, echo_server_ostname); + lustre_cfg_bufs_set_string(&bufs, 2, peer); + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) { - CERROR("failed setup osc\n"); + CERROR("failed setup osc\n"); RETURN(-EINVAL); - } + } - /* attach echo_client */ - LCFG_INIT(lcfg, LCFG_ATTACH, echo_dev_name); - lcfg.lcfg_inlbuf1 = "echo_client"; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = echo_uuid_str.uuid; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1; - err = class_process_config(&lcfg); + /* attach echo_client */ + lustre_cfg_bufs_reset(&bufs, echo_dev_name); + lustre_cfg_bufs_set_string(&bufs, 1, "echo_client"); + lustre_cfg_bufs_set_string(&bufs, 2, echo_uuid_str.uuid); + lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) { - CERROR("failed attach echo_client\n"); + CERROR("failed attach echo_client\n"); RETURN(-EINVAL); - } + } - /* setup echo_client */ - LCFG_INIT(lcfg, LCFG_SETUP, echo_dev_name); - lcfg.lcfg_inlbuf1 = osc_dev_name; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = NULL; - lcfg.lcfg_inllen2 = 0; - err = class_process_config(&lcfg); + /* setup echo_client */ + lustre_cfg_bufs_reset(&bufs, echo_dev_name); + lustre_cfg_bufs_set_string(&bufs, 1, osc_dev_name); + lustre_cfg_bufs_set_string(&bufs, 2, NULL); + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) { - CERROR("failed setup echo_client\n"); + CERROR("failed setup echo_client\n"); RETURN(-EINVAL); - } + } - RETURN(0); + RETURN(0); } static int disconnect_echo_client(void) @@ -187,39 +185,45 @@ static int disconnect_echo_client(void) int err; ENTRY; - /* cleanup echo_client */ - LCFG_INIT(lcfg, LCFG_CLEANUP, echo_dev_name); - err = class_process_config(&lcfg); + /* cleanup echo_client */ + lustre_cfg_bufs_reset(&bufs, echo_dev_name); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); + err = class_process_config(lcfg); if (err < 0) { - CERROR("failed cleanup echo_client\n"); + lustre_cfg_free(lcfg); + CERROR("failed cleanup echo_client\n"); RETURN(-EINVAL); - } + } - /* detach echo_client */ - LCFG_INIT(lcfg, LCFG_DETACH, echo_dev_name); - err = class_process_config(&lcfg); + /* detach echo_client */ + lcfg->lcfg_command = LCFG_DETACH; + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) { - CERROR("failed detach echo_client\n"); + CERROR("failed detach echo_client\n"); RETURN(-EINVAL); - } + } - /* cleanup osc */ - LCFG_INIT(lcfg, LCFG_CLEANUP, osc_dev_name); - err = class_process_config(&lcfg); + /* cleanup osc */ + lustre_cfg_bufs_reset(&bufs, osc_dev_name); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); + err = class_process_config(lcfg); if (err < 0) { - CERROR("failed cleanup osc device\n"); + lustre_cfg_free(lcfg); + CERROR("failed cleanup osc device\n"); RETURN(-EINVAL); - } + } - /* detach osc */ - LCFG_INIT(lcfg, LCFG_DETACH, osc_dev_name); - err = class_process_config(&lcfg); + /* detach osc */ + lcfg->lcfg_command = LCFG_DETACH; + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) { - CERROR("failed detach osc device\n"); + CERROR("failed detach osc device\n"); RETURN(-EINVAL); - } + } - RETURN(0); + RETURN(0); } static void usage(const char *s) diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 6801508..f0190ac 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -517,7 +517,8 @@ out: static int lustre_process_log(struct lustre_mount_data *lmd, char *profile, struct config_llog_instance *cfg, int allow_recov) { - struct lustre_cfg lcfg; + struct lustre_cfg *lcfg = NULL; + struct lustre_cfg_bufs bufs; struct portals_cfg pcfg; char *peer = "MDS_PEER_UUID"; struct obd_device *obd; @@ -559,33 +560,38 @@ static int lustre_process_log(struct lustre_mount_data *lmd, char *profile, if (rc < 0) GOTO(out, rc); } + lustre_cfg_bufs_reset(&bufs, name); + lustre_cfg_bufs_set_string(&bufs, 1, peer); - LCFG_INIT(lcfg, LCFG_ADD_UUID, name); - lcfg.lcfg_nid = lmd->lmd_server_nid; - lcfg.lcfg_inllen1 = strlen(peer) + 1; - lcfg.lcfg_inlbuf1 = peer; - lcfg.lcfg_nal = lmd->lmd_nal; - rc = class_process_config(&lcfg); - if (rc < 0) - GOTO(out_del_conn, rc); - - LCFG_INIT(lcfg, LCFG_ATTACH, name); - lcfg.lcfg_inlbuf1 = "mdc"; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = lmv_uuid.uuid; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1; - err = class_process_config(&lcfg); - if (rc < 0) - GOTO(out_del_uuid, rc); - - LCFG_INIT(lcfg, LCFG_SETUP, name); - lcfg.lcfg_inlbuf1 = lmd->lmd_mds; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - lcfg.lcfg_inlbuf2 = peer; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1; - rc = class_process_config(&lcfg); - if (rc < 0) - GOTO(out_detach, rc); + lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs); + lcfg->lcfg_nal = lmd->lmd_nal; + lcfg->lcfg_nid = lmd->lmd_server_nid; + LASSERT(lcfg->lcfg_nal); + LASSERT(lcfg->lcfg_nid); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); + if (err < 0) + GOTO(out_del_conn, err); + + lustre_cfg_bufs_reset(&bufs, name); + lustre_cfg_bufs_set_string(&bufs, 1, LUSTRE_MDC_NAME); + lustre_cfg_bufs_set_string(&bufs, 2, lmv_uuid.uuid); + + lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); + if (err < 0) + GOTO(out_del_uuid, err); + + lustre_cfg_bufs_reset(&bufs, name); + lustre_cfg_bufs_set_string(&bufs, 1, lmd->lmd_mds); + lustre_cfg_bufs_set_string(&bufs, 2, peer); + + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); + if (err < 0) + GOTO(out_detach, err); obd = class_name2obd(name); if (obd == NULL) @@ -620,22 +626,26 @@ static int lustre_process_log(struct lustre_mount_data *lmd, char *profile, EXIT; out_cleanup: - LCFG_INIT(lcfg, LCFG_CLEANUP, name); - err = class_process_config(&lcfg); + lustre_cfg_bufs_reset(&bufs, name); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) GOTO(out, err); - out_detach: - LCFG_INIT(lcfg, LCFG_DETACH, name); - err = class_process_config(&lcfg); + lustre_cfg_bufs_reset(&bufs, name); + lcfg = lustre_cfg_new(LCFG_DETACH, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err < 0) GOTO(out, err); out_del_uuid: - LCFG_INIT(lcfg, LCFG_DEL_UUID, name); - lcfg.lcfg_inllen1 = strlen(peer) + 1; - lcfg.lcfg_inlbuf1 = peer; - err = class_process_config(&lcfg); + lustre_cfg_bufs_reset(&bufs, name); + lustre_cfg_bufs_set_string(&bufs, 1, peer); + lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs); + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); out_del_conn: if (lmd->lmd_nal == SOCKNAL || @@ -664,7 +674,8 @@ out: static void lustre_manual_cleanup(struct ll_sb_info *sbi) { - struct lustre_cfg lcfg; + struct lustre_cfg *lcfg; + struct lustre_cfg_bufs bufs; struct obd_device *obd; int next = 0; @@ -672,15 +683,17 @@ static void lustre_manual_cleanup(struct ll_sb_info *sbi) { int err; - LCFG_INIT(lcfg, LCFG_CLEANUP, obd->obd_name); - err = class_process_config(&lcfg); + lustre_cfg_bufs_reset(&bufs, obd->obd_name); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); + err = class_process_config(lcfg); if (err) { CERROR("cleanup failed: %s\n", obd->obd_name); //continue; } - - LCFG_INIT(lcfg, LCFG_DETACH, obd->obd_name); - err = class_process_config(&lcfg); + + lcfg->lcfg_command = LCFG_DETACH; + err = class_process_config(lcfg); + lustre_cfg_free(lcfg); if (err) { CERROR("detach failed: %s\n", obd->obd_name); //continue; @@ -984,14 +997,12 @@ void ll_clear_inode(struct inode *inode) LASSERT(!lli->lli_open_fd_write_count); LASSERT(!lli->lli_open_fd_read_count); LASSERT(!lli->lli_open_fd_exec_count); - if (lli->lli_mds_write_och) ll_md_real_close(sbi->ll_md_exp, inode, FMODE_WRITE); if (lli->lli_mds_exec_och) ll_md_real_close(sbi->ll_md_exp, inode, FMODE_EXEC); if (lli->lli_mds_read_och) ll_md_real_close(sbi->ll_md_exp, inode, FMODE_READ); - if (lli->lli_smd) obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd, null_if_equal, inode); diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 6c4b487..1ae1660 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -552,27 +552,27 @@ static int lmv_setup(struct obd_device *obd, obd_count len, void *buf) struct lmv_obd *lmv = &obd->u.lmv; ENTRY; - if (lcfg->lcfg_inllen1 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("LMV setup requires a descriptor\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) { CERROR("LMV setup requires an MDT UUID list\n"); RETURN(-EINVAL); } - desc = (struct lmv_desc *)lcfg->lcfg_inlbuf1; - if (sizeof(*desc) > lcfg->lcfg_inllen1) { + desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1); + if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) { CERROR("descriptor size wrong: %d > %d\n", - (int)sizeof(*desc), lcfg->lcfg_inllen1); + (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1)); RETURN(-EINVAL); } - uuids = (struct obd_uuid *)lcfg->lcfg_inlbuf2; - if (sizeof(*uuids) * desc->ld_tgt_count != lcfg->lcfg_inllen2) { + uuids = (struct obd_uuid *)lustre_cfg_buf(lcfg, 2); + if (sizeof(*uuids) * desc->ld_tgt_count != LUSTRE_CFG_BUFLEN(lcfg, 2)) { CERROR("UUID array size wrong: %u * %u != %u\n", - sizeof(*uuids), desc->ld_tgt_count, lcfg->lcfg_inllen2); + sizeof(*uuids), desc->ld_tgt_count, LUSTRE_CFG_BUFLEN(lcfg, 2)); RETURN(-EINVAL); } diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index d2b0552..34c3257 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -435,15 +435,15 @@ static int lov_setup(struct obd_device *obd, obd_count len, void *buf) int count; ENTRY; - if (lcfg->lcfg_inllen1 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("LOV setup requires a descriptor\n"); RETURN(-EINVAL); } - desc = (struct lov_desc *)lcfg->lcfg_inlbuf1; - if (sizeof(*desc) > lcfg->lcfg_inllen1) { + desc = (struct lov_desc *)lustre_cfg_string(lcfg, 1); + if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) { CERROR("descriptor size wrong: %d > %d\n", - (int)sizeof(*desc), lcfg->lcfg_inllen1); + (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1)); RETURN(-EINVAL); } @@ -626,14 +626,14 @@ static int lov_process_config(struct obd_device *obd, obd_count len, void *buf) switch(cmd = lcfg->lcfg_command) { case LCFG_LOV_ADD_OBD: case LCFG_LOV_DEL_OBD: { - if (lcfg->lcfg_inllen1 > sizeof(obd_uuid.uuid)) + if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) GOTO(out, rc = -EINVAL); - obd_str2uuid(&obd_uuid, lcfg->lcfg_inlbuf1); + obd_str2uuid(&obd_uuid, lustre_cfg_string(lcfg, 1)); - if (sscanf(lcfg->lcfg_inlbuf2, "%d", &index) != 1) + if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1) GOTO(out, rc = -EINVAL); - if (sscanf(lcfg->lcfg_inlbuf3, "%d", &gen) != 1) + if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1) GOTO(out, rc = -EINVAL); if (cmd == LCFG_LOV_ADD_OBD) rc = lov_add_obd(obd, &obd_uuid, index, gen); diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index bcd44c4..c0c9279 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -3185,11 +3185,13 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf) int rc = 0; ENTRY; + if (lcfg->lcfg_bufcount < 3) + RETURN(rc = -EINVAL); - if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2) + if (LUSTRE_CFG_BUFLEN(lcfg, 1) == 0 || LUSTRE_CFG_BUFLEN(lcfg, 2) == 0) RETURN(rc = -EINVAL); - obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2); + obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2)); if (IS_ERR(obd->obd_fsops)) RETURN(rc = PTR_ERR(obd->obd_fsops)); @@ -3207,9 +3209,10 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf) * and the rest of options are passed by mount options. Probably this * should be moved to somewhere else like startup scripts or lconf. */ sprintf(options, "iopen_nopriv"); - if (lcfg->lcfg_inllen4 > 0 && lcfg->lcfg_inlbuf4) + + if (LUSTRE_CFG_BUFLEN(lcfg, 4) > 0 && lustre_cfg_buf(lcfg, 4)) sprintf(options + strlen(options), ",%s", - lcfg->lcfg_inlbuf4); + lustre_cfg_string(lcfg, 4)); /* we have to know mdsnum before touching underlying fs -bzzz */ atomic_set(&mds->mds_open_count, 0); @@ -3217,42 +3220,46 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf) mds->mds_md_connected = 0; mds->mds_md_name = NULL; - if (lcfg->lcfg_inllen5 > 0 && lcfg->lcfg_inlbuf5 && - strncmp(lcfg->lcfg_inlbuf5, "dumb", lcfg->lcfg_inllen5)) { + if (LUSTRE_CFG_BUFLEN(lcfg, 5) > 0 && lustre_cfg_buf(lcfg, 5) && + strncmp(lustre_cfg_string(lcfg, 5), "dumb", LUSTRE_CFG_BUFLEN(lcfg, 5))) { class_uuid_t uuid; CDEBUG(D_OTHER, "MDS: %s is master for %s\n", - obd->obd_name, lcfg->lcfg_inlbuf5); + obd->obd_name, lustre_cfg_buf); generate_random_uuid(uuid); class_uuid_unparse(uuid, &mds->mds_md_uuid); - OBD_ALLOC(mds->mds_md_name, lcfg->lcfg_inllen5); + OBD_ALLOC(mds->mds_md_name, LUSTRE_CFG_BUFLEN(lcfg, 5)); if (mds->mds_md_name == NULL) RETURN(rc = -ENOMEM); - memcpy(mds->mds_md_name, lcfg->lcfg_inlbuf5, - lcfg->lcfg_inllen5); + memcpy(mds->mds_md_name, lustre_cfg_buf(lcfg, 5), + LUSTRE_CFG_BUFLEN(lcfg, 5)); rc = mds_md_connect(obd, mds->mds_md_name); if (rc) { - OBD_FREE(mds->mds_md_name, lcfg->lcfg_inllen5); + OBD_FREE(mds->mds_md_name, LUSTRE_CFG_BUFLEN(lcfg, 5)); GOTO(err_ops, rc); } } mds->mds_obd_type = MDS_MASTER_OBD; - if (lcfg->lcfg_inllen6 > 0 && lcfg->lcfg_inlbuf6 && - strncmp(lcfg->lcfg_inlbuf6, "dumb", lcfg->lcfg_inllen6)) { - if (!memcmp(lcfg->lcfg_inlbuf6, "master", strlen("master"))) { + if (LUSTRE_CFG_BUFLEN(lcfg, 6) > 0 && lustre_cfg_buf(lcfg, 6) && + strncmp(lustre_cfg_string(lcfg, 6), "dumb", + LUSTRE_CFG_BUFLEN(lcfg, 6))) { + if (!memcmp(lustre_cfg_string(lcfg, 6), "master", + strlen("master"))) { mds->mds_obd_type = MDS_MASTER_OBD; - } else if (!memcmp(lcfg->lcfg_inlbuf6, "cache", strlen("cache"))) { + } else if (!memcmp(lustre_cfg_string(lcfg, 6), "cache", + strlen("cache"))) { mds->mds_obd_type = MDS_CACHE_OBD; } } - rc = lvfs_mount_fs(lcfg->lcfg_inlbuf1, lcfg->lcfg_inlbuf2, + rc = lvfs_mount_fs(lustre_cfg_string(lcfg, 1), + lustre_cfg_string(lcfg, 2), options, 0, &lvfs_ctxt); free_page(page); @@ -3266,7 +3273,7 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf) mds->mds_lvfs_ctxt = lvfs_ctxt; ll_clear_rdonly(ll_sbdev(mnt->mnt_sb)); - CDEBUG(D_SUPER, "%s: mnt = %p\n", lcfg->lcfg_inlbuf1, mnt); + CDEBUG(D_SUPER, "%s: mnt = %p\n", lustre_cfg_string(lcfg, 1), mnt); sema_init(&mds->mds_epoch_sem, 1); atomic_set(&mds->mds_real_clients, 0); @@ -3293,30 +3300,34 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf) rc = llog_start_commit_thread(); if (rc < 0) + GOTO(err_fs, rc); - if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 && - strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3)) { + + if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0 && lustre_cfg_buf(lcfg, 3) && + strncmp(lustre_cfg_string(lcfg, 3), "dumb", + LUSTRE_CFG_BUFLEN(lcfg, 3))) { class_uuid_t uuid; generate_random_uuid(uuid); class_uuid_unparse(uuid, &mds->mds_dt_uuid); - OBD_ALLOC(mds->mds_profile, lcfg->lcfg_inllen3); + OBD_ALLOC(mds->mds_profile, LUSTRE_CFG_BUFLEN(lcfg, 3)); if (mds->mds_profile == NULL) GOTO(err_fs, rc = -ENOMEM); - memcpy(mds->mds_profile, lcfg->lcfg_inlbuf3, - lcfg->lcfg_inllen3); + strncpy(mds->mds_profile, lustre_cfg_string(lcfg, 3), + LUSTRE_CFG_BUFLEN(lcfg, 3)); } /* * setup root dir and files ID dir if lmv already connected, or there is * not lmv at all. */ - if (mds->mds_md_exp || (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 && - strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3))) - { + if (mds->mds_md_exp || (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0 && + lustre_cfg_buf(lcfg, 3) && + strncmp(lustre_cfg_string(lcfg, 3), "dumb", + LUSTRE_CFG_BUFLEN(lcfg, 3)))) { rc = mds_fs_setup_rootid(obd); if (rc) GOTO(err_fs, rc); @@ -3604,14 +3615,14 @@ static int mds_process_config(struct obd_device *obd, obd_count len, void *buf) switch(lcfg->lcfg_command) { case LCFG_SET_SECURITY: { - if (!lcfg->lcfg_inllen1 || !lcfg->lcfg_inllen2) + if (LUSTRE_CFG_BUFLEN(lcfg, 1) || LUSTRE_CFG_BUFLEN(lcfg, 2)) GOTO(out, rc = -EINVAL); - if (!strcmp(lcfg->lcfg_inlbuf1, "mds_mds_sec")) - rc = set_security(lcfg->lcfg_inlbuf2, + if (!strcmp(lustre_cfg_string(lcfg, 1), "mds_mds_sec")) + rc = set_security(lustre_cfg_string(lcfg, 2), &mds->mds_mds_sec); - else if (!strcmp(lcfg->lcfg_inlbuf1, "mds_ost_sec")) - rc = set_security(lcfg->lcfg_inlbuf2, + else if (!strcmp(lustre_cfg_string(lcfg, 2), "mds_ost_sec")) + rc = set_security(lustre_cfg_string(lcfg, 2), &mds->mds_ost_sec); else { CERROR("Unrecognized key\n"); diff --git a/lustre/obdclass/Makefile.in b/lustre/obdclass/Makefile.in index 66f6eb2..c0f84f1 100644 --- a/lustre/obdclass/Makefile.in +++ b/lustre/obdclass/Makefile.in @@ -1,6 +1,6 @@ MODULES := obdclass llog_test confobd -obdclass-objs := llog_obd.o class_obd.o +obdclass-objs := llog_obd.o class_obd.o llog_swab.o obdclass-objs += debug.o genops.o sysctl.o uuid.o llog_ioctl.o obdclass-objs += lprocfs_status.o lustre_handles.o lustre_peer.o obdclass-objs += statfs_pack.o obdo.o obd_config.o mea.o diff --git a/lustre/obdclass/autoMakefile.am b/lustre/obdclass/autoMakefile.am index d4e3204..4622054 100644 --- a/lustre/obdclass/autoMakefile.am +++ b/lustre/obdclass/autoMakefile.am @@ -3,7 +3,7 @@ if LIBLUSTRE noinst_LIBRARIES = liblustreclass.a liblustreclass_a_SOURCES = class_obd.c debug.c genops.c statfs_pack.c uuid.c liblustreclass_a_SOURCES += lustre_handles.c lustre_peer.c lprocfs_status.c mea.c -liblustreclass_a_SOURCES += obdo.c obd_config.c llog_obd.c #llog_ioctl.c rbtree.c +liblustreclass_a_SOURCES += obdo.c obd_config.c llog_swab.c llog_obd.c #llog_ioctl.c rbtree.c liblustreclass_a_CPPFLAGS = $(LLCPPFLAGS) -DLUSTRE_VERSION=\"32\" -DBUILD_VERSION=\"1\" liblustreclass_a_CFLAGS = $(LLCFLAGS) diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 5876810..b108412 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -194,24 +194,28 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) switch (cmd) { case OBD_IOC_PROCESS_CFG: { - char *buf; struct lustre_cfg *lcfg; if (!data->ioc_plen1 || !data->ioc_pbuf1) { CERROR("No config buffer passed!\n"); GOTO(out, err = -EINVAL); } - err = lustre_cfg_getdata(&buf, data->ioc_plen1, - data->ioc_pbuf1, 0); + + err = lustre_cfg_sanity_check(data->ioc_pbuf1, + data->ioc_plen1); + if (err) + GOTO(out, err); + + OBD_ALLOC(lcfg, data->ioc_plen1); + err = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1); if (err) GOTO(out, err); - lcfg = (struct lustre_cfg* ) buf; err = class_process_config(lcfg); - lustre_cfg_freedata(buf, data->ioc_plen1); + OBD_FREE(lcfg, data->ioc_plen1); GOTO(out, err); } - + case OBD_GET_VERSION: if (!data->ioc_inlbuf1) { CERROR("No buffer passed in ioctl\n"); diff --git a/lustre/obdclass/confobd.c b/lustre/obdclass/confobd.c index d8517b8..6baeb7f 100644 --- a/lustre/obdclass/confobd.c +++ b/lustre/obdclass/confobd.c @@ -152,28 +152,31 @@ static int confobd_setup(struct obd_device *obd, obd_count len, void *buf) int rc = 0; ENTRY; - if (lcfg->lcfg_inllen1 < 1 || !lcfg->lcfg_inlbuf1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 || + lustre_cfg_buf(lcfg, 1) == NULL) { CERROR("CONFOBD setup requires device name\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 < 1 || !lcfg->lcfg_inlbuf2) { + if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1 || + lustre_cfg_buf(lcfg, 2) == NULL) { CERROR("CONFOBD setup requires fstype\n"); RETURN(-EINVAL); } - OBD_ALLOC(name, lcfg->lcfg_inllen1 + 1); + OBD_ALLOC(name, LUSTRE_CFG_BUFLEN(lcfg, 1)); if (!name) { CERROR("No Memory\n"); GOTO(out, rc = -ENOMEM); } - memcpy(name, lcfg->lcfg_inlbuf1, lcfg->lcfg_inllen1); + memcpy(name, lustre_cfg_string(lcfg, 1), LUSTRE_CFG_BUFLEN(lcfg, 1)); - OBD_ALLOC(fstype, lcfg->lcfg_inllen2 + 1); + OBD_ALLOC(fstype, LUSTRE_CFG_BUFLEN(lcfg, 2)); if (!fstype) { CERROR("No Memory\n"); GOTO(out, rc = -ENOMEM); } - memcpy(fstype, lcfg->lcfg_inlbuf2, lcfg->lcfg_inllen2); + memcpy(fstype, lustre_cfg_string(lcfg, 2), + LUSTRE_CFG_BUFLEN(lcfg, 2)); obd->obd_fsops = fsfilt_get_ops(fstype); if (IS_ERR(obd->obd_fsops)) { @@ -181,13 +184,14 @@ static int confobd_setup(struct obd_device *obd, obd_count len, void *buf) GOTO(err_ops, rc = PTR_ERR(obd->obd_fsops)); } - if (lcfg->lcfg_inllen3 >= 1 && lcfg->lcfg_inlbuf3) { - OBD_ALLOC(mountoption, lcfg->lcfg_inllen3 + 1); + if (LUSTRE_CFG_BUFLEN(lcfg, 3) >= 1 && lustre_cfg_buf(lcfg, 3)) { + OBD_ALLOC(mountoption, LUSTRE_CFG_BUFLEN(lcfg, 3)); if (!mountoption) { CERROR("No Memory\n"); GOTO(err_ops, rc = -ENOMEM); } - memcpy(mountoption, lcfg->lcfg_inlbuf3, lcfg->lcfg_inllen3); + memcpy(mountoption, lustre_cfg_string(lcfg, 3), + LUSTRE_CFG_BUFLEN(lcfg, 3)); } rc = lvfs_mount_fs(name, fstype, mountoption, 0, &lvfs_ctxt); if (rc) @@ -210,11 +214,11 @@ out: if (rc && lvfs_ctxt) lvfs_umount_fs(lvfs_ctxt); if (name) - OBD_FREE(name, lcfg->lcfg_inllen1 + 1); + OBD_FREE(name, LUSTRE_CFG_BUFLEN(lcfg, 1)); if (fstype) - OBD_FREE(fstype, lcfg->lcfg_inllen2 + 1); + OBD_FREE(fstype, LUSTRE_CFG_BUFLEN(lcfg, 2)); if (mountoption) - OBD_FREE(mountoption, lcfg->lcfg_inllen3 + 1); + OBD_FREE(mountoption, LUSTRE_CFG_BUFLEN(lcfg, 3)); return rc; err_ops: diff --git a/lustre/obdclass/llog_swab.c b/lustre/obdclass/llog_swab.c new file mode 100644 index 0000000..b966fb5 --- /dev/null +++ b/lustre/obdclass/llog_swab.c @@ -0,0 +1,202 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * Copyright (C) 2004-2005 Cluster File Systems, Inc. + * Author: jacob berkman + * + * This file is part of Lustre, http://www.lustre.org. + * + * Lustre is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * Lustre is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Lustre; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Swabbing of llog datatypes (from disk or over the wire). + * + */ + +#define DEBUG_SUBSYSTEM S_LOG + +#include + +static void print_llogd_body(struct llogd_body *d) +{ + CDEBUG(D_OTHER, "llogd body: %p\n", d); + CDEBUG(D_OTHER, "\tlgd_logid.lgl_oid: "LPX64"\n", d->lgd_logid.lgl_oid); + CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogr: "LPX64"\n", d->lgd_logid.lgl_ogr); + CDEBUG(D_OTHER, "\tlgd_logid.lgl_ogen: %#x\n", d->lgd_logid.lgl_ogen); + CDEBUG(D_OTHER, "\tlgd_ctxt_idx: %#x\n", d->lgd_ctxt_idx); + CDEBUG(D_OTHER, "\tlgd_llh_flags: %#x\n", d->lgd_llh_flags); + CDEBUG(D_OTHER, "\tlgd_index: %#x\n", d->lgd_index); + CDEBUG(D_OTHER, "\tlgd_saved_index: %#x\n", d->lgd_saved_index); + CDEBUG(D_OTHER, "\tlgd_len: %#x\n", d->lgd_len); + CDEBUG(D_OTHER, "\tlgd_cur_offset: "LPX64"\n", d->lgd_cur_offset); +} + +void lustre_swab_llogd_body (struct llogd_body *d) +{ + ENTRY; + print_llogd_body(d); + __swab64s (&d->lgd_logid.lgl_oid); + __swab64s (&d->lgd_logid.lgl_ogr); + __swab32s (&d->lgd_logid.lgl_ogen); + __swab32s (&d->lgd_ctxt_idx); + __swab32s (&d->lgd_llh_flags); + __swab32s (&d->lgd_index); + __swab32s (&d->lgd_saved_index); + __swab32s (&d->lgd_len); + __swab64s (&d->lgd_cur_offset); + print_llogd_body(d); + EXIT; +} +EXPORT_SYMBOL(lustre_swab_llogd_body); + +void lustre_swab_llogd_conn_body (struct llogd_conn_body *d) +{ + __swab64s (&d->lgdc_gen.mnt_cnt); + __swab64s (&d->lgdc_gen.conn_cnt); + __swab64s (&d->lgdc_logid.lgl_oid); + __swab64s (&d->lgdc_logid.lgl_ogr); + __swab32s (&d->lgdc_logid.lgl_ogen); + __swab32s (&d->lgdc_ctxt_idx); +} +EXPORT_SYMBOL(lustre_swab_llogd_conn_body); + +void lustre_swab_llog_hdr (struct llog_log_hdr *h) +{ + __swab32s (&h->llh_hdr.lrh_index); + __swab32s (&h->llh_hdr.lrh_len); + __swab32s (&h->llh_hdr.lrh_type); + __swab64s (&h->llh_timestamp); + __swab32s (&h->llh_count); + __swab32s (&h->llh_bitmap_offset); + __swab32s (&h->llh_flags); + __swab32s (&h->llh_tail.lrt_index); + __swab32s (&h->llh_tail.lrt_len); +} +EXPORT_SYMBOL(lustre_swab_llog_hdr); + +#define PRINT_PCFG32(x) CDEBUG(D_OTHER, "\tpcfg->pcfg_"#x": %#x\n", pcfg->pcfg_##x) +#define PRINT_PCFG64(x) CDEBUG(D_OTHER, "\tpcfg->pcfg_"#x": "LPX64"\n", pcfg->pcfg_##x) + +static void print_portals_cfg(struct portals_cfg *pcfg) +{ + ENTRY; + + if (!(portal_debug & D_OTHER)) /* don't loop on nothing */ + return; + CDEBUG(D_OTHER, "portals_cfg: %p\n", pcfg); + PRINT_PCFG32(version); + PRINT_PCFG32(command); + + PRINT_PCFG32(nal); + PRINT_PCFG32(flags); + + PRINT_PCFG32(gw_nal); + PRINT_PCFG64(nid); + PRINT_PCFG64(nid2); + PRINT_PCFG64(nid3); + PRINT_PCFG32(id); + PRINT_PCFG32(misc); + PRINT_PCFG32(fd); + PRINT_PCFG32(count); + PRINT_PCFG32(size); + PRINT_PCFG32(wait); + + PRINT_PCFG32(plen1); + PRINT_PCFG32(plen2); + + EXIT; +} + +void lustre_swab_portals_cfg(struct portals_cfg *pcfg) +{ + ENTRY; + + __swab32s(&pcfg->pcfg_version); + __swab32s(&pcfg->pcfg_command); + + __swab32s(&pcfg->pcfg_nal); + __swab32s(&pcfg->pcfg_flags); + + __swab32s(&pcfg->pcfg_gw_nal); + __swab64s(&pcfg->pcfg_nid); + __swab64s(&pcfg->pcfg_nid2); + __swab64s(&pcfg->pcfg_nid3); + __swab32s(&pcfg->pcfg_id); + __swab32s(&pcfg->pcfg_misc); + __swab32s(&pcfg->pcfg_fd); + __swab32s(&pcfg->pcfg_count); + __swab32s(&pcfg->pcfg_size); + __swab32s(&pcfg->pcfg_wait); + + __swab32s(&pcfg->pcfg_plen1); + __swab32s(&pcfg->pcfg_plen2); + + print_portals_cfg(pcfg); + EXIT; +} +EXPORT_SYMBOL(lustre_swab_portals_cfg); + +static void print_lustre_cfg(struct lustre_cfg *lcfg) +{ + int i; + ENTRY; + + if (!(portal_debug & D_OTHER)) /* don't loop on nothing */ + return; + CDEBUG(D_OTHER, "lustre_cfg: %p\n", lcfg); + CDEBUG(D_OTHER, "\tlcfg->lcfg_version: %#x\n", lcfg->lcfg_version); + + CDEBUG(D_OTHER, "\tlcfg->lcfg_command: %#x\n", lcfg->lcfg_command); + CDEBUG(D_OTHER, "\tlcfg->lcfg_num: %#x\n", lcfg->lcfg_num); + CDEBUG(D_OTHER, "\tlcfg->lcfg_flags: %#x\n", lcfg->lcfg_flags); + CDEBUG(D_OTHER, "\tlcfg->lcfg_nid: "LPX64"\n", lcfg->lcfg_nid); + CDEBUG(D_OTHER, "\tlcfg->lcfg_nal: %#x\n", lcfg->lcfg_nal); + + CDEBUG(D_OTHER, "\tlcfg->lcfg_bufcount: %d\n", lcfg->lcfg_bufcount); + if (lcfg->lcfg_bufcount < LUSTRE_CFG_MAX_BUFCOUNT) + for (i = 0; i < lcfg->lcfg_bufcount; i++) + CDEBUG(D_OTHER, "\tlcfg->lcfg_buflens[%d]: %d\n", + i, lcfg->lcfg_buflens[i]); + EXIT; +} + +void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg) +{ + int i; + ENTRY; + + __swab32s(&lcfg->lcfg_version); + + if (lcfg->lcfg_version != LUSTRE_CFG_VERSION) { + CERROR("not swabbing lustre_cfg version %#x (expecting %#x)\n", + lcfg->lcfg_version, LUSTRE_CFG_VERSION); + EXIT; + return; + } + + __swab32s(&lcfg->lcfg_command); + + __swab32s(&lcfg->lcfg_num); + __swab32s(&lcfg->lcfg_flags); + __swab64s(&lcfg->lcfg_nid); + __swab32s(&lcfg->lcfg_nal); + + __swab32s(&lcfg->lcfg_bufcount); + for (i = 0; i < lcfg->lcfg_bufcount && i < LUSTRE_CFG_MAX_BUFCOUNT; i++) + __swab32s(&lcfg->lcfg_buflens[i]); + + print_lustre_cfg(lcfg); + EXIT; + return; +} +EXPORT_SYMBOL(lustre_swab_lustre_cfg); diff --git a/lustre/obdclass/llog_test.c b/lustre/obdclass/llog_test.c index 18efa90..8c2756b 100644 --- a/lustre/obdclass/llog_test.c +++ b/lustre/obdclass/llog_test.c @@ -640,15 +640,15 @@ static int llog_test_setup(struct obd_device *obd, obd_count len, void *buf) int rc; ENTRY; - if (lcfg->lcfg_inllen1 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("requires a TARGET OBD name\n"); RETURN(-EINVAL); } - tgt = class_name2obd(lcfg->lcfg_inlbuf1); + tgt = class_name2obd(lustre_cfg_string(lcfg, 1)); if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) { CERROR("target device not attached or not set up (%s)\n", - lcfg->lcfg_inlbuf1); + lustre_cfg_string(lcfg, 1)); RETURN(-EINVAL); } diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index c27c6ae..f8478b4 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -50,39 +50,26 @@ static int class_attach(struct lustre_cfg *lcfg) char *typename, *name, *uuid; int rc, len, cleanup_phase = 0; - if (!lcfg->lcfg_inllen1 || !lcfg->lcfg_inlbuf1) { + if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) { CERROR("No type passed!\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inlbuf1[lcfg->lcfg_inllen1 - 1] != 0) { - CERROR("Type not nul terminated!\n"); - RETURN(-EINVAL); - } - typename = lcfg->lcfg_inlbuf1; + typename = lustre_cfg_string(lcfg, 1); - if (!lcfg->lcfg_dev_namelen || !lcfg->lcfg_dev_name) { + if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) { CERROR("No name passed!\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_dev_name[lcfg->lcfg_dev_namelen - 1] != 0) { - CERROR("Name not nul terminated!\n"); - RETURN(-EINVAL); - } - name = lcfg->lcfg_dev_name; + name = lustre_cfg_string(lcfg, 0); - if (!lcfg->lcfg_inllen2 || !lcfg->lcfg_inlbuf2) { + if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) { CERROR("No UUID passed!\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inlbuf2[lcfg->lcfg_inllen2 - 1] != 0) { - CERROR("UUID not nul terminated!\n"); - RETURN(-EINVAL); - } - uuid = lcfg->lcfg_inlbuf2; + uuid = lustre_cfg_string(lcfg, 2); CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n", - MKSTR(lcfg->lcfg_inlbuf1), MKSTR(lcfg->lcfg_dev_name), - MKSTR(lcfg->lcfg_inlbuf2)); + MKSTR(typename), MKSTR(name), MKSTR(uuid)); /* find the type */ type = class_get_type(typename); @@ -274,9 +261,8 @@ static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg) CERROR("Device %d not setup\n", obd->obd_minor); RETURN(-ENODEV); } - - if (lcfg->lcfg_inlbuf1) { - for (flag = lcfg->lcfg_inlbuf1; *flag != 0; flag++) + if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) { + for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++) switch (*flag) { case 'F': flags |= OBD_OPT_FORCE; @@ -308,6 +294,7 @@ static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg) CERROR("OBD device %d (%p,%s) has refcount %d\n", obd->obd_minor, obd, obd->obd_name, atomic_read(&obd->obd_refcount)); + portals_debug_dumplog(); dump_exports(obd); GOTO(out, err = -EBUSY); } @@ -359,15 +346,16 @@ int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg) { struct obd_import *imp; struct obd_uuid uuid; - int priority, rc; + int rc; ENTRY; - if (lcfg->lcfg_inllen1 <= 0 || - lcfg->lcfg_inllen1 > sizeof(struct obd_uuid)) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 || + LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) { CERROR("invalid conn_uuid\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 != sizeof(int)) { + + if (LUSTRE_CFG_BUFLEN(lcfg, 2) != sizeof(int)) { CERROR("invalid priority\n"); RETURN(-EINVAL); } @@ -383,9 +371,8 @@ int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg) RETURN(-EINVAL); } - obd_str2uuid(&uuid, lcfg->lcfg_inlbuf1); - priority = *((int*) lcfg->lcfg_inlbuf2); - rc = obd_add_conn(imp, &uuid, priority); + obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1)); + rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num); RETURN(rc); } @@ -396,11 +383,12 @@ int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg) int rc; ENTRY; - if (lcfg->lcfg_inllen1 <= 0 || - lcfg->lcfg_inllen1 > sizeof(struct obd_uuid)) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 || + LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) { CERROR("invalid conn_uuid\n"); RETURN(-EINVAL); } + if (strcmp(obd->obd_type->typ_name, "mdc") && strcmp(obd->obd_type->typ_name, "osc")) { CERROR("can't add connection on non-client dev\n"); @@ -413,7 +401,7 @@ int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg) RETURN(-EINVAL); } - obd_str2uuid(&uuid, lcfg->lcfg_inlbuf1); + obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1)); rc = obd_del_conn(imp, &uuid); RETURN(rc); @@ -505,38 +493,43 @@ int class_process_config(struct lustre_cfg *lcfg) } case LCFG_ADD_UUID: { CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64 - " (%s), nal %x\n", lcfg->lcfg_inlbuf1, lcfg->lcfg_nid, + " (%s), nal %x\n", lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid, portals_nid2str(lcfg->lcfg_nal, lcfg->lcfg_nid, str), lcfg->lcfg_nal); - err = class_add_uuid(lcfg->lcfg_inlbuf1, lcfg->lcfg_nid, - lcfg->lcfg_nal); - GOTO(out, err); + err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid, + lcfg->lcfg_nal); + GOTO(out, err); } case LCFG_DEL_UUID: { CDEBUG(D_IOCTL, "removing mappings for uuid %s\n", - lcfg->lcfg_inlbuf1 == NULL ? "" : - lcfg->lcfg_inlbuf1); + (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0) + ? "" : lustre_cfg_string(lcfg, 1)); - err = class_del_uuid(lcfg->lcfg_inlbuf1); + err = class_del_uuid(lustre_cfg_string(lcfg, 1)); GOTO(out, err); } case LCFG_MOUNTOPT: { CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n", - lcfg->lcfg_inlbuf1, lcfg->lcfg_inlbuf2, - lcfg->lcfg_inlbuf3); + lustre_cfg_string(lcfg, 1), + lustre_cfg_string(lcfg, 2), + lustre_cfg_string(lcfg, 3)); /* set these mount options somewhere, so ll_fill_super * can find them. */ - err = class_add_profile(lcfg->lcfg_inllen1, lcfg->lcfg_inlbuf1, - lcfg->lcfg_inllen2, lcfg->lcfg_inlbuf2, - lcfg->lcfg_inllen3, lcfg->lcfg_inlbuf3); + err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1), + lustre_cfg_string(lcfg, 1), + LUSTRE_CFG_BUFLEN(lcfg, 2), + lustre_cfg_string(lcfg, 2), + LUSTRE_CFG_BUFLEN(lcfg, 3), + lustre_cfg_string(lcfg, 3)); GOTO(out, err); } case LCFG_DEL_MOUNTOPT: { - CDEBUG(D_IOCTL, "mountopt: profile %s\n", lcfg->lcfg_inlbuf1); + CDEBUG(D_IOCTL, "mountopt: profile %s\n", + lustre_cfg_string(lcfg, 1)); /* set these mount options somewhere, so ll_fill_super * can find them. */ - class_del_profile(lcfg->lcfg_inlbuf1); + class_del_profile(lustre_cfg_string(lcfg, 1)); GOTO(out, err = 0); } case LCFG_SET_TIMEOUT: { @@ -548,22 +541,24 @@ int class_process_config(struct lustre_cfg *lcfg) } case LCFG_SET_UPCALL: { CDEBUG(D_IOCTL, "setting lustre ucpall to: %s\n", - lcfg->lcfg_inlbuf1); - if (lcfg->lcfg_inllen1 > sizeof obd_lustre_upcall) + lustre_cfg_string(lcfg, 1)); + if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof obd_lustre_upcall) GOTO(out, err = -EINVAL); - memcpy(obd_lustre_upcall, lcfg->lcfg_inlbuf1, - lcfg->lcfg_inllen1); + strncpy(obd_lustre_upcall, lustre_cfg_string(lcfg, 1), + sizeof (obd_lustre_upcall)); GOTO(out, err = 0); } } - + /* Commands that require a device */ - obd = class_name2obd(lcfg->lcfg_dev_name); + obd = class_name2obd(lustre_cfg_string(lcfg, 0)); if (obd == NULL) { - if (lcfg->lcfg_dev_name == NULL) - CERROR("this lcfg command requires a device name\n"); + if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) + CERROR("this lcfg command %d requires a device name\n", + lcfg->lcfg_command); else - CERROR("no device for: %s\n", lcfg->lcfg_dev_name); + CERROR("no device for: %s\n", + lustre_cfg_string(lcfg, 0)); GOTO(out, err = -EINVAL); } @@ -609,56 +604,51 @@ static int class_config_parse_handler(struct llog_handle * handle, ENTRY; if (rec->lrh_type == OBD_CFG_REC) { - char *buf; - struct lustre_cfg *lcfg; - char *old_name = NULL; - int old_len = 0; - char *old_uuid = NULL; - int old_uuid_len = 0; + struct lustre_cfg *lcfg, *lcfg_new; + struct lustre_cfg_bufs bufs; + char *inst_name = NULL; int inst_len = 0; + int inst = 0; - rc = lustre_cfg_getdata(&buf, cfg_len, cfg_buf, 1); + lcfg = (struct lustre_cfg *)cfg_buf; + if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) + lustre_swab_lustre_cfg(lcfg); + + rc = lustre_cfg_sanity_check(cfg_buf, cfg_len); if (rc) GOTO(out, rc); - lcfg = (struct lustre_cfg* ) buf; - if (cfg && cfg->cfg_instance && lcfg->lcfg_dev_name) { - inst_len = strlen(lcfg->lcfg_dev_name) + - strlen(cfg->cfg_instance) + 2; + lustre_cfg_bufs_init(&bufs, lcfg); + + if (cfg && cfg->cfg_instance && LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) { + inst = 1; + inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) + + strlen(cfg->cfg_instance) + 1; OBD_ALLOC(inst_name, inst_len); if (inst_name == NULL) GOTO(out, rc = -ENOMEM); - sprintf(inst_name, "%s-%s", lcfg->lcfg_dev_name, + sprintf(inst_name, "%s-%s", + lustre_cfg_string(lcfg, 0), cfg->cfg_instance); - old_name = lcfg->lcfg_dev_name; - old_len = lcfg->lcfg_dev_namelen; - lcfg->lcfg_dev_name = inst_name; - lcfg->lcfg_dev_namelen = strlen(inst_name) + 1; - } + lustre_cfg_bufs_set_string(&bufs, 0, inst_name); + } if (cfg && lcfg->lcfg_command == LCFG_ATTACH) { - old_uuid = lcfg->lcfg_inlbuf2; - old_uuid_len = lcfg->lcfg_inllen2; - - lcfg->lcfg_inlbuf2 = (char*)&cfg->cfg_uuid.uuid; - lcfg->lcfg_inllen2 = sizeof(cfg->cfg_uuid); + lustre_cfg_bufs_set_string(&bufs, 2, cfg->cfg_uuid.uuid); } + lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs); - rc = class_process_config(lcfg); - - if (old_name) { - lcfg->lcfg_dev_name = old_name; - lcfg->lcfg_dev_namelen = old_len; - OBD_FREE(inst_name, inst_len); - } + lcfg_new->lcfg_num = lcfg->lcfg_num; + lcfg_new->lcfg_flags = lcfg->lcfg_flags; + lcfg_new->lcfg_nid = lcfg->lcfg_nid; + lcfg_new->lcfg_nal = lcfg->lcfg_nal; - if (old_uuid) { - lcfg->lcfg_inlbuf2 = old_uuid; - lcfg->lcfg_inllen2 = old_uuid_len; - } + rc = class_process_config(lcfg_new); + lustre_cfg_free(lcfg_new); - lustre_cfg_freedata(buf, cfg_len); + if (inst) + OBD_FREE(inst_name, inst_len); } else if (rec->lrh_type == PTL_CFG_REC) { struct portals_cfg *pcfg = (struct portals_cfg *)cfg_buf; if (pcfg->pcfg_command == NAL_CMD_REGISTER_MYNID && @@ -703,22 +693,21 @@ int class_config_dump_handler(struct llog_handle * handle, char *cfg_buf = (char*) (rec + 1); int rc = 0; ENTRY; - if (rec->lrh_type == OBD_CFG_REC) { - char *buf; struct lustre_cfg *lcfg; + int i; - rc = lustre_cfg_getdata(&buf, cfg_len, cfg_buf, 1); + rc = lustre_cfg_sanity_check(cfg_buf, cfg_len); if (rc) GOTO(out, rc); - lcfg = (struct lustre_cfg* ) buf; + lcfg = (struct lustre_cfg *)cfg_buf; - CDEBUG(D_INFO, "lcfg command: 0x%x\n", lcfg->lcfg_command); - if (lcfg->lcfg_dev_name) + CDEBUG(D_INFO, "lcfg command: %x\n", lcfg->lcfg_command); + if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) CDEBUG(D_INFO, " devname: %s\n", - lcfg->lcfg_dev_name); + lustre_cfg_string(lcfg, 0)); if (lcfg->lcfg_flags) - CDEBUG(D_INFO, " flags: 0x%x\n", lcfg->lcfg_flags); + CDEBUG(D_INFO, " flags: %x\n", lcfg->lcfg_flags); if (lcfg->lcfg_nid) CDEBUG(D_INFO, " nid: "LPX64"\n", lcfg->lcfg_nid); @@ -726,24 +715,13 @@ int class_config_dump_handler(struct llog_handle * handle, CDEBUG(D_INFO, " nal: %x\n", lcfg->lcfg_nal); if (lcfg->lcfg_num) CDEBUG(D_INFO, " nal: %x\n", lcfg->lcfg_num); - if (lcfg->lcfg_inlbuf1) - CDEBUG(D_INFO, " inlbuf1: %s\n",lcfg->lcfg_inlbuf1); - if (lcfg->lcfg_inlbuf2) - CDEBUG(D_INFO, " inlbuf2: %s\n",lcfg->lcfg_inlbuf2); - if (lcfg->lcfg_inlbuf3) - CDEBUG(D_INFO, " inlbuf3: %s\n",lcfg->lcfg_inlbuf3); - if (lcfg->lcfg_inlbuf4) - CDEBUG(D_INFO, " inlbuf4: %s\n",lcfg->lcfg_inlbuf4); - if (lcfg->lcfg_inlbuf5) - CDEBUG(D_INFO, " inlbuf5: %s\n",lcfg->lcfg_inlbuf5); - if (lcfg->lcfg_inlbuf6) - CDEBUG(D_INFO, " inlbuf6: %s\n",lcfg->lcfg_inlbuf6); - - lustre_cfg_freedata(buf, cfg_len); + for (i = 1; i < lcfg->lcfg_bufcount; i++) + if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0) + CDEBUG(D_INFO, " inlbuf%d: %s\n", i, + lustre_cfg_string(lcfg, i)); } else if (rec->lrh_type == PTL_CFG_REC) { struct portals_cfg *pcfg = (struct portals_cfg *)cfg_buf; - - CDEBUG(D_INFO, "pcfg command: 0x%x\n", pcfg->pcfg_command); + CDEBUG(D_INFO, "pcfg command: %d\n", pcfg->pcfg_command); if (pcfg->pcfg_nal) CDEBUG(D_INFO, " nal: %x\n", pcfg->pcfg_nal); @@ -754,19 +732,19 @@ int class_config_dump_handler(struct llog_handle * handle, CDEBUG(D_INFO, " nid: "LPX64"\n", pcfg->pcfg_nid); if (pcfg->pcfg_nid2) - CDEBUG(D_INFO, " nid2: "LPX64"\n", + CDEBUG(D_INFO, " nid: "LPX64"\n", pcfg->pcfg_nid2); if (pcfg->pcfg_nid3) - CDEBUG(D_INFO, " nid3: "LPX64"\n", + CDEBUG(D_INFO, " nid: "LPX64"\n", pcfg->pcfg_nid3); if (pcfg->pcfg_misc) - CDEBUG(D_INFO, " misc: %d\n", + CDEBUG(D_INFO, " nid: %d\n", pcfg->pcfg_misc); if (pcfg->pcfg_id) - CDEBUG(D_INFO, " id: 0x%x\n", + CDEBUG(D_INFO, " id: %x\n", pcfg->pcfg_id); if (pcfg->pcfg_flags) - CDEBUG(D_INFO, " flags: 0x%x\n", + CDEBUG(D_INFO, " flags: %x\n", pcfg->pcfg_flags); } else { CERROR("unhandled lrh_type: %#x\n", rec->lrh_type); diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 3d5e145..1af78b4 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -1331,15 +1331,15 @@ echo_client_setup(struct obd_device *obddev, obd_count len, void *buf) int rc; ENTRY; - if (lcfg->lcfg_inllen1 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("requires a TARGET OBD name\n"); RETURN(-EINVAL); } - tgt = class_name2obd(lcfg->lcfg_inlbuf1); + tgt = class_name2obd(lustre_cfg_string(lcfg, 1)); if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) { CERROR("device not attached or not set up (%s)\n", - lcfg->lcfg_inlbuf1); + lustre_cfg_string(lcfg, 1)); RETURN(-EINVAL); } @@ -1349,7 +1349,7 @@ echo_client_setup(struct obd_device *obddev, obd_count len, void *buf) rc = obd_connect(&conn, tgt, &echo_uuid, NULL, FILTER_GROUP_ECHO); if (rc) { - CERROR("fail to connect to device %s\n", lcfg->lcfg_inlbuf1); + CERROR("fail to connect to device %s\n", lustre_cfg_string(lcfg, 1)); return (rc); } ec->ec_exp = class_conn2export(&conn); diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index a272398..218e188 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -1433,23 +1433,25 @@ static int filter_post_fs_setup(struct obd_device *obd) int filter_common_setup(struct obd_device *obd, obd_count len, void *buf, char *option) { - struct lustre_cfg* lcfg = buf; + struct lustre_cfg *lcfg = buf; struct filter_obd *filter = &obd->u.filter; struct lvfs_obd_ctxt *lvfs_ctxt = NULL; struct vfsmount *mnt; + char *str; char ns_name[48]; int rc = 0, i; ENTRY; - - if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2) + if ((LUSTRE_CFG_BUFLEN(lcfg, 1)) < 1 || + (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1)) RETURN(-EINVAL); - obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2); + obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2)); if (IS_ERR(obd->obd_fsops)) RETURN(PTR_ERR(obd->obd_fsops)); - rc = lvfs_mount_fs(lcfg->lcfg_inlbuf1, lcfg->lcfg_inlbuf2, + rc = lvfs_mount_fs(lustre_cfg_string(lcfg, 1), + lustre_cfg_string(lcfg, 2), option, MS_NOATIME | MS_NODIRATIME, &lvfs_ctxt); if (rc) { CERROR("lvfs_mount_fs failed: rc = %d\n", rc); @@ -1460,15 +1462,16 @@ int filter_common_setup(struct obd_device *obd, obd_count len, void *buf, mnt = lvfs_ctxt->loc_mnt; filter->fo_lvfs_ctxt = lvfs_ctxt; - if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3) { - if (*lcfg->lcfg_inlbuf3 == 'f') { + if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0 && lustre_cfg_buf(lcfg, 3)) { + str = lustre_cfg_string(lcfg, 3); + if (*str == 'f') { obd->obd_replayable = 1; obd_sync_filter = 1; CWARN("%s: recovery enabled\n", obd->obd_name); } else { - if (*lcfg->lcfg_inlbuf3 != 'n') { + if (*str != 'n') { CERROR("unrecognised flag '%c'\n", - *lcfg->lcfg_inlbuf3); + *str); } // XXX Robert? Why do we get errors here // GOTO(err_mntput, rc = -EINVAL); @@ -1585,7 +1588,7 @@ static int filter_setup(struct obd_device *obd, obd_count len, void *buf) /* all mount options including errors=remount-ro and asyncdel are passed * using 4th lcfg param. And it is good, finally we have got rid of * hardcoded fs types in the code. */ - rc = filter_common_setup(obd, len, buf, lcfg->lcfg_inlbuf4); + rc = filter_common_setup(obd, len, buf, lustre_cfg_buf(lcfg, 4)); if (rc) RETURN(rc); rc = filter_post_fs_setup(obd); diff --git a/lustre/obdfilter/filter_san.c b/lustre/obdfilter/filter_san.c index f6d8d06..ed4da89 100644 --- a/lustre/obdfilter/filter_san.c +++ b/lustre/obdfilter/filter_san.c @@ -40,13 +40,13 @@ int filter_san_setup(struct obd_device *obd, obd_count len, void *buf) struct lustre_cfg* lcfg = buf; char *option = NULL; - if (!lcfg->lcfg_inlbuf2) + if (!lustre_cfg_buf(lcfg, 2)) RETURN(-EINVAL); /* for extN/ext3 filesystem, we must mount it with 'writeback' mode */ - if (!strcmp(lcfg->lcfg_inlbuf2, "extN")) + if (!strcmp(lustre_cfg_string(lcfg, 2), "extN")) option = "data=writeback"; - else if (!strcmp(lcfg->lcfg_inlbuf2, "ext3")) + else if (!strcmp(lustre_cfg_string(lcfg, 2), "ext3")) option = "data=writeback,asyncdel"; else LBUG(); /* just a reminder */ diff --git a/lustre/osc/osc_lib.c b/lustre/osc/osc_lib.c index cdf2ae6..34532e1 100644 --- a/lustre/osc/osc_lib.c +++ b/lustre/osc/osc_lib.c @@ -60,16 +60,16 @@ int client_sanobd_setup(struct obd_device *obddev, obd_count len, void *buf) struct client_obd *cli = &obddev->u.cli; ENTRY; - if (lcfg->lcfg_inllen3 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 3) < 1) { CERROR("setup requires a SAN device pathname\n"); RETURN(-EINVAL); } client_obd_setup(obddev, len, buf); - cli->cl_sandev = path2dev(lcfg->lcfg_inlbuf3); + cli->cl_sandev = path2dev(lustre_cfg_string(lcfg, 3)); if (!kdev_t_to_nr(cli->cl_sandev)) { - CERROR("%s seems not a valid SAN device\n", lcfg->lcfg_inlbuf3); + CERROR("%s seems not a valid SAN device\n", lustre_cfg_string(lcfg, 3)); RETURN(-EINVAL); } diff --git a/lustre/ptlbd/client.c b/lustre/ptlbd/client.c index b1d21e1..c44f955 100644 --- a/lustre/ptlbd/client.c +++ b/lustre/ptlbd/client.c @@ -55,17 +55,17 @@ static int ptlbd_cl_setup(struct obd_device *obd, obd_count len, void *buf) if (ptlbd->bd_import != NULL) RETURN(-EALREADY); - if (lcfg->lcfg_inllen1 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("requires a PTLBD server UUID\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen1 > 37) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) { CERROR("PTLBD server UUID must be less than 38 characters\n"); RETURN(-EINVAL); } - obd_str2uuid(&ptlbd->bd_server_uuid, lcfg->lcfg_inlbuf1); + obd_str2uuid(&ptlbd->bd_server_uuid, lustre_cfg_string(lcfg, 1)); /* * from client_obd_connect.. *shrug* @@ -83,8 +83,8 @@ static int ptlbd_cl_setup(struct obd_device *obd, obd_count len, void *buf) "ptlbd", &ptlbd->bd_client); imp->imp_client = &ptlbd->bd_client; imp->imp_obd = obd; - memcpy(imp->imp_target_uuid.uuid, lcfg->lcfg_inlbuf1, - lcfg->lcfg_inllen1); + memcpy(imp->imp_target_uuid.uuid, lustre_cfg_string(lcfg, 1), + LUSTRE_CFG_BUFLEN(lcfg, 1)); ptlbd_blk_register(ptlbd); RETURN(0); diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index 1016882..dba43a9 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -871,43 +871,6 @@ int llog_log_swabbed(struct llog_log_hdr *hdr) return 0; return -1; } - -void lustre_swab_llogd_body (struct llogd_body *d) -{ - __swab64s (&d->lgd_logid.lgl_oid); - __swab64s (&d->lgd_logid.lgl_ogr); - __swab32s (&d->lgd_logid.lgl_ogen); - __swab32s (&d->lgd_ctxt_idx); - __swab32s (&d->lgd_llh_flags); - __swab32s (&d->lgd_index); - __swab32s (&d->lgd_saved_index); - __swab32s (&d->lgd_len); - __swab64s (&d->lgd_cur_offset); -} - -void lustre_swab_llog_hdr (struct llog_log_hdr *h) -{ - __swab32s (&h->llh_hdr.lrh_index); - __swab32s (&h->llh_hdr.lrh_len); - __swab32s (&h->llh_hdr.lrh_type); - __swab64s (&h->llh_timestamp); - __swab32s (&h->llh_count); - __swab32s (&h->llh_bitmap_offset); - __swab32s (&h->llh_flags); - __swab32s (&h->llh_tail.lrt_index); - __swab32s (&h->llh_tail.lrt_len); -} - -void lustre_swab_llogd_conn_body (struct llogd_conn_body *d) -{ - __swab64s (&d->lgdc_gen.mnt_cnt); - __swab64s (&d->lgdc_gen.conn_cnt); - __swab64s (&d->lgdc_logid.lgl_oid); - __swab64s (&d->lgdc_logid.lgl_ogr); - __swab32s (&d->lgdc_logid.lgl_ogen); - __swab32s (&d->lgdc_ctxt_idx); -} - void lustre_assert_wire_constants(void) { } diff --git a/lustre/tests/cobd.sh b/lustre/tests/cobd.sh index 9e9e1cd..cc74e41 100755 --- a/lustre/tests/cobd.sh +++ b/lustre/tests/cobd.sh @@ -29,7 +29,7 @@ OSDTYPE=${OSDTYPE:-obdfilter} OSTFAILOVER=${OSTFAILOVER:-} FSTYPE=${FSTYPE:-smfs} -BACK_FSTYPE=${BACK_FSTYPE:-ext3} +BACK_FSTYPE=${BACK_FSTYPE:-ldiskfs} NETTYPE=${NETTYPE:-tcp} NIDTYPE=${NIDTYPE:-$NETTYPE} @@ -55,7 +55,7 @@ h2tcp () { ${LMC} -m $config --add net --node $NODE --nid `h2$NIDTYPE $NODE` --nettype $NETTYPE || exit 1 ${LMC} -m $config --format --add mds --node $MDSNODE --mds $CACHE_MDS --fstype $FSTYPE \ ---backfstype $BACK_FSTYPE --dev $FSTYPE --backdev $MDS_CACHE_DEV --mountfsoptions $MDS_MOUNT_OPTS --size $MDSSIZE ||exit 10 +--backfstype $BACK_FSTYPE --dev $MDS_CACHE_DEV --mountfsoptions $MDS_MOUNT_OPTS --size $MDSSIZE ||exit 10 ${LMC} -m $config --format --add mds --node $MDSNODE --mds $MASTER_MDS --fstype $BACK_FSTYPE \ --dev $MDS_MASTER_DEV --size $MDSSIZE || exit 10 @@ -67,8 +67,8 @@ ${LMC} -m $config --add lov --lov $MASTER_LOV --mds $MASTER_MDS \ --stripe_sz 65536 --stripe_cnt $STRIPECNT --stripe_pattern 0 || exit 20 ${LMC} -m $config --add ost --node $NODE --lov $CACHE_LOV \ ---fstype $FSTYPE --dev $FSTYPE --backfstype $BACK_FSTYPE \ ---backdev $OST_CACHE_DEV --mountfsoptions $OST_MOUNT_OPTS --size $OSTSIZE || exit 21 +--fstype $FSTYPE --dev $OST_CACHE_DEV --backfstype $BACK_FSTYPE \ +--mountfsoptions $OST_MOUNT_OPTS --size $OSTSIZE || exit 21 ${LMC} -m $config --add ost --node $NODE --lov $MASTER_LOV \ --fstype $BACK_FSTYPE --dev $OST_MASTER_DEV --size $OSTSIZE || exit 21 diff --git a/lustre/tests/local.sh b/lustre/tests/local.sh index 549e59e..dd1b977 100755 --- a/lustre/tests/local.sh +++ b/lustre/tests/local.sh @@ -20,11 +20,8 @@ NETTYPE=${NETTYPE:-tcp} OSTDEV=${OSTDEV:-$TMP/ost1-`hostname`} OSTSIZE=${OSTSIZE:-400000} -MDS_BACKFSTYPE=${MDS_BACKFSTYPE:-ext3} -OST_BACKFSTYPE=${OST_BACKFSTYPE:-ext3} - -MDS_BACKDEV=${MDS_BACKDEV:-$TMP/mds1-`hostname`} -OST_BACKDEV=${OST_BACKDEV:-$TMP/ost1-`hostname`} +MDS_BACKFSTYPE=${MDS_BACKFSTYPE:-$DEF_FSTYPE} +OST_BACKFSTYPE=${OST_BACKFSTYPE:-$DEF_FSTYPE} # specific journal size for the ost, in MB JSIZE=${JSIZE:-0} @@ -49,7 +46,7 @@ ${LMC} --add net --node client --nid '*' --nettype $NETTYPE || exit 12 # configure mds server ${LMC} --add mds --nspath /mnt/mds_ns --node localhost --mds mds1 \ --fstype $FSTYPE --backfstype $MDS_BACKFSTYPE --dev $MDSDEV \ ---backdev $MDS_BACKDEV $MDS_MOUNT_OPTS --size $MDSSIZE $JARG $IARG || exit 20 +$MDS_MOUNT_OPTS --size $MDSSIZE $JARG $IARG || exit 20 [ "x$OST_MOUNT_OPTS" != "x" ] && OST_MOUNT_OPTS="--mountfsoptions $OST_MOUNT_OPTS" @@ -60,7 +57,7 @@ ${LMC} -m $config --add lov --lov lov1 --mds mds1 --stripe_sz $STRIPE_BYTES \ ${LMC} --add ost --ost ost1 --nspath /mnt/ost_ns --node localhost --lov lov1 \ --fstype $OST_FSTYPE --backfstype $OST_BACKFSTYPE --dev $OSTDEV \ ---backdev $OST_BACKDEV $OST_MOUNT_OPTS --size $OSTSIZE $JARG || exit 30 +$OST_MOUNT_OPTS --size $OSTSIZE $JARG || exit 30 # create client config ${LMC} --add mtpt --node localhost --path $MOUNT --clientoptions async --mds mds1 --lov lov1 || exit 40 diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index b0af4a6..3d90d40 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -93,19 +93,18 @@ int jt_lcfg_newdev(int argc, char **argv) int jt_lcfg_attach(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; int rc; - LCFG_INIT(lcfg, LCFG_ATTACH, lcfg_devname); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); if (argc != 2 && argc != 3 && argc != 4) return CMD_HELP; - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; + lustre_cfg_bufs_set_string(&bufs, 1, argv[1]); if (argc >= 3) { - lcfg.lcfg_dev_namelen = strlen(argv[2]) + 1; - lcfg.lcfg_dev_name = argv[2]; + lustre_cfg_bufs_set_string(&bufs, 0, argv[2]); } else { fprintf(stderr, "error: %s: LCFG_ATTACH requires a name\n", jt_cmdname(argv[0])); @@ -113,11 +112,11 @@ int jt_lcfg_attach(int argc, char **argv) } if (argc == 4) { - lcfg.lcfg_inllen2 = strlen(argv[3]) + 1; - lcfg.lcfg_inlbuf2 = argv[3]; + lustre_cfg_bufs_set_string(&bufs, 2, argv[3]); } - - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) { fprintf(stderr, "error: %s: LCFG_ATTACH %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); @@ -143,8 +142,9 @@ int jt_lcfg_attach(int argc, char **argv) int jt_lcfg_setup(int argc, char **argv) { - struct lustre_cfg lcfg; - int rc; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; + int rc, i; if (lcfg_devname == NULL) { fprintf(stderr, "%s: please use 'cfg_device name' to set the " @@ -153,36 +153,18 @@ int jt_lcfg_setup(int argc, char **argv) return -EINVAL; } - LCFG_INIT(lcfg, LCFG_SETUP, lcfg_devname); - + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + if (argc > 7) return CMD_HELP; - if (argc > 1) { - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; - } - if (argc > 2) { - lcfg.lcfg_inllen2 = strlen(argv[2]) + 1; - lcfg.lcfg_inlbuf2 = argv[2]; - } - if (argc > 3) { - lcfg.lcfg_inllen3 = strlen(argv[3]) + 1; - lcfg.lcfg_inlbuf3 = argv[3]; - } - if (argc > 4) { - lcfg.lcfg_inllen4 = strlen(argv[4]) + 1; - lcfg.lcfg_inlbuf4 = argv[4]; - } - if (argc > 5) { - lcfg.lcfg_inllen5 = strlen(argv[5]) + 1; - lcfg.lcfg_inlbuf5 = argv[5]; + for (i = 1; i < argc; i++) { + lustre_cfg_bufs_set_string(&bufs, i, argv[i]); } - if (argc > 6) { - lcfg.lcfg_inllen6 = strlen(argv[6]) + 1; - lcfg.lcfg_inlbuf6 = argv[6]; - } - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); @@ -192,7 +174,8 @@ int jt_lcfg_setup(int argc, char **argv) int jt_obd_detach(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; int rc; if (lcfg_devname == NULL) { @@ -201,42 +184,49 @@ int jt_obd_detach(int argc, char **argv) jt_cmdname(argv[0])); return -EINVAL; } - - LCFG_INIT(lcfg, LCFG_DETACH, lcfg_devname); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); if (argc != 1) return CMD_HELP; - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(LCFG_DETACH, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); + if (rc < 0) fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); - return rc; } int jt_obd_cleanup(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; char force = 'F'; char failover = 'A'; char flags[3]; int flag_cnt = 0, n; int rc; + + if (lcfg_devname == NULL) { fprintf(stderr, "%s: please use 'cfg_device name' to set the " "device name for config commands.\n", jt_cmdname(argv[0])); - return -EINVAL; + return -EINVAL; } - LCFG_INIT(lcfg, LCFG_CLEANUP, lcfg_devname); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); if (argc < 1 || argc > 3) return CMD_HELP; - for (n = 1; n < argc; n++) + /* we are protected from overflowing our buffer by the argc + * check above + */ + for (n = 1; n < argc; n++) { if (strcmp(argv[n], "force") == 0) { flags[flag_cnt++] = force; } else if (strcmp(argv[n], "failover") == 0) { @@ -245,12 +235,15 @@ int jt_obd_cleanup(int argc, char **argv) fprintf(stderr, "unknown option: %s", argv[n]); return CMD_HELP; } + } - lcfg.lcfg_inllen1 = flag_cnt; - if (flag_cnt) - lcfg.lcfg_inlbuf1 = flags; + if (flag_cnt) { + lustre_cfg_bufs_set_string(&bufs, 1, flags); + } - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); @@ -263,15 +256,19 @@ int do_add_uuid(char * func, char *uuid, ptl_nid_t nid, int nal) { char tmp[64]; int rc; - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; + + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + if (uuid) + lustre_cfg_bufs_set_string(&bufs, 1, uuid); - LCFG_INIT(lcfg, LCFG_ADD_UUID, lcfg_devname); - lcfg.lcfg_nid = nid; - lcfg.lcfg_inllen1 = strlen(uuid) + 1; - lcfg.lcfg_inlbuf1 = uuid; - lcfg.lcfg_nal = nal; + lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs); + lcfg->lcfg_nid = nid; + lcfg->lcfg_nal = nal; - rc = lcfg_ioctl(func, OBD_DEV_ID, &lcfg); + rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc) { fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n", strerror(errno)); @@ -280,6 +277,7 @@ int do_add_uuid(char * func, char *uuid, ptl_nid_t nid, int nal) printf ("Added uuid %s: %s\n", uuid, ptl_nid2str (tmp, nid)); return 0; + } int jt_lcfg_add_uuid(int argc, char **argv) @@ -314,22 +312,21 @@ int obd_add_uuid(char *uuid, ptl_nid_t nid, int nal) int jt_lcfg_del_uuid(int argc, char **argv) { int rc; - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]); return 0; } - LCFG_INIT(lcfg, LCFG_DEL_UUID, lcfg_devname); - + lustre_cfg_bufs_reset(&bufs, lcfg_devname); if (strcmp (argv[1], "_all_")) - { - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; - } + lustre_cfg_bufs_set_string(&bufs, 1, argv[1]); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc) { fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n", strerror(errno)); @@ -340,7 +337,8 @@ int jt_lcfg_del_uuid(int argc, char **argv) int jt_lcfg_lov_setup(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; struct lov_desc desc; int rc; char *end; @@ -409,13 +407,13 @@ int jt_lcfg_lov_setup(int argc, char **argv) return -EINVAL; } } - - LCFG_INIT(lcfg, LCFG_SETUP, lcfg_devname); - - lcfg.lcfg_inllen1 = sizeof(desc); - lcfg.lcfg_inlbuf1 = (char *)&desc; - - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc)); + + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc) fprintf(stderr, "error: %s: ioctl error: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); @@ -424,13 +422,13 @@ int jt_lcfg_lov_setup(int argc, char **argv) int jt_lcfg_lmv_setup(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; struct lmv_desc desc; struct obd_uuid *uuidarray, *ptr; int rc, i; - LCFG_INIT(lcfg, LCFG_SETUP, lcfg_devname); - + lustre_cfg_bufs_reset(&bufs, lcfg_devname); if (argc <= 2) return CMD_HELP; @@ -470,12 +468,13 @@ int jt_lcfg_lmv_setup(int argc, char **argv) strcpy((char *)ptr, argv[i]); } - lcfg.lcfg_inllen1 = sizeof(desc); - lcfg.lcfg_inlbuf1 = (char *)&desc; - lcfg.lcfg_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray); - lcfg.lcfg_inlbuf2 = (char *)uuidarray; - - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc)); + lustre_cfg_bufs_set(&bufs, 2, (char*)uuidarray, + desc.ld_tgt_count * sizeof(*uuidarray)); + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); + if (rc) fprintf(stderr, "error: %s: ioctl error: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); @@ -483,11 +482,12 @@ out: free(uuidarray); return rc; } - int jt_lcfg_lov_modify_tgts(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; char *end; + int cmd = 0; int index; int gen; int rc; @@ -497,33 +497,34 @@ int jt_lcfg_lov_modify_tgts(int argc, char **argv) return CMD_HELP; if (!strncmp(argv[1], "add", 4)) { - LCFG_INIT(lcfg, LCFG_LOV_ADD_OBD, argv[2]); + cmd = LCFG_LOV_ADD_OBD; } else if (!strncmp(argv[1], "del", 4)) { - LCFG_INIT(lcfg, LCFG_LOV_DEL_OBD, argv[2]); + cmd = LCFG_LOV_DEL_OBD; } else { fprintf(stderr, "error: %s: bad operation '%s'\n", jt_cmdname(argv[0]), argv[1]); return CMD_HELP; } - lcfg.lcfg_inlbuf1 = argv[3]; - lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1; - if (lcfg.lcfg_inllen1 > sizeof(struct obd_uuid)) { + lustre_cfg_bufs_reset(&bufs, argv[2]); + + + if (((index = strlen(argv[3]) + 1)) > sizeof(struct obd_uuid)) { fprintf(stderr, "error: %s: OBD uuid '%s' longer than "LPSZ" chars\n", jt_cmdname(argv[0]), argv[3], sizeof(struct obd_uuid) - 1); return -EINVAL; } - + lustre_cfg_bufs_set(&bufs, 1, argv[3], index); + index = strtoul(argv[4], &end, 0); if (*end) { fprintf(stderr, "error: %s: bad OBD index '%s'\n", jt_cmdname(argv[0]), argv[4]); return CMD_HELP; } - lcfg.lcfg_inlbuf2 = argv[4]; - lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2); + lustre_cfg_bufs_set(&bufs, 2, argv[4], strlen(argv[4])); gen = strtoul(argv[5], &end, 0); if (*end) { @@ -531,88 +532,85 @@ int jt_lcfg_lov_modify_tgts(int argc, char **argv) jt_cmdname(argv[0]), argv[5]); return CMD_HELP; } - lcfg.lcfg_inlbuf3 = argv[5]; - lcfg.lcfg_inllen3 = strlen(lcfg.lcfg_inlbuf3); + lustre_cfg_bufs_set(&bufs, 3, argv[5], strlen(argv[5])); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(cmd, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc) fprintf(stderr, "error: %s: ioctl error: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); - return rc; } int jt_lcfg_mount_option(int argc, char **argv) { int rc; - struct lustre_cfg lcfg; - - LCFG_INIT(lcfg, LCFG_MOUNTOPT, lcfg_devname); + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; + int i; if (argc < 3 || argc > 4) return CMD_HELP; - /* profile name */ - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; - /* osc name */ - lcfg.lcfg_inllen2 = strlen(argv[2]) + 1; - lcfg.lcfg_inlbuf2 = argv[2]; - if (argc == 4) { - /* mdc name */ - lcfg.lcfg_inllen3 = strlen(argv[3]) + 1; - lcfg.lcfg_inlbuf3 = argv[3]; - } - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + + for (i = 1; i < argc; i++) + lustre_cfg_bufs_set_string(&bufs, i, argv[i]); + + lcfg = lustre_cfg_new(LCFG_MOUNTOPT, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) { fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); } - return rc; } int jt_lcfg_del_mount_option(int argc, char **argv) { int rc; - struct lustre_cfg lcfg; - - LCFG_INIT(lcfg, LCFG_DEL_MOUNTOPT, lcfg_devname); + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; if (argc != 2) return CMD_HELP; + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + /* profile name */ - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; + lustre_cfg_bufs_set_string(&bufs, 1, argv[1]); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) { fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); } - return rc; } int jt_lcfg_set_timeout(int argc, char **argv) { int rc; - struct lustre_cfg lcfg; - - LCFG_INIT(lcfg, LCFG_SET_TIMEOUT, lcfg_devname); + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; if (argc != 2) return CMD_HELP; - lcfg.lcfg_num = atoi(argv[1]); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs); + lcfg->lcfg_num = atoi(argv[1]); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) { fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); } - return rc; } @@ -620,28 +618,31 @@ int jt_lcfg_set_timeout(int argc, char **argv) int jt_lcfg_set_lustre_upcall(int argc, char **argv) { int rc; - struct lustre_cfg lcfg; - - LCFG_INIT(lcfg, LCFG_SET_UPCALL, lcfg_devname); + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; if (argc != 2) return CMD_HELP; + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + /* profile name */ - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; + lustre_cfg_bufs_set_string(&bufs, 1, argv[1]); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(LCFG_SET_UPCALL, &bufs); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) { fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); } - return rc; } + int jt_lcfg_add_conn(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; int priority; int rc; @@ -656,29 +657,29 @@ int jt_lcfg_add_conn(int argc, char **argv) fprintf(stderr, "%s: please use 'cfg_device name' to set the " "device name for config commands.\n", jt_cmdname(argv[0])); - return -EINVAL; + return -EINVAL; } - LCFG_INIT(lcfg, LCFG_ADD_CONN, lcfg_devname); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); - /* connection uuid */ - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; - lcfg.lcfg_inllen2 = sizeof(int); - lcfg.lcfg_inlbuf2 = (char*) &priority; + lustre_cfg_bufs_set_string(&bufs, 1, argv[1]); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs); + lcfg->lcfg_num = priority; + + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free (lcfg); if (rc < 0) { fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); } - return rc; } int jt_lcfg_del_conn(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; int rc; if (argc != 2) @@ -688,16 +689,18 @@ int jt_lcfg_del_conn(int argc, char **argv) fprintf(stderr, "%s: please use 'cfg_device name' to set the " "device name for config commands.\n", jt_cmdname(argv[0])); - return -EINVAL; + return -EINVAL; } - LCFG_INIT(lcfg, LCFG_DEL_CONN, lcfg_devname); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); /* connection uuid */ - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; + lustre_cfg_bufs_set_string(&bufs, 1, argv[1]); + + lcfg = lustre_cfg_new(LCFG_DEL_CONN, &bufs); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) { fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); @@ -708,7 +711,8 @@ int jt_lcfg_del_conn(int argc, char **argv) int jt_lcfg_set_security(int argc, char **argv) { - struct lustre_cfg lcfg; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; int rc; if (argc != 3) @@ -721,7 +725,7 @@ int jt_lcfg_set_security(int argc, char **argv) return -EINVAL; } - LCFG_INIT(lcfg, LCFG_SET_SECURITY, lcfg_devname); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); /* currently only used to set on mds */ if (strcmp(argv[1], "mds_mds_sec") && strcmp(argv[1], "mds_ost_sec")) { @@ -736,12 +740,12 @@ int jt_lcfg_set_security(int argc, char **argv) } /* connection uuid */ - lcfg.lcfg_inllen1 = strlen(argv[1]) + 1; - lcfg.lcfg_inlbuf1 = argv[1]; - lcfg.lcfg_inllen2 = strlen(argv[2]) + 1; - lcfg.lcfg_inlbuf2 = argv[2]; + lustre_cfg_bufs_set_string(&bufs, 1, argv[1]); + lustre_cfg_bufs_set_string(&bufs, 2, argv[2]); + lcfg = lustre_cfg_new(LCFG_SET_SECURITY, &bufs); - rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg); + rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg); + lustre_cfg_free(lcfg); if (rc < 0) { fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), strerror(rc = errno)); diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index c56ae41..ebed1b3 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -142,33 +142,22 @@ int obd_record(enum cfg_record_type type, int len, void *ptr) int lcfg_ioctl(char * func, int dev_id, struct lustre_cfg *lcfg) { int opc; - char lcfg_rawbuf[8192]; - char * lcfg_buf= lcfg_rawbuf; struct obd_ioctl_data data; - int len; int rc; - memset(lcfg_buf, 0, sizeof(lcfg_rawbuf)); - if (lustre_cfg_pack(lcfg, &lcfg_buf, sizeof(lcfg_rawbuf), &len)) { - fprintf(stderr, "error: %s: invalid ioctl\n", - jt_cmdname(func)); - return -2; - } - IOC_INIT(data); data.ioc_type = LUSTRE_CFG_TYPE; - data.ioc_plen1 = len; - data.ioc_pbuf1 = lcfg_buf; + data.ioc_plen1 = lustre_cfg_len(lcfg->lcfg_bufcount, + lcfg->lcfg_buflens); + data.ioc_pbuf1 = (void *)lcfg; IOC_PACK(func, data); - if (jt_recording) + if (jt_recording) { opc = OBD_IOC_DORECORD; - else + } else { opc = OBD_IOC_PROCESS_CFG; - + } rc = l_ioctl(dev_id, opc, buf); - if (rc == 0) - rc = lustre_cfg_unpack(lcfg, lcfg_buf, sizeof(lcfg_rawbuf)); return rc; }