From d705a86078f700e4eb0e51d49fb19e55f8132782 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 21 Dec 2015 15:56:47 -0500 Subject: [PATCH] LU-6142 lnet: return proper error code It is consider bad style in the linux kernel to return -1 or a positive number for an error. Instead return the appropriate error codes. Change-Id: Icd9729de84f162b07df17caab48e7693459a03e8 Signed-off-by: James Simmons Reviewed-on: http://review.whamcloud.com/17626 Tested-by: Jenkins Reviewed-by: Doug Oucharek Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Oleg Drokin --- lnet/lnet/api-ni.c | 6 +++--- lnet/lnet/config.c | 6 +++--- lnet/lnet/lib-eq.c | 2 +- lnet/lnet/lib-move.c | 22 +++++++++++----------- lnet/lnet/nidstrings.c | 2 +- lnet/lnet/router.c | 6 +++--- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 0302f67..dd7e96a 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -1422,7 +1422,7 @@ int lnet_lib_init(void) CERROR("Can't have %d CPTs for LNet (max allowed is %d), " "please change setting of CPT-table and retry\n", the_lnet.ln_cpt_number, LNET_CPT_MAX); - return -1; + return -E2BIG; } while ((1 << the_lnet.ln_cpt_bits) < the_lnet.ln_cpt_number) @@ -1431,7 +1431,7 @@ int lnet_lib_init(void) rc = lnet_create_locks(); if (rc != 0) { CERROR("Can't create LNet global locks: %d\n", rc); - return -1; + return rc; } the_lnet.ln_refcount = 0; @@ -1946,7 +1946,7 @@ LNetCtl(unsigned int cmd, void *arg) net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk; if (net_config == NULL) - return -1; + return -EINVAL; return lnet_get_net_config(config->cfg_count, &config->cfg_ncpts, diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index 37340d9..b00267d 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -479,7 +479,7 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str) ltb = lnet_new_text_buf(nob); if (ltb == NULL) { lnet_free_text_bufs(&pending); - return -1; + return -ENOMEM; } for (i = 0; i < nob; i++) @@ -612,7 +612,7 @@ lnet_str2tbs_expand(struct list_head *tbs, char *str) failed: lnet_free_text_bufs(&pending); - return -1; + return -EINVAL; } static int @@ -646,7 +646,7 @@ lnet_parse_priority(char *str, unsigned int *priority, char **token) /* Update the caller's token pointer so it treats the found priority as the token to report in the error message. */ *token += sep - str + 1; - return -1; + return -EINVAL; } CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob); diff --git a/lnet/lnet/lib-eq.c b/lnet/lnet/lib-eq.c index d5cc380..91dbf08 100644 --- a/lnet/lnet/lib-eq.c +++ b/lnet/lnet/lib-eq.c @@ -331,7 +331,7 @@ __must_hold(&the_lnet.ln_eq_wait_lock) cfs_time_t now; if (tms == 0) - return -1; /* don't want to wait and no new event */ + return -ENXIO; /* don't want to wait and no new event */ init_waitqueue_entry(&wl, current); set_current_state(TASK_INTERRUPTIBLE); diff --git a/lnet/lnet/lib-move.c b/lnet/lnet/lib-move.c index 17a62c8..052548c 100644 --- a/lnet/lnet/lib-move.c +++ b/lnet/lnet/lib-move.c @@ -1149,30 +1149,30 @@ lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2) return 1; if (r1->lr_priority > r2->lr_priority) - return -1; + return -ERANGE; if (r1_hops < r2_hops) return 1; if (r1_hops > r2_hops) - return -1; + return -ERANGE; if (p1->lp_txqnob < p2->lp_txqnob) return 1; if (p1->lp_txqnob > p2->lp_txqnob) - return -1; + return -ERANGE; if (p1->lp_txcredits > p2->lp_txcredits) return 1; if (p1->lp_txcredits < p2->lp_txcredits) - return -1; + return -ERANGE; if (r1->lr_seq - r2->lr_seq <= 0) return 1; - return -1; + return -ERANGE; } static lnet_peer_t * @@ -1488,7 +1488,7 @@ lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg) libcfs_id2str(info.mi_id), info.mi_portal, info.mi_mbits, info.mi_roffset, info.mi_rlength, rc); - return ENOENT; /* +ve: OK but no match */ + return -ENOENT; /* -ve: OK but no match */ } } @@ -1520,7 +1520,7 @@ lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get) " offset %d length %d\n", libcfs_id2str(info.mi_id), info.mi_portal, info.mi_mbits, info.mi_roffset, info.mi_rlength); - return ENOENT; /* +ve: OK but no match */ + return -ENOENT; /* -ve: OK but no match */ } LASSERT(rc == LNET_MATCHMD_OK); @@ -1588,7 +1588,7 @@ lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg) md->md_me->me_portal); lnet_res_unlock(cpt); - return ENOENT; /* +ve: OK but no match */ + return -ENOENT; /* -ve: OK but no match */ } LASSERT (md->md_offset == 0); @@ -1604,7 +1604,7 @@ lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg) rlength, hdr->msg.reply.dst_wmd.wh_object_cookie, mlength); lnet_res_unlock(cpt); - return ENOENT; /* +ve: OK but no match */ + return -ENOENT; /* -ve: OK but no match */ } CDEBUG(D_NET, "%s: Reply from %s of length %d/%d into md "LPX64"\n", @@ -1657,7 +1657,7 @@ lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg) md->md_me->me_portal); lnet_res_unlock(cpt); - return ENOENT; /* +ve! */ + return -ENOENT; /* -ve! */ } CDEBUG(D_NET, "%s: ACK from %s into md "LPX64"\n", @@ -1726,7 +1726,7 @@ lnet_parse_local(lnet_ni_t *ni, lnet_msg_t *msg) return -EPROTO; } - LASSERT(rc == 0 || rc == ENOENT); + LASSERT(rc == 0 || rc == -ENOENT); return rc; } diff --git a/lnet/lnet/nidstrings.c b/lnet/lnet/nidstrings.c index 2995a72..95f485a 100644 --- a/lnet/lnet/nidstrings.c +++ b/lnet/lnet/nidstrings.c @@ -1086,7 +1086,7 @@ libcfs_str2lnd(const char *str) if (nf != NULL) return nf->nf_type; - return -1; + return -ENXIO; } EXPORT_SYMBOL(libcfs_str2lnd); diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index 4b47269..362af36 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -1488,7 +1488,7 @@ lnet_nrb_tiny_calculate(void) LCONSOLE_ERROR_MSG(0x10c, "tiny_router_buffers=%d invalid when " "routing enabled\n", tiny_router_buffers); - return -1; + return -EINVAL; } if (tiny_router_buffers > 0) @@ -1507,7 +1507,7 @@ lnet_nrb_small_calculate(void) LCONSOLE_ERROR_MSG(0x10c, "small_router_buffers=%d invalid when " "routing enabled\n", small_router_buffers); - return -1; + return -EINVAL; } if (small_router_buffers > 0) @@ -1526,7 +1526,7 @@ lnet_nrb_large_calculate(void) LCONSOLE_ERROR_MSG(0x10c, "large_router_buffers=%d invalid when " "routing enabled\n", large_router_buffers); - return -1; + return -EINVAL; } if (large_router_buffers > 0) -- 1.8.3.1