From cf4180615577365d562669db7a4dc6e76c26a15b Mon Sep 17 00:00:00 2001 From: shadow Date: Wed, 2 Jul 2008 06:28:05 +0000 Subject: [PATCH] cleanup usage obd_set_info_async, obd_get_info. fix KEY_IS macro Branch b1_8 b=14032 i=johann i=deen --- lustre/include/obd.h | 24 +++++++++++++++++++----- lustre/include/obd_support.h | 3 ++- lustre/liblustre/rw.c | 2 +- lustre/liblustre/super.c | 4 ++-- lustre/llite/dir.c | 2 +- lustre/llite/file.c | 2 +- lustre/llite/llite_lib.c | 14 +++++++------- lustre/llite/lproc_llite.c | 2 +- lustre/lov/lov_obd.c | 8 ++++---- lustre/lov/lov_pack.c | 2 +- lustre/mdc/mdc_request.c | 7 +++---- lustre/mds/handler.c | 2 +- lustre/mds/lproc_mds.c | 4 ++-- lustre/mds/mds_lov.c | 1 - lustre/mds/mds_reint.c | 4 ++-- lustre/mgc/mgc_request.c | 6 +++--- lustre/obdclass/obd_mount.c | 10 +++++----- lustre/obdfilter/filter.c | 6 +++--- lustre/osc/osc_request.c | 8 ++++---- lustre/ost/ost_handler.c | 2 +- lustre/ptlrpc/import.c | 2 +- 21 files changed, 64 insertions(+), 51 deletions(-) diff --git a/lustre/include/obd.h b/lustre/include/obd.h index e3458cb..5f8cf4d 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -883,13 +883,27 @@ enum obd_cleanup_stage { }; /* get/set_info keys */ -#define KEY_MDS_CONN "mds_conn" -#define KEY_NEXT_ID "next_id" -#define KEY_LOVDESC "lovdesc" -#define KEY_INIT_RECOV "initial_recov" -#define KEY_INIT_RECOV_BACKUP "init_recov_bk" +#define KEY_MDS_CONN "mds_conn" +#define KEY_NEXT_ID "next_id" +#define KEY_LOVDESC "lovdesc" +#define KEY_INIT_RECOV "initial_recov" +#define KEY_INIT_RECOV_BACKUP "init_recov_bk" #define KEY_LOV_IDX "lov_idx" #define KEY_LAST_ID "last_id" +#define KEY_LOCK_TO_STRIPE "lock_to_stripe" +#define KEY_CHECKSUM "checksum" +#define KEY_READONLY "readonly" +#define KEY_UNLINKED "unlinked" +#define KEY_EVICT_BY_NID "evict_by_nid" +#define KEY_REGISTER_TARGET "register_target" +#define KEY_SET_FS "set_fs" +#define KEY_CLEAR_FS "clear_fs" +#define KEY_SET_INFO "set_info" +#define KEY_BLOCKSIZE "blocksize" +#define KEY_BLOCKSIZE_BITS "blocksize_bits" +#define KEY_MAX_EASIZE "max_ea_size" +/* XXX unused */ +#define KEY_ASYNC "async" struct obd_ops { struct module *o_owner; diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h index e7f1e0a..6ceb9cc 100644 --- a/lustre/include/obd_support.h +++ b/lustre/include/obd_support.h @@ -618,7 +618,8 @@ do { \ #define OBD_SLAB_FREE_PTR(ptr, slab) \ OBD_SLAB_FREE((ptr), (slab), sizeof *(ptr)) -#define KEY_IS(str) (keylen >= strlen(str) && strcmp(key, str) == 0) +#define KEY_IS(str) \ + (keylen >= (sizeof(str) - 1) && memcmp(key, str, sizeof(str) - 1) == 0) /* Wrapper for contiguous page frame allocation */ #define OBD_PAGES_ALLOC(ptr, order, gfp_mask) \ diff --git a/lustre/liblustre/rw.c b/lustre/liblustre/rw.c index e096a0e..e49d518 100644 --- a/lustre/liblustre/rw.c +++ b/lustre/liblustre/rw.c @@ -94,7 +94,7 @@ static int llu_lock_to_stripe_offset(struct inode *inode, struct ldlm_lock *lock char name[16]; struct ldlm_lock *lock; struct lov_stripe_md *lsm; - } key = { .name = "lock_to_stripe", .lock = lock, .lsm = lsm }; + } key = { .name = KEY_LOCK_TO_STRIPE, .lock = lock, .lsm = lsm }; __u32 stripe, vallen = sizeof(stripe); int rc; ENTRY; diff --git a/lustre/liblustre/super.c b/lustre/liblustre/super.c index 24b4058..baf8ed9 100644 --- a/lustre/liblustre/super.c +++ b/lustre/liblustre/super.c @@ -1934,7 +1934,7 @@ llu_fsswop_mount(const char *source, CERROR("MDC %s: not setup or attached\n", mdc); GOTO(out_free, err = -EINVAL); } - obd_set_info_async(obd->obd_self_export, strlen("async"), "async", + obd_set_info_async(obd->obd_self_export, sizeof(KEY_ASYNC), KEY_ASYNC, sizeof(async), &async, NULL); ocd.ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_VERSION | @@ -1967,7 +1967,7 @@ llu_fsswop_mount(const char *source, CERROR("OSC %s: not setup or attached\n", osc); GOTO(out_mdc, err = -EINVAL); } - obd_set_info_async(obd->obd_self_export, strlen("async"), "async", + obd_set_info_async(obd->obd_self_export, sizeof(KEY_ASYNC), KEY_ASYNC, sizeof(async), &async, NULL); obd->obd_upcall.onu_owner = &sbi->ll_lco; diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 31e59da..323bebd 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -430,7 +430,7 @@ int ll_send_mgc_param(struct obd_export *mgc, char *string) return -ENOMEM; strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN); - rc = obd_set_info_async(mgc, strlen(KEY_SET_INFO), KEY_SET_INFO, + rc = obd_set_info_async(mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO, sizeof(struct mgs_send_param), msp, NULL); if (rc) CERROR("Failed to set parameter: %d\n", rc); diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 825628a..2031dc4 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -646,7 +646,7 @@ static int ll_lock_to_stripe_offset(struct inode *inode, struct ldlm_lock *lock) char name[16]; struct ldlm_lock *lock; struct lov_stripe_md *lsm; - } key = { .name = "lock_to_stripe", .lock = lock, .lsm = lsm }; + } key = { .name = KEY_LOCK_TO_STRIPE, .lock = lock, .lsm = lsm }; __u32 stripe, vallen = sizeof(stripe); int rc; ENTRY; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 65fe307..669c50d 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -408,8 +408,8 @@ static int client_common_fill_super(struct super_block *sb, } checksum = sbi->ll_flags & LL_SBI_DATA_CHECKSUM; - err = obd_set_info_async(sbi->ll_osc_exp, strlen("checksum"), - "checksum", sizeof(checksum), + err = obd_set_info_async(sbi->ll_osc_exp, sizeof(KEY_CHECKSUM), + KEY_CHECKSUM, sizeof(checksum), &checksum, NULL); /* making vm readahead 0 for 2.4.x. In the case of 2.6.x, @@ -455,8 +455,8 @@ int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize) *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL); size = sizeof(int); - rc = obd_get_info(sbi->ll_mdc_exp, strlen("max_easize"), "max_easize", - &size, lmmsize); + rc = obd_get_info(sbi->ll_mdc_exp, sizeof(KEY_MAX_EASIZE), + KEY_MAX_EASIZE, &size, lmmsize); if (rc) CERROR("Get max mdsize error rc %d \n", rc); @@ -912,7 +912,7 @@ static int old_lustre_process_log(struct super_block *sb, char *newprofile, /* Try all connections, but only once. */ rc = obd_set_info_async(obd->obd_self_export, - strlen("init_recov_bk"), "init_recov_bk", + sizeof(KEY_INIT_RECOV_BACKUP), KEY_INIT_RECOV_BACKUP, sizeof(recov_bk), &recov_bk, NULL); if (rc) GOTO(out_cleanup, rc); @@ -2026,8 +2026,8 @@ int ll_remount_fs(struct super_block *sb, int *flags, char *data) if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) { read_only = *flags & MS_RDONLY; - err = obd_set_info_async(sbi->ll_mdc_exp, strlen("read-only"), - "read-only", sizeof(read_only), + err = obd_set_info_async(sbi->ll_mdc_exp, sizeof(KEY_READONLY), + KEY_READONLY, sizeof(read_only), &read_only, NULL); if (err) { CERROR("Failed to change the read-only flag during " diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index b5a306b..9a735c8 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -344,7 +344,7 @@ static int ll_wr_checksum(struct file *file, const char *buffer, else sbi->ll_flags &= ~(LL_SBI_LLITE_CHECKSUM|LL_SBI_DATA_CHECKSUM); - rc = obd_set_info_async(sbi->ll_osc_exp, strlen("checksum"), "checksum", + rc = obd_set_info_async(sbi->ll_osc_exp, sizeof(KEY_CHECKSUM), KEY_CHECKSUM, sizeof(val), &val, NULL); if (rc) CWARN("Failed to set OSC checksum flags: %d\n", rc); diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index d3d2626..222de1d 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -2467,7 +2467,7 @@ static int lov_get_info(struct obd_export *exp, __u32 keylen, lov_getref(obddev); - if (KEY_IS("lock_to_stripe")) { + if (KEY_IS(KEY_LOCK_TO_STRIPE)) { struct { char name[16]; struct ldlm_lock *lock; @@ -2565,11 +2565,11 @@ static int lov_set_info_async(struct obd_export *exp, obd_count keylen, incr = sizeof(struct obd_id_info); do_inactive = 1; next_id = 1; - } else if (KEY_IS("checksum")) { + } else if (KEY_IS(KEY_CHECKSUM)) { do_inactive = 1; - } else if (KEY_IS(KEY_MDS_CONN) || KEY_IS("unlinked")) { + } else if (KEY_IS(KEY_MDS_CONN) || KEY_IS(KEY_UNLINKED)) { check_uuid = val ? 1 : 0; - } else if (KEY_IS("evict_by_nid")) { + } else if (KEY_IS(KEY_EVICT_BY_NID)) { /* use defaults: do_inactive = incr = 0; */ diff --git a/lustre/lov/lov_pack.c b/lustre/lov/lov_pack.c index ba8663b..aea018f 100644 --- a/lustre/lov/lov_pack.c +++ b/lustre/lov/lov_pack.c @@ -378,7 +378,7 @@ int lov_setea(struct obd_export *exp, struct lov_stripe_md **lsmp, for (i = 0; i < lump->lmm_stripe_count; i++) { __u32 len = sizeof(last_id); oexp = lov->lov_tgts[lump->lmm_objects[i].l_ost_idx]->ltd_exp; - rc = obd_get_info(oexp, strlen("last_id"), "last_id", + rc = obd_get_info(oexp, sizeof(KEY_LAST_ID), KEY_LAST_ID, &len, &last_id); if (rc) RETURN(rc); diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index d82f83f..0073231 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -918,7 +918,7 @@ int mdc_set_info_async(struct obd_export *exp, obd_count keylen, exp->exp_obd->obd_name, imp->imp_initial_recov_bk); RETURN(0); } - if (KEY_IS("read-only")) { + if (KEY_IS(KEY_READONLY)) { struct ptlrpc_request *req; int size[3] = { sizeof(struct ptlrpc_body), keylen, vallen }; char *bufs[3] = { NULL, key, val }; @@ -962,8 +962,7 @@ int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key, { int rc = -EINVAL; - if (keylen == strlen("max_easize") && - memcmp(key, "max_easize", strlen("max_easize")) == 0) { + if (KEY_IS(KEY_MAX_EASIZE)) { int mdsize, *max_easize; if (*vallen != sizeof(int)) @@ -1235,7 +1234,7 @@ int mdc_init_ea_size(struct obd_export *mdc_exp, struct obd_export *lov_exp) int rc, size; ENTRY; - rc = obd_get_info(lov_exp, strlen(KEY_LOVDESC) + 1, KEY_LOVDESC, + rc = obd_get_info(lov_exp, sizeof(KEY_LOVDESC), KEY_LOVDESC, &valsize, &desc); if (rc) RETURN(rc); diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 6486f05..26d3ce2 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -1364,7 +1364,7 @@ static int mds_set_info_rpc(struct obd_export *exp, struct ptlrpc_request *req) lustre_msg_set_status(req->rq_repmsg, 0); - if (KEY_IS("read-only")) { + if (KEY_IS(KEY_READONLY)) { if (val == NULL || vallen < sizeof(__u32)) { DEBUG_REQ(D_HA, req, "no set_info val"); RETURN(-EFAULT); diff --git a/lustre/mds/lproc_mds.c b/lustre/mds/lproc_mds.c index ba1562f..c2aacd7 100644 --- a/lustre/mds/lproc_mds.c +++ b/lustre/mds/lproc_mds.c @@ -90,8 +90,8 @@ static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer, return -ENOMEM; if (obd->u.mds.mds_evict_ost_nids) { - rc = obd_set_info_async(mds->mds_osc_exp,strlen("evict_by_nid"), - "evict_by_nid", strlen(tmpbuf + 4) + 1, + rc = obd_set_info_async(mds->mds_osc_exp,sizeof(KEY_EVICT_BY_NID), + KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1, tmpbuf + 4, set); if (rc) CERROR("Failed to evict nid %s from OSTs: rc %d\n", diff --git a/lustre/mds/mds_lov.c b/lustre/mds/mds_lov.c index 3495f3a..6116d34 100644 --- a/lustre/mds/mds_lov.c +++ b/lustre/mds/mds_lov.c @@ -353,7 +353,6 @@ static int mds_lov_set_one_nextid(struct obd_device * obd, __u32 idx, obd_id *id info.idx = idx; info.data = id; - rc = obd_set_info_async(mds->mds_osc_exp, sizeof(KEY_NEXT_ID), KEY_NEXT_ID, sizeof(info), &info, NULL); if (rc) diff --git a/lustre/mds/mds_reint.c b/lustre/mds/mds_reint.c index 57b9b7b..08af2f4 100644 --- a/lustre/mds/mds_reint.c +++ b/lustre/mds/mds_reint.c @@ -1790,8 +1790,8 @@ cleanup: rc = mds_finish_transno(mds, dparent ? dparent->d_inode : NULL, handle, req, rc, 0, 0); if (!rc) - (void)obd_set_info_async(mds->mds_osc_exp, strlen("unlinked"), - "unlinked", 0, NULL, NULL); + (void)obd_set_info_async(mds->mds_osc_exp, sizeof(KEY_UNLINKED), + KEY_UNLINKED, 0, NULL, NULL); switch(cleanup_phase) { case 5: /* pending_dir semaphore */ UNLOCK_INODE_MUTEX(mds->mds_pending_dir->d_inode); diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index e1ab586..9b06f72 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -828,7 +828,7 @@ int mgc_set_info_async(struct obd_export *exp, obd_count keylen, RETURN(0); } /* FIXME move this to mgc_process_config */ - if (KEY_IS("register_target")) { + if (KEY_IS(KEY_REGISTER_TARGET)) { struct mgs_target_info *mti; if (vallen != sizeof(struct mgs_target_info)) RETURN(-EINVAL); @@ -838,7 +838,7 @@ int mgc_set_info_async(struct obd_export *exp, obd_count keylen, rc = mgc_target_register(exp, mti); RETURN(rc); } - if (KEY_IS("set_fs")) { + if (KEY_IS(KEY_SET_FS)) { struct super_block *sb = (struct super_block *)val; struct lustre_sb_info *lsi; if (vallen != sizeof(struct super_block)) @@ -850,7 +850,7 @@ int mgc_set_info_async(struct obd_export *exp, obd_count keylen, } RETURN(rc); } - if (KEY_IS("clear_fs")) { + if (KEY_IS(KEY_CLEAR_FS)) { if (vallen != 0) RETURN(-EINVAL); rc = mgc_fs_cleanup(exp->exp_obd); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index ce82e45..aa97caa 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -593,7 +593,7 @@ static int lustre_start_mgc(struct super_block *sb) recov_bk++; CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk); rc = obd_set_info_async(obd->obd_self_export, - strlen(KEY_INIT_RECOV_BACKUP), + sizeof(KEY_INIT_RECOV_BACKUP), KEY_INIT_RECOV_BACKUP, sizeof(recov_bk), &recov_bk, NULL); GOTO(out, rc = 0); @@ -694,7 +694,7 @@ static int lustre_start_mgc(struct super_block *sb) /* Try all connections, but only once. */ recov_bk = 1; rc = obd_set_info_async(obd->obd_self_export, - strlen(KEY_INIT_RECOV_BACKUP), + sizeof(KEY_INIT_RECOV_BACKUP), KEY_INIT_RECOV_BACKUP, sizeof(recov_bk), &recov_bk, NULL); if (rc) @@ -813,7 +813,7 @@ static int server_mgc_set_fs(struct obd_device *mgc, struct super_block *sb) /* cl_mgc_sem in mgc insures we sleep if the mgc_fs is busy */ rc = obd_set_info_async(mgc->obd_self_export, - strlen("set_fs"), "set_fs", + sizeof(KEY_SET_FS), KEY_SET_FS, sizeof(*sb), sb, NULL); if (rc) { CERROR("can't set_fs %d\n", rc); @@ -830,7 +830,7 @@ static int server_mgc_clear_fs(struct obd_device *mgc) CDEBUG(D_MOUNT, "Unassign mgc disk\n"); rc = obd_set_info_async(mgc->obd_self_export, - strlen("clear_fs"), "clear_fs", + sizeof(KEY_CLEAR_FS), KEY_CLEAR_FS, 0, NULL, NULL); RETURN(rc); } @@ -958,7 +958,7 @@ int server_register_target(struct super_block *sb) /* Register the target */ /* FIXME use mgc_process_config instead */ rc = obd_set_info_async(mgc->u.cli.cl_mgc_mgsexp, - strlen("register_target"), "register_target", + sizeof(KEY_REGISTER_TARGET), KEY_REGISTER_TARGET, sizeof(*mti), mti, NULL); if (rc) GOTO(out, rc); diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 5ccfb0f..1e991ba 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -3458,7 +3458,7 @@ static int filter_get_info(struct obd_export *exp, __u32 keylen, RETURN(-EINVAL); } - if (KEY_IS("blocksize")) { + if (KEY_IS(KEY_BLOCKSIZE)) { __u32 *blocksize = val; if (blocksize) { if (*vallen < sizeof(*blocksize)) @@ -3469,7 +3469,7 @@ static int filter_get_info(struct obd_export *exp, __u32 keylen, RETURN(0); } - if (KEY_IS("blocksize_bits")) { + if (KEY_IS(KEY_BLOCKSIZE_BITS)) { __u32 *blocksize_bits = val; if (blocksize_bits) { if (*vallen < sizeof(*blocksize_bits)) @@ -3480,7 +3480,7 @@ static int filter_get_info(struct obd_export *exp, __u32 keylen, RETURN(0); } - if (KEY_IS("last_id")) { + if (KEY_IS(KEY_LAST_ID)) { obd_id *last_id = val; /* FIXME: object groups */ if (last_id) { diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index 841c9e6..00a3e9a 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -3458,12 +3458,12 @@ static int osc_get_info(struct obd_export *exp, obd_count keylen, if (!vallen || !val) RETURN(-EFAULT); - if (KEY_IS("lock_to_stripe")) { + if (KEY_IS(KEY_LOCK_TO_STRIPE)) { __u32 *stripe = val; *vallen = sizeof(*stripe); *stripe = 0; RETURN(0); - } else if (KEY_IS("last_id")) { + } else if (KEY_IS(KEY_LAST_ID)) { struct ptlrpc_request *req; obd_id *reply; char *bufs[2] = { NULL, key }; @@ -3547,7 +3547,7 @@ static int osc_set_info_async(struct obd_export *exp, obd_count keylen, RETURN(0); } - if (KEY_IS("unlinked")) { + if (KEY_IS(KEY_UNLINKED)) { struct osc_creator *oscc = &obd->u.cli.cl_oscc; spin_lock(&oscc->oscc_lock); oscc->oscc_flags &= ~OSCC_FLAG_NOSPC; @@ -3567,7 +3567,7 @@ static int osc_set_info_async(struct obd_export *exp, obd_count keylen, RETURN(0); } - if (KEY_IS("checksum")) { + if (KEY_IS(KEY_CHECKSUM)) { if (vallen != sizeof(int)) RETURN(-EINVAL); exp->exp_obd->u.cli.cl_checksum = (*(int *)val) ? 1 : 0; diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c index 76c4228..f2a43ea 100644 --- a/lustre/ost/ost_handler.c +++ b/lustre/ost/ost_handler.c @@ -1294,7 +1294,7 @@ static int ost_set_info(struct obd_export *exp, struct ptlrpc_request *req) if (vallen) val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0); - if (KEY_IS("evict_by_nid")) { + if (KEY_IS(KEY_EVICT_BY_NID)) { if (val && vallen) obd_export_evict_by_nid(exp->exp_obd, val); diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c index e65d145..3125de8 100644 --- a/lustre/ptlrpc/import.c +++ b/lustre/ptlrpc/import.c @@ -496,7 +496,7 @@ int ptlrpc_connect_import(struct obd_import *imp, char *new_uuid) /* Don't retry if connect fails */ rc = 0; obd_set_info_async(obd->obd_self_export, - strlen(KEY_INIT_RECOV), + sizeof(KEY_INIT_RECOV), KEY_INIT_RECOV, sizeof(rc), &rc, NULL); } -- 1.8.3.1