From 317b1f984140b97d049fef85e5374da42503c1ae Mon Sep 17 00:00:00 2001 From: yangsheng Date: Mon, 2 Mar 2009 07:02:02 +0000 Subject: [PATCH] Branch b1_8 b=17594 i=bobijam, deen Coverity fixes. Author: Jim Garlick(LLNL). --- lustre/ldlm/ldlm_lockd.c | 2 +- lustre/ldlm/ldlm_request.c | 5 +++-- lustre/ldlm/ldlm_resource.c | 1 - lustre/llite/dcache.c | 14 +++++++++----- lustre/llite/file.c | 3 +-- lustre/llite/namei.c | 12 ++++++++---- lustre/llite/rw.c | 9 ++++----- lustre/lov/lov_obd.c | 6 +++--- lustre/mds/handler.c | 8 +++----- lustre/mgs/mgs_handler.c | 1 + lustre/obdclass/llog_obd.c | 3 ++- lustre/obdfilter/filter.c | 6 +++--- lustre/osc/osc_request.c | 7 +++++-- lustre/tests/iopentest2.c | 3 +-- lustre/tests/it_test.c | 6 ++---- lustre/tests/multiop.c | 6 ++++++ lustre/tests/writemany.c | 4 +++- lustre/utils/lustre_cfg.c | 24 ------------------------ lustre/utils/mkfs_lustre.c | 5 +++++ lustre/utils/mount_lustre.c | 29 +++++++++++++++++++++++------ 20 files changed, 83 insertions(+), 71 deletions(-) diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index 6c984b0..6cf98a7 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -902,7 +902,7 @@ int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data) int rc = 0; ENTRY; - LASSERT(lock != NULL); + LASSERT(lock != NULL && lock->l_export != NULL); req = ptlrpc_prep_req(lock->l_export->exp_imp_reverse, LUSTRE_DLM_VERSION, LDLM_GL_CALLBACK, 2, size, diff --git a/lustre/ldlm/ldlm_request.c b/lustre/ldlm/ldlm_request.c index d2b2985..cafd530 100644 --- a/lustre/ldlm/ldlm_request.c +++ b/lustre/ldlm/ldlm_request.c @@ -966,9 +966,8 @@ int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *cancels, int count) { struct ptlrpc_request *req = NULL; - struct ldlm_request *body; __u32 size[2] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body), - [DLM_LOCKREQ_OFF] = sizeof(*body) }; + [DLM_LOCKREQ_OFF] = sizeof(struct ldlm_request) }; struct obd_import *imp; int free, sent = 0; int rc = 0; @@ -1007,8 +1006,10 @@ int ldlm_cli_cancel_req(struct obd_export *exp, req->rq_reply_portal = LDLM_CANCEL_REPLY_PORTAL; ptlrpc_at_set_req_timeout(req); + /* body = lustre_msg_buf(req->rq_reqmsg, DLM_LOCKREQ_OFF, sizeof(*body)); + */ ldlm_cancel_pack(req, DLM_LOCKREQ_OFF, cancels, count); ptlrpc_req_set_repsize(req, 1, NULL); diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 7dff082..9857485 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -655,7 +655,6 @@ void ldlm_namespace_free(struct ldlm_namespace *ns, void ldlm_namespace_get_locked(struct ldlm_namespace *ns) { - LASSERT(ns->ns_refcount >= 0); ns->ns_refcount++; } diff --git a/lustre/llite/dcache.c b/lustre/llite/dcache.c index fd0d52b..1692859 100644 --- a/lustre/llite/dcache.c +++ b/lustre/llite/dcache.c @@ -726,16 +726,20 @@ int ll_revalidate_nd(struct dentry *dentry, struct nameidata *nd) (struct ptlrpc_request *) it->d.lustre.it_data); } else { - struct file *filp; - - nd->intent.open.file->private_data = it; - filp = lookup_instantiate_filp(nd, dentry,NULL); #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)) /* 2.6.1[456] have a bug in open_namei() that forgets to check * nd->intent.open.file for error, so we need to return it as lookup's result * instead */ - if (IS_ERR(filp)) + struct file *filp; + + nd->intent.open.file->private_data = it; + filp = lookup_instantiate_filp(nd, dentry,NULL); + if (IS_ERR(filp)) { rc = 0; + } +#else + nd->intent.open.file->private_data = it; + (void)lookup_instantiate_filp(nd, dentry,NULL); #endif } #else diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 87875ca..a315983 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -2510,7 +2510,7 @@ static int ll_file_join(struct inode *head, struct file *filp, struct file *tail_filp, *first_filp, *second_filp; struct ll_lock_tree first_tree, second_tree; struct ll_lock_tree_node *first_node, *second_node; - struct ll_inode_info *hlli = ll_i2info(head), *tlli; + struct ll_inode_info *hlli = ll_i2info(head); int rc = 0, cleanup_phase = 0; ENTRY; @@ -2525,7 +2525,6 @@ static int ll_file_join(struct inode *head, struct file *filp, } tail = igrab(tail_filp->f_dentry->d_inode); - tlli = ll_i2info(tail); tail_dentry = tail_filp->f_dentry; LASSERT(tail_dentry); cleanup_phase = 1; diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 5b0c8bc..fa2aa10 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -696,19 +696,23 @@ static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry, (struct ptlrpc_request *) it->d.lustre.it_data); } else { - struct file *filp; - nd->intent.open.file->private_data = it; - filp =lookup_instantiate_filp(nd,dentry, - NULL); #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)) /* 2.6.1[456] have a bug in open_namei() that forgets to check * nd->intent.open.file for error, so we need to return it as lookup's result * instead */ + struct file *filp; + nd->intent.open.file->private_data = it; + filp =lookup_instantiate_filp(nd,dentry, + NULL); if (IS_ERR(filp)) { if (de) dput(de); de = (struct dentry *) filp; } +#else + nd->intent.open.file->private_data = it; + (void)lookup_instantiate_filp(nd,dentry, + NULL); #endif } diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index c81b504..22e661e 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -1761,16 +1761,15 @@ static void ras_stride_increase_window(struct ll_readahead_state *ras, unsigned long stride_len; LASSERT(ras->ras_stride_length > 0); + LASSERTF(ras->ras_window_start + ras->ras_window_len + >= ras->ras_stride_offset, "window_start %lu, window_len %lu" + " stride_offset %lu\n", ras->ras_window_start, + ras->ras_window_len, ras->ras_stride_offset); stride_len = ras->ras_window_start + ras->ras_window_len - ras->ras_stride_offset; - LASSERTF(stride_len >= 0, "window_start %lu, window_len %lu" - " stride_offset %lu\n", ras->ras_window_start, - ras->ras_window_len, ras->ras_stride_offset); - left = stride_len % ras->ras_stride_length; - window_len = ras->ras_window_len - left; if (left < ras->ras_stride_pages) diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index a70a1b5..9b8b014 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -2112,7 +2112,7 @@ static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm, struct obd_info oinfo; struct lov_request *req; struct list_head *pos; - struct lov_obd *lov = &exp->exp_obd->u.lov; + struct lov_obd *lov; struct lustre_handle *lov_lockhp; int lov_flags, rc = 0; ENTRY; @@ -2188,7 +2188,7 @@ static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm, struct obd_info oinfo; struct lov_request *req; struct list_head *pos; - struct lov_obd *lov = &exp->exp_obd->u.lov; + struct lov_obd *lov; struct lustre_handle *lov_lockhp; ldlm_mode_t this_mode; int err = 0, rc = 0; @@ -2740,7 +2740,7 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key, GOTO(out, rc = -EINVAL); /* If OST is inactive, return extent with UNKNOWN flag */ - if (lov && !lov->lov_tgts[ost_index]->ltd_active) { + if (!lov->lov_tgts[ost_index]->ltd_active) { fm_local->fm_flags |= FIEMAP_EXTENT_LAST; fm_local->fm_mapped_extents = 1; diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 92fc846..e26e4aa 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -1588,9 +1588,8 @@ int mds_handle(struct ptlrpc_request *req) OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0); rc = target_handle_connect(req, mds_handle); if (!rc) { - /* Now that we have an export, set mds. */ + /* Now that we have an export, set obd. */ obd = req->rq_export->exp_obd; - mds = mds_req2mds(req); } break; @@ -1681,9 +1680,8 @@ int mds_handle(struct ptlrpc_request *req) __swab32s(&opc); DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc, - (opc < sizeof(reint_names) / sizeof(reint_names[0]) || - reint_names[opc] == NULL) ? reint_names[opc] : - "unknown opcode"); + (opc < REINT_MAX) ? reint_names[opc] : + "unknown opcode"); switch (opc) { case REINT_CREATE: diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 46ef023..2718f52 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -401,6 +401,7 @@ static int mgs_handle_target_reg(struct ptlrpc_request *req) mti = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*mti), lustre_swab_mgs_target_info); + LASSERT(mti); if (!(mti->mti_flags & (LDD_F_WRITECONF | LDD_F_UPGRADE14 | LDD_F_UPDATE))) { diff --git a/lustre/obdclass/llog_obd.c b/lustre/obdclass/llog_obd.c index b03b3f6..e2be6c8 100644 --- a/lustre/obdclass/llog_obd.c +++ b/lustre/obdclass/llog_obd.c @@ -109,7 +109,7 @@ EXPORT_SYMBOL(__llog_ctxt_put); int llog_cleanup(struct llog_ctxt *ctxt) { struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); - struct obd_device *obd = ctxt->loc_obd; + struct obd_device *obd; int rc, idx; ENTRY; @@ -117,6 +117,7 @@ int llog_cleanup(struct llog_ctxt *ctxt) CERROR("No ctxt\n"); RETURN(-ENODEV); } + obd = ctxt->loc_obd; /*banlance the ctxt get when calling llog_cleanup */ llog_ctxt_put(ctxt); diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index adf455a..6d4e6cc 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -479,13 +479,13 @@ static int filter_client_free(struct obd_export *exp) if (strcmp(fed->fed_lcd->lcd_uuid, obd->obd_uuid.uuid ) == 0) GOTO(free, 0); - CDEBUG(D_INFO, "freeing client at idx %u, offset %lld with UUID '%s'\n", - fed->fed_lr_idx, fed->fed_lr_off, fed->fed_lcd->lcd_uuid); - LASSERT(filter->fo_last_rcvd_slots != NULL); off = fed->fed_lr_off; + CDEBUG(D_INFO, "freeing client at idx %u, offset %lld with UUID '%s'\n", + fed->fed_lr_idx, fed->fed_lr_off, fed->fed_lcd->lcd_uuid); + /* Don't clear fed_lr_idx here as it is likely also unset. At worst * we leak a client slot that will be cleaned on the next recovery. */ if (off <= 0) { diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index c5b0fc5..57a0586 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -1729,15 +1729,18 @@ static int osc_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo, struct obdo *saved_oa = NULL; struct brw_page **ppga, **orig; struct obd_import *imp = class_exp2cliimp(exp); - struct client_obd *cli = &imp->imp_obd->u.cli; + struct client_obd *cli; int rc, page_count_orig; ENTRY; + LASSERT((imp != NULL) && (imp->imp_obd != NULL)); + cli = &imp->imp_obd->u.cli; + if (cmd & OBD_BRW_CHECK) { /* The caller just wants to know if there's a chance that this * I/O can succeed */ - if (imp == NULL || imp->imp_invalid) + if (imp->imp_invalid) RETURN(-EIO); RETURN(0); } diff --git a/lustre/tests/iopentest2.c b/lustre/tests/iopentest2.c index d38d395..396bb3f 100644 --- a/lustre/tests/iopentest2.c +++ b/lustre/tests/iopentest2.c @@ -95,13 +95,12 @@ static char *get_iname(char *fname, const char *mtpt) int main(int argc, char *argv[]) { - char *fname, *mtpt, *pname; + char *fname, *mtpt; char *fname_iname, *dir; char *dir_iname = NULL, *foo = NULL, *bar = NULL; int rc, fd, i, thread = 0; int pidlist[10]; - pname = strdup(argv[0]); progname = basename(argv[0]); if (argc != 2) { diff --git a/lustre/tests/it_test.c b/lustre/tests/it_test.c index adaccde..a2997a7 100644 --- a/lustre/tests/it_test.c +++ b/lustre/tests/it_test.c @@ -84,11 +84,9 @@ static enum interval_iter cb(struct interval_node *n, void *args) static int count = 1; if (node->hit == 1) { - dprintf("NODE "__S" has ever been accessed\n", - __F(&n->in_extent)); + error("A duplicate node "__S" access found\n", + __F(&n->in_extent)); return INTERVAL_ITER_CONT; - error("duplicate node accessing found\n"); - return INTERVAL_ITER_STOP; } if (node->valid == 0) { diff --git a/lustre/tests/multiop.c b/lustre/tests/multiop.c index 946fe05..c7be929 100755 --- a/lustre/tests/multiop.c +++ b/lustre/tests/multiop.c @@ -185,6 +185,7 @@ int main(int argc, char **argv) exit(1); } + memset(&st, 0, sizeof(st)); signal(SIGUSR1, usr1_handler); fname = argv[1]; @@ -263,6 +264,11 @@ int main(int argc, char **argv) } break; case 'M': + if (st.st_size == 0) { + fprintf(stderr, "mmap without preceeding stat, or on" + " zero length file.\n"); + exit(-1); + } mmap_len = st.st_size; mmap_ptr = mmap(NULL, mmap_len, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0); diff --git a/lustre/tests/writemany.c b/lustre/tests/writemany.c index c9db9f9..707ab8d 100644 --- a/lustre/tests/writemany.c +++ b/lustre/tests/writemany.c @@ -178,6 +178,7 @@ int run_one_child(char *file, int thread, int seconds) maxrand *= 10; gettimeofday(&start, NULL); + cur = start; while(!rc) { if (usr1_received) @@ -233,7 +234,8 @@ int run_one_child(char *file, int thread, int seconds) printf("%s: %7ld files, %4ld MB in %.2fs (%7.2f files/s, " "%5.2f MB/s): rc = %d\n", cmdname, nfiles, nbytes >> 20, diff, - (double)nfiles / diff, (double)nbytes/1024/1024 / diff, + diff == 0 ? (double)0 : (double)nfiles / diff, + diff == 0 ? (double)0 : (double)nbytes/1024/1024 / diff, rc); return rc; diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 36608d3..e352eec 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -366,36 +366,12 @@ int jt_lcfg_del_mount_option(int argc, char **argv) int jt_lcfg_set_timeout(int argc, char **argv) { - int rc; - struct lustre_cfg_bufs bufs; - struct lustre_cfg *lcfg; - fprintf(stderr, "%s has been deprecated. Use conf_param instead.\n" "e.g. conf_param lustre-MDT0000 obd_timeout=50\n", jt_cmdname(argv[0])); return CMD_HELP; - - - if (argc != 2) - return CMD_HELP; - - 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_mgs_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_bufs bufs; diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index 6835d05..8b772e4 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -1080,6 +1080,11 @@ static char *convert_hostnames(char *s1) lnet_nid_t nid; converted = malloc(left); + if (converted == NULL) { + fprintf(stderr, "out of memory: needed %d bytes\n", + MAXNIDSTR); + return NULL; + } end = s1 + strlen(s1); c = converted; while ((left > 0) && (s1 < end)) { diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 25c12f4..157182b 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -162,6 +162,11 @@ static char *convert_hostnames(char *s1) lnet_nid_t nid; converted = malloc(left); + if (converted == NULL) { + fprintf(stderr, "out of memory: needed %d bytes\n", + MAXNIDSTR); + return NULL; + } c = converted; while ((left > 0) && (*s1 != '/')) { s2 = strpbrk(s1, ",:"); @@ -327,7 +332,7 @@ int set_tunables(char *source, int src_len) glob_t glob_info; struct stat stat_buf; char *chk_major, *chk_minor; - char *savept, *dev, *s2 = 0; + char *savept, *dev; char *ret_path; char buf[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'}; char real_path[PATH_MAX] = {'\0'}; @@ -350,7 +355,7 @@ int set_tunables(char *source, int src_len) if (strncmp(real_path, "/dev/loop", 9) == 0) return 0; - if ((real_path[0] != '/') && ((s2 = strpbrk(real_path, ",:")) != NULL)) + if ((real_path[0] != '/') && (strpbrk(real_path, ",:") != NULL)) return 0; dev = real_path + src_len - 1; @@ -514,7 +519,15 @@ int main(int argc, char *const argv[]) } usource = argv[optind]; + if (!usource) { + usage(stderr); + } + source = convert_hostnames(usource); + if (!source) { + usage(stderr); + } + target = argv[optind + 1]; ptr = target + strlen(target) - 1; while ((ptr > target) && (*ptr == '/')) { @@ -522,10 +535,6 @@ int main(int argc, char *const argv[]) ptr--; } - if (!usource || !source) { - usage(stderr); - } - if (verbose) { for (i = 0; i < argc; i++) printf("arg[%d] = %s\n", i, argv[i]); @@ -534,6 +543,10 @@ int main(int argc, char *const argv[]) } options = malloc(strlen(orig_options) + 1); + if (options == NULL) { + fprintf(stderr, "can't allocate memory for options\n"); + return -1; + } strcpy(options, orig_options); rc = parse_options(options, &flags); if (rc) { @@ -572,6 +585,10 @@ int main(int argc, char *const argv[]) functions. So we'll stick it on the end of the options. */ optlen = strlen(options) + strlen(",device=") + strlen(source) + 1; optcopy = malloc(optlen); + if (optcopy == NULL) { + fprintf(stderr, "can't allocate memory to optcopy\n"); + return -1; + } strcpy(optcopy, options); if (*optcopy) strcat(optcopy, ","); -- 1.8.3.1