From: Shaun Tancheff Date: Sun, 24 Mar 2024 06:55:08 +0000 (+0700) Subject: LU-17592 build: kernel 6.8 removed strlcpy() X-Git-Tag: 2.15.63~83 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=7a0517fa25162a6af2e10827851d7d8c7a4ed1ac LU-17592 build: kernel 6.8 removed strlcpy() Linux commit v6.7-11707-gd26270061ae6 string: Remove strlcpy() strlcpy() is removed, use strscpy() and provide a strscpy() for kernels that do not have one. HPE-bug-id: LUS-12181 Signed-off-by: Shaun Tancheff Change-Id: Ieab872f20e08d17a4842bc944fa38f9867de81f9 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54227 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index a2e5ddb..ed1b29e 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -104,7 +104,7 @@ l_wait_condition||wait_event_idle \bMIN\(||min_t mdo2fid||mdd_object_fid mktemp||mkstemp -nla_strlcpy|nla_strscpy +nla_strlcpy||nla_strscpy OBD_FAILED||CFS_FAILED OBD_FAIL_CHECK||CFS_FAIL_CHECK OBD_FAIL_CHECK_ORSET||CFS_FAIL_CHECK_ORSET @@ -139,6 +139,7 @@ setup_timer||cfs_timer_setup sprintf||snprintf strcat||strncat strcpy||strncpy +strlcpy||strscpy struct timeval||struct timespec64 tempnam||mkstemp time_t||timeout_t diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 3048b6f..ba0c8d1 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -625,7 +625,9 @@ AC_DEFUN([LIBCFS_SRC_STRSCPY_EXISTS], [ LB2_LINUX_TEST_SRC([strscpy_exists], [ #include ],[ - strscpy((char *)NULL, (const char *)NULL, 0); + char buf[129]; + + strscpy(buf, "something", sizeof(buf)); ],[-Werror]) ]) AC_DEFUN([LIBCFS_STRSCPY_EXISTS], [ diff --git a/libcfs/include/libcfs/linux/linux-misc.h b/libcfs/include/libcfs/linux/linux-misc.h index 5936c78..f267ecb 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -204,7 +204,12 @@ static inline void *cfs_kallsyms_lookup_name(const char *name) #endif #ifndef HAVE_STRSCPY -#define strscpy(s1, s2, sz) strlcpy((s1), (s2), (sz)) +static inline ssize_t strscpy(char *s1, const char *s2, size_t sz) +{ + ssize_t len = strlcpy(s1, s2, sz); + + return (len >= sz) ? -E2BIG : len; +} #endif #ifndef HAVE_BITMAP_TO_ARR32 diff --git a/libcfs/libcfs/hash.c b/libcfs/libcfs/hash.c index 86f321b..34da19d 100644 --- a/libcfs/libcfs/hash.c +++ b/libcfs/libcfs/hash.c @@ -1068,7 +1068,7 @@ cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits, if (hs == NULL) RETURN(NULL); - strlcpy(hs->hs_name, name, len); + strscpy(hs->hs_name, name, len); hs->hs_flags = flags; kref_init(&hs->hs_refcount); diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 9c638a6b0..1a0ce6f 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -660,12 +660,12 @@ void libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata, debug_buf += sizeof(header); } - strlcpy(debug_buf, file, PAGE_SIZE - tage->used); + snprintf(debug_buf, PAGE_SIZE - tage->used, "%s", file); tage->used += strlen(file) + 1; debug_buf += strlen(file) + 1; if (fn) { - strlcpy(debug_buf, fn, PAGE_SIZE - tage->used); + snprintf(debug_buf, PAGE_SIZE - tage->used, "%s", fn); tage->used += strlen(fn) + 1; debug_buf += strlen(fn) + 1; } diff --git a/lnet/klnds/o2iblnd/o2iblnd.c b/lnet/klnds/o2iblnd/o2iblnd.c index 993525d..7a7ca38 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.c +++ b/lnet/klnds/o2iblnd/o2iblnd.c @@ -2276,15 +2276,15 @@ kiblnd_init_poolset(struct kib_poolset *ps, int cpt, memset(ps, 0, sizeof(struct kib_poolset)); ps->ps_cpt = cpt; - ps->ps_net = net; - ps->ps_pool_create = po_create; - ps->ps_pool_destroy = po_destroy; - ps->ps_node_init = nd_init; - ps->ps_node_fini = nd_fini; - ps->ps_pool_size = size; - if (strlcpy(ps->ps_name, name, sizeof(ps->ps_name)) - >= sizeof(ps->ps_name)) - return -E2BIG; + ps->ps_net = net; + ps->ps_pool_create = po_create; + ps->ps_pool_destroy = po_destroy; + ps->ps_node_init = nd_init; + ps->ps_node_fini = nd_fini; + ps->ps_pool_size = size; + rc = strscpy(ps->ps_name, name, sizeof(ps->ps_name)); + if (rc < 0) + return rc; spin_lock_init(&ps->ps_lock); INIT_LIST_HEAD(&ps->ps_pool_list); INIT_LIST_HEAD(&ps->ps_failed_pool_list); @@ -3736,7 +3736,7 @@ kiblnd_startup(struct lnet_ni *ni) } ibdev->ibd_ifip = ntohl(ifaces[i].li_ipaddr); - strlcpy(ibdev->ibd_ifname, ifaces[i].li_name, + strscpy(ibdev->ibd_ifname, ifaces[i].li_name, sizeof(ibdev->ibd_ifname)); ibdev->ibd_can_failover = ifaces[i].li_iff_master; diff --git a/lnet/klnds/socklnd/socklnd.c b/lnet/klnds/socklnd/socklnd.c index cbcfeb7..d187969 100644 --- a/lnet/klnds/socklnd/socklnd.c +++ b/lnet/klnds/socklnd/socklnd.c @@ -2633,7 +2633,7 @@ ksocknal_startup(struct lnet_ni *ni) ni->ni_nid.nid_size = 0; ni->ni_nid.nid_addr[0] = sa->sin_addr.s_addr; } - strlcpy(ksi->ksni_name, ifaces[if_idx].li_name, sizeof(ksi->ksni_name)); + strscpy(ksi->ksni_name, ifaces[if_idx].li_name, sizeof(ksi->ksni_name)); /* call it before add it to ksocknal_data.ksnd_nets */ rc = ksocknal_net_start_threads(net, ni->ni_cpts, ni->ni_ncpts); diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index 9fb59e8..85ba572 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -1573,7 +1573,7 @@ int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns, bool v6) ifaces[nip].li_index = dev->ifindex; ifaces[nip].li_ipaddr = ifa->ifa_local; ifaces[nip].li_netmask = ntohl(ifa->ifa_mask); - strlcpy(ifaces[nip].li_name, ifa->ifa_label, + strscpy(ifaces[nip].li_name, ifa->ifa_label, sizeof(ifaces[nip].li_name)); nip++; } @@ -1615,7 +1615,7 @@ int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns, bool v6) ifaces[nip].li_index = dev->ifindex; memcpy(ifaces[nip].li_ipv6addr, &ifa6->addr, sizeof(struct in6_addr)); - strlcpy(ifaces[nip].li_name, dev->name, + strscpy(ifaces[nip].li_name, dev->name, sizeof(ifaces[nip].li_name)); nip++; /* As different IPv6 addresses don't have unique diff --git a/lnet/selftest/conrpc.c b/lnet/selftest/conrpc.c index df5e09a..ba0d820 100644 --- a/lnet/selftest/conrpc.c +++ b/lnet/selftest/conrpc.c @@ -571,27 +571,27 @@ lstcon_sesrpc_prep(struct lstcon_node *nd, int transop, struct srpc_rmsn_reqst *rsrq; int rc; - switch (transop) { - case LST_TRANS_SESNEW: + switch (transop) { + case LST_TRANS_SESNEW: rc = lstcon_rpc_prep(nd, SRPC_SERVICE_MAKE_SESSION, feats, 0, 0, crpc); - if (rc != 0) - return rc; + if (rc != 0) + return rc; - msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst; + msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst; msrq->mksn_sid.ses_stamp = console_session.ses_id.ses_stamp; msrq->mksn_sid.ses_nid = lnet_nid_to_nid4(&console_session.ses_id.ses_nid); msrq->mksn_force = console_session.ses_force; - strlcpy(msrq->mksn_name, console_session.ses_name, + strscpy(msrq->mksn_name, console_session.ses_name, sizeof(msrq->mksn_name)); - break; + break; - case LST_TRANS_SESEND: + case LST_TRANS_SESEND: rc = lstcon_rpc_prep(nd, SRPC_SERVICE_REMOVE_SESSION, feats, 0, 0, crpc); - if (rc != 0) - return rc; + if (rc != 0) + return rc; rsrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.rmsn_reqst; rsrq->rmsn_sid.ses_stamp = console_session.ses_id.ses_stamp; @@ -599,11 +599,11 @@ lstcon_sesrpc_prep(struct lstcon_node *nd, int transop, lnet_nid_to_nid4(&console_session.ses_id.ses_nid); break; - default: - LBUG(); - } + default: + LBUG(); + } - return 0; + return 0; } int diff --git a/lnet/selftest/console.c b/lnet/selftest/console.c index e46624e..cfba9fc 100644 --- a/lnet/selftest/console.c +++ b/lnet/selftest/console.c @@ -1708,22 +1708,22 @@ lstcon_session_new(char *name, int key, unsigned feats, if (strlen(name) > sizeof(console_session.ses_name)-1) return -E2BIG; - strlcpy(console_session.ses_name, name, + strscpy(console_session.ses_name, name, sizeof(console_session.ses_name)); - rc = lstcon_batch_add(LST_DEFAULT_BATCH); - if (rc != 0) - return rc; + rc = lstcon_batch_add(LST_DEFAULT_BATCH); + if (rc != 0) + return rc; - rc = lstcon_rpc_pinger_start(); - if (rc != 0) { + rc = lstcon_rpc_pinger_start(); + if (rc != 0) { struct lstcon_batch *bat = NULL; - lstcon_batch_find(LST_DEFAULT_BATCH, &bat); - lstcon_batch_destroy(bat); + lstcon_batch_find(LST_DEFAULT_BATCH, &bat); + lstcon_batch_destroy(bat); - return rc; - } + return rc; + } console_session.ses_state = LST_SESSION_ACTIVE; @@ -1834,7 +1834,7 @@ lstcon_acceptor_handle(struct srpc_server_rpc *rpc) struct lstcon_ndlink *ndl; int rc = 0; - sfw_unpack_message(req); + sfw_unpack_message(req); mutex_lock(&console_session.ses_mutex); @@ -1842,70 +1842,70 @@ lstcon_acceptor_handle(struct srpc_server_rpc *rpc) jrep->join_sid.ses_nid = lnet_nid_to_nid4(&console_session.ses_id.ses_nid); if (LNET_NID_IS_ANY(&console_session.ses_id.ses_nid)) { - jrep->join_status = ESRCH; - goto out; - } + jrep->join_status = ESRCH; + goto out; + } if (lstcon_session_feats_check(req->msg_ses_feats) != 0) { jrep->join_status = EPROTO; goto out; } - if (jreq->join_sid.ses_nid != LNET_NID_ANY && - !lstcon_session_match(jreq->join_sid)) { - jrep->join_status = EBUSY; - goto out; - } + if (jreq->join_sid.ses_nid != LNET_NID_ANY && + !lstcon_session_match(jreq->join_sid)) { + jrep->join_status = EBUSY; + goto out; + } - if (lstcon_group_find(jreq->join_group, &grp) != 0) { - rc = lstcon_group_alloc(jreq->join_group, &grp); - if (rc != 0) { - CERROR("Out of memory\n"); - goto out; - } + if (lstcon_group_find(jreq->join_group, &grp) != 0) { + rc = lstcon_group_alloc(jreq->join_group, &grp); + if (rc != 0) { + CERROR("Out of memory\n"); + goto out; + } list_add_tail(&grp->grp_link, &console_session.ses_grp_list); lstcon_group_addref(grp); } - if (grp->grp_ref > 2) { - /* Group in using */ - jrep->join_status = EBUSY; - goto out; - } + if (grp->grp_ref > 2) { + /* Group in using */ + jrep->join_status = EBUSY; + goto out; + } - rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0); - if (rc == 0) { - jrep->join_status = EEXIST; - goto out; - } + rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 0); + if (rc == 0) { + jrep->join_status = EEXIST; + goto out; + } - rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1); - if (rc != 0) { - CERROR("Out of memory\n"); - goto out; - } + rc = lstcon_group_ndlink_find(grp, rpc->srpc_peer, &ndl, 1); + if (rc != 0) { + CERROR("Out of memory\n"); + goto out; + } - ndl->ndl_node->nd_state = LST_NODE_ACTIVE; - ndl->ndl_node->nd_timeout = console_session.ses_timeout; + ndl->ndl_node->nd_state = LST_NODE_ACTIVE; + ndl->ndl_node->nd_timeout = console_session.ses_timeout; - if (grp->grp_userland == 0) - grp->grp_userland = 1; + if (grp->grp_userland == 0) + grp->grp_userland = 1; - strlcpy(jrep->join_session, console_session.ses_name, + strscpy(jrep->join_session, console_session.ses_name, sizeof(jrep->join_session)); - jrep->join_timeout = console_session.ses_timeout; - jrep->join_status = 0; + jrep->join_timeout = console_session.ses_timeout; + jrep->join_status = 0; out: rep->msg_ses_feats = console_session.ses_features; - if (grp != NULL) + if (grp != NULL) lstcon_group_decref(grp); mutex_unlock(&console_session.ses_mutex); - return rc; + return rc; } static struct srpc_service lstcon_acceptor_service; diff --git a/lnet/selftest/framework.c b/lnet/selftest/framework.c index 6afad0d..aa45e47 100644 --- a/lnet/selftest/framework.c +++ b/lnet/selftest/framework.c @@ -265,7 +265,7 @@ sfw_init_session(struct sfw_session *sn, struct lst_sid sid, refcount_set(&sn->sn_refcount, 1); /* +1 for caller */ atomic_set(&sn->sn_brw_errors, 0); atomic_set(&sn->sn_ping_errors, 0); - strlcpy(&sn->sn_name[0], name, sizeof(sn->sn_name)); + strscpy(&sn->sn_name[0], name, sizeof(sn->sn_name)); sn->sn_timer_active = 0; sn->sn_id.ses_stamp = sid.ses_stamp; @@ -438,10 +438,10 @@ sfw_make_session(struct srpc_mksn_reqst *request, struct srpc_mksn_reply *reply) if (!request->mksn_force) { reply->mksn_status = EBUSY; - cplen = strlcpy(&reply->mksn_name[0], &sn->sn_name[0], + cplen = strscpy(&reply->mksn_name[0], &sn->sn_name[0], sizeof(reply->mksn_name)); - if (cplen >= sizeof(reply->mksn_name)) - return -E2BIG; + if (cplen < 0) + return cplen; return 0; } } @@ -520,6 +520,7 @@ sfw_debug_session(struct srpc_debug_reqst *request, struct srpc_debug_reply *reply) { struct sfw_session *sn = sfw_data.fw_session; + int cplen; if (sn == NULL) { reply->dbg_status = ESRCH; @@ -530,9 +531,10 @@ sfw_debug_session(struct srpc_debug_reqst *request, reply->dbg_status = 0; reply->dbg_sid = get_old_sid(sn); reply->dbg_timeout = sn->sn_timeout; - if (strlcpy(reply->dbg_name, &sn->sn_name[0], - sizeof(reply->dbg_name)) >= sizeof(reply->dbg_name)) - return -E2BIG; + cplen = strscpy(reply->dbg_name, &sn->sn_name[0], + sizeof(reply->dbg_name)); + if (cplen < 0) + return cplen; return 0; } diff --git a/lustre/fid/fid_store.c b/lustre/fid/fid_store.c index 547f92c..43b17db 100644 --- a/lustre/fid/fid_store.c +++ b/lustre/fid/fid_store.c @@ -88,7 +88,7 @@ static int seq_update_cb_add(struct thandle *th, struct lu_server_seq *seq) dcb = &ccb->suc_cb; dcb->dcb_func = seq_update_cb; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "seq_update_cb", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "seq_update_cb", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) diff --git a/lustre/fld/fld_cache.c b/lustre/fld/fld_cache.c index e77df96..02fbe1f 100644 --- a/lustre/fld/fld_cache.c +++ b/lustre/fld/fld_cache.c @@ -68,7 +68,7 @@ struct fld_cache *fld_cache_init(const char *name, int cache_size, cache->fci_cache_count = 0; rwlock_init(&cache->fci_lock); - strlcpy(cache->fci_name, name, sizeof(cache->fci_name)); + strscpy(cache->fci_name, name, sizeof(cache->fci_name)); cache->fci_cache_size = cache_size; cache->fci_threshold = cache_threshold; diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index d9ed477..472325d 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -3020,7 +3020,7 @@ int pcc_ioctl_state(struct file *file, struct inode *inode, if (IS_ERR(path)) GOTO(out_unlock, rc = PTR_ERR(path)); - if (strlcpy(state->pccs_path, path, buf_len) >= buf_len) + if (strscpy(state->pccs_path, path, buf_len) < 0) GOTO(out_unlock, rc = -ENAMETOOLONG); out_unlock: diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index ab1d9e3..a8aa5ca 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -3616,11 +3616,11 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm, lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version); lsm->lsm_md_migrate_offset = le32_to_cpu(lmm1->lmv_migrate_offset); lsm->lsm_md_migrate_hash = le32_to_cpu(lmm1->lmv_migrate_hash); - cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name, + cplen = strscpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name, sizeof(lsm->lsm_md_pool_name)); - if (cplen >= sizeof(lsm->lsm_md_pool_name)) - RETURN(-E2BIG); + if (cplen < 0) + RETURN(cplen); CDEBUG(D_INFO, "unpack lsm count %d/%d, master %d hash_type %#x/%#x layout_version %d\n", lsm->lsm_md_stripe_count, diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 1bb2afd9..412aef1 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -365,7 +365,7 @@ static inline int lod_set_pool(char **pool, const char *new_pool) OBD_ALLOC(*pool, len); if (*pool == NULL) return -ENOMEM; - strlcpy(*pool, new_pool, len); + strscpy(*pool, new_pool, len); } return 0; } @@ -639,7 +639,7 @@ static inline void lod_layout_get_pool(struct lod_layout_component *entries, if (entries[i].llc_magic == LOV_MAGIC_FOREIGN) continue; if (entries[i].llc_pool != NULL) { - strlcpy(pool, entries[i].llc_pool, len); + strscpy(pool, entries[i].llc_pool, len); break; } } diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index de080bf..626938e 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -778,11 +778,11 @@ static int lod_gen_component_ea(const struct lu_env *env, objs = &lmm->lmm_objects[0]; } else { struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *)lmm; - size_t cplen = strlcpy(v3->lmm_pool_name, + size_t cplen = strscpy(v3->lmm_pool_name, lod_comp->llc_pool, sizeof(v3->lmm_pool_name)); - if (cplen >= sizeof(v3->lmm_pool_name)) - RETURN(-E2BIG); + if (cplen < 0) + RETURN(cplen); objs = &v3->lmm_objects[0]; } lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 07f6bfc..6bccd97 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -4106,7 +4106,7 @@ static void embed_pool_to_comp_v1(const struct lov_comp_md_v1 *src, } else { lum3->lmm_magic = cpu_to_le32(LOV_USER_MAGIC_V3); entry->lcme_size = cpu_to_le32(sizeof(*lum3)); - strlcpy(lum3->lmm_pool_name, pool, + strscpy(lum3->lmm_pool_name, pool, sizeof(lum3->lmm_pool_name)); shift += sizeof(*lum3) - sizeof(*lum); } @@ -4176,7 +4176,7 @@ static int lod_xattr_set_default_lov_on_dir(const struct lu_env *env, v3->lmm_stripe_offset = cpu_to_le32(v1->lmm_stripe_offset); v3->lmm_stripe_size = cpu_to_le32(v1->lmm_stripe_size); - strlcpy(v3->lmm_pool_name, pool, sizeof(v3->lmm_pool_name)); + strscpy(v3->lmm_pool_name, pool, sizeof(v3->lmm_pool_name)); info->lti_buf.lb_buf = v3; info->lti_buf.lb_len = sizeof(*v3); diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index 2c85740..96b1bcf 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -466,7 +466,7 @@ int lod_pool_new(struct obd_device *obd, char *poolname) if (new_pool == NULL) RETURN(-ENOMEM); - strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); + strscpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); new_pool->pool_spill_target[0] = '\0'; atomic_set(&new_pool->pool_spill_hit, 0); new_pool->pool_lobd = obd; diff --git a/lustre/lov/lov_ea.c b/lustre/lov/lov_ea.c index a1ccd9d..45a1a65 100644 --- a/lustre/lov/lov_ea.c +++ b/lustre/lov/lov_ea.c @@ -241,10 +241,10 @@ lsme_unpack(struct lov_obd *lov, struct lov_mds_md *lmm, size_t buf_size, if (pool_name) { size_t pool_name_len; - pool_name_len = strlcpy(lsme->lsme_pool_name, pool_name, + pool_name_len = strscpy(lsme->lsme_pool_name, pool_name, sizeof(lsme->lsme_pool_name)); - if (pool_name_len >= sizeof(lsme->lsme_pool_name)) - GOTO(out_lsme, rc = -E2BIG); + if (pool_name_len < 0) + GOTO(out_lsme, rc = pool_name_len); } /* with Data-on-MDT set maxbytes to stripe size */ diff --git a/lustre/lov/lov_pack.c b/lustre/lov/lov_pack.c index 8399f3e..8f0a061 100644 --- a/lustre/lov/lov_pack.c +++ b/lustre/lov/lov_pack.c @@ -132,7 +132,7 @@ static ssize_t lov_lsm_pack_v1v3(const struct lov_stripe_md *lsm, void *buf, if (lsm->lsm_magic == LOV_MAGIC_V3) { BUILD_BUG_ON(sizeof(lsm->lsm_entries[0]->lsme_pool_name) != sizeof(lmmv3->lmm_pool_name)); - strlcpy(lmmv3->lmm_pool_name, + strscpy(lmmv3->lmm_pool_name, lsm->lsm_entries[0]->lsme_pool_name, sizeof(lmmv3->lmm_pool_name)); lmm_objects = lmmv3->lmm_objects; @@ -215,7 +215,7 @@ unsigned int lov_lsme_pack_v1v3(struct lov_stripe_md_entry *lsme, if (lsme->lsme_magic == LOV_MAGIC_V3) { struct lov_mds_md_v3 *lmmv3 = (struct lov_mds_md_v3 *)lmm; - strlcpy(lmmv3->lmm_pool_name, lsme->lsme_pool_name, + strscpy(lmmv3->lmm_pool_name, lsme->lsme_pool_name, sizeof(lmmv3->lmm_pool_name)); lmm_objects = lmmv3->lmm_objects; } else { diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index 31a4287..c31d8d5 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -390,7 +390,7 @@ int lov_pool_new(struct obd_device *obd, char *poolname) if (new_pool == NULL) RETURN(-ENOMEM); - strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); + strscpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name)); new_pool->pool_lobd = obd; /* ref count init to 1 because when created a pool is always used * up to deletion diff --git a/lustre/mdc/mdc_lib.c b/lustre/mdc/mdc_lib.c index a60396c..0a8d2b4 100644 --- a/lustre/mdc/mdc_lib.c +++ b/lustre/mdc/mdc_lib.c @@ -113,7 +113,7 @@ static void mdc_pack_name(struct req_capsule *pill, buf[name_len] = '\0'; return; } - cpy_len = strlcpy(buf, name, buf_size); + cpy_len = strscpy(buf, name, buf_size); LASSERT(lu_name_is_valid_2(buf, cpy_len)); if (cpy_len != name_len) @@ -175,7 +175,7 @@ void mdc_file_sepol_pack(struct req_capsule *pill, struct sptlrpc_sepol *p) RCL_CLIENT); LASSERT(buf_size == p->ssp_sepol_size); - strlcpy(buf, p->ssp_sepol, p->ssp_sepol_size); + strscpy(buf, p->ssp_sepol, p->ssp_sepol_size); } void mdc_readdir_pack(struct req_capsule *pill, __u64 pgoff, size_t size, diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 74327f5..d39fbef 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -1816,7 +1816,7 @@ static int mdd_changelog_user_register(const struct lu_env *env, rc = mdd_changelog_name_check(env, ctxt, mdd, name); if (rc) GOTO(out_users, rc); - strlcpy(rec->cur_name, name, sizeof(rec->cur_name)); + strscpy(rec->cur_name, name, sizeof(rec->cur_name)); } mdd_chlg_username(rec, user_name, sizeof(user_name)); diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 685f0c3..45d6aa0 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -1045,7 +1045,7 @@ static void mdd_changelog_rec_ext_rename(struct changelog_rec *rec, rnm->cr_spfid = *spfid; changelog_rec_name(rec)[rec->cr_namelen] = '\0'; - strlcpy(changelog_rec_sname(rec), sname->ln_name, extsize); + strscpy(changelog_rec_sname(rec), sname->ln_name, extsize); rec->cr_namelen += extsize; } @@ -1056,7 +1056,7 @@ void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid) if (jobid == NULL || jobid[0] == '\0') return; - strlcpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid)); + strscpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid)); } void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags) @@ -1095,7 +1095,7 @@ void mdd_changelog_rec_extra_xattr(struct changelog_rec *rec, { struct changelog_ext_xattr *xattr = changelog_rec_xattr(rec); - strlcpy(xattr->cr_xattr, xattr_name, sizeof(xattr->cr_xattr)); + strscpy(xattr->cr_xattr, xattr_name, sizeof(xattr->cr_xattr)); } /** diff --git a/lustre/mdd/mdd_lproc.c b/lustre/mdd/mdd_lproc.c index 86e6532..aec27cb 100644 --- a/lustre/mdd/mdd_lproc.c +++ b/lustre/mdd/mdd_lproc.c @@ -754,7 +754,7 @@ static ssize_t append_pool_store(struct kobject *kobj, struct attribute *attr, if (!count || count > LOV_MAXPOOLNAME + 1 || buffer[0] == '\n') return -EINVAL; - strlcpy(mdd->mdd_append_pool, buffer, LOV_MAXPOOLNAME + 1); + strscpy(mdd->mdd_append_pool, buffer, LOV_MAXPOOLNAME + 1); if (mdd->mdd_append_pool[count - 1] == '\n') mdd->mdd_append_pool[count - 1] = '\0'; diff --git a/lustre/mdt/mdt_coordinator.c b/lustre/mdt/mdt_coordinator.c index ee4dd71..b7bf445 100644 --- a/lustre/mdt/mdt_coordinator.c +++ b/lustre/mdt/mdt_coordinator.c @@ -256,7 +256,7 @@ static int mdt_cdt_waiting_cb(const struct lu_env *env, RETURN(-ENOMEM); hal->hal_version = HAL_VERSION; - strlcpy(hal->hal_fsname, hsd->hsd_fsname, MTI_NAME_MAXLEN + 1); + strscpy(hal->hal_fsname, hsd->hsd_fsname, MTI_NAME_MAXLEN + 1); hal->hal_archive_id = larr->arr_archive_id; hal->hal_flags = larr->arr_flags; hal->hal_count = 0; diff --git a/lustre/mdt/mdt_lib.c b/lustre/mdt/mdt_lib.c index f69d19f..9925214 100644 --- a/lustre/mdt/mdt_lib.c +++ b/lustre/mdt/mdt_lib.c @@ -139,7 +139,7 @@ static void ucred_set_jobid(struct mdt_thread_info *info, struct lu_ucred *uc) /* set jobid if specified. */ if (jobid) - strlcpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid)); + strscpy(uc->uc_jobid, jobid, sizeof(uc->uc_jobid)); else uc->uc_jobid[0] = '\0'; } diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 5a53bfb..100ce53 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -1524,9 +1524,9 @@ again: body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY); LASSERT(body != NULL); LASSERT(sizeof(body->mcb_name) > strlen(cld->cld_logname)); - if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name)) - >= sizeof(body->mcb_name)) - GOTO(out, rc = -E2BIG); + rc = strscpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name)); + if (rc < 0) + GOTO(out, rc); body->mcb_offset = cfg->cfg_last_idx + 1; body->mcb_type = cld->cld_type; body->mcb_bits = PAGE_SHIFT; diff --git a/lustre/mgc/mgc_request_server.c b/lustre/mgc/mgc_request_server.c index 6eadd9d..15e2bf5 100644 --- a/lustre/mgc/mgc_request_server.c +++ b/lustre/mgc/mgc_request_server.c @@ -361,9 +361,9 @@ again: body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY); LASSERT(body); LASSERT(sizeof(body->mcb_name) > strlen(cld->cld_logname)); - if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name)) - >= sizeof(body->mcb_name)) - GOTO(out, rc = -E2BIG); + rc = strscpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name)); + if (rc < 0) + GOTO(out, rc); body->mcb_offset = config_read_offset; body->mcb_type = cld->cld_type; body->mcb_bits = PAGE_SHIFT; diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 1cda408..0e15af1 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -743,7 +743,7 @@ static int mgs_extract_fs_pool(char *arg, char *fsname, char *poolname) /* Also make sure poolname is not to long. */ if (strlen(ptr) > LOV_MAXPOOLNAME) return -ENAMETOOLONG; - strlcpy(poolname, ptr, LOV_MAXPOOLNAME + 1); + strscpy(poolname, ptr, LOV_MAXPOOLNAME + 1); /* Test if fsname is empty */ len = strlen(arg) - strlen(ptr) - 1; diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 3fca59e..20887d4 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -995,14 +995,14 @@ static int mgs_modify(const struct lu_env *env, struct mgs_device *mgs, OBD_ALLOC_PTR(mml); if (!mml) GOTO(out_close, rc = -ENOMEM); - if (strlcpy(mml->mml_marker.cm_comment, comment, - sizeof(mml->mml_marker.cm_comment)) >= - sizeof(mml->mml_marker.cm_comment)) - GOTO(out_free, rc = -E2BIG); - if (strlcpy(mml->mml_marker.cm_tgtname, devname, - sizeof(mml->mml_marker.cm_tgtname)) >= - sizeof(mml->mml_marker.cm_tgtname)) - GOTO(out_free, rc = -E2BIG); + rc = strscpy(mml->mml_marker.cm_comment, comment, + sizeof(mml->mml_marker.cm_comment)); + if (rc < 0) + GOTO(out_free, rc); + rc = strscpy(mml->mml_marker.cm_tgtname, devname, + sizeof(mml->mml_marker.cm_tgtname)); + if (rc < 0) + GOTO(out_free, rc); /* Modify mostly means cancel */ mml->mml_marker.cm_flags = flags; mml->mml_marker.cm_canceltime = flags ? ktime_get_real_seconds() : 0; @@ -1479,11 +1479,11 @@ static int mgs_replace_log(const struct lu_env *env, GOTO(out_close, rc = -ENOMEM); /* devname is only needed information to replace UUID records */ if (devname) - strlcpy(mrd->target.mti_svname, devname, + strscpy(mrd->target.mti_svname, devname, sizeof(mrd->target.mti_svname)); /* data is parsed in llog callback */ if (data) - strlcpy(mrd->target.mti_params, data, + strscpy(mrd->target.mti_params, data, sizeof(mrd->target.mti_params)); /* Copy records to this temporary llog */ mrd->temp_llh = orig_llh; @@ -1971,14 +1971,14 @@ static int record_marker(const struct lu_env *env, mgi->mgi_marker.cm_step = fsdb->fsdb_gen; mgi->mgi_marker.cm_flags = flags; mgi->mgi_marker.cm_vers = LUSTRE_VERSION_CODE; - cplen = strlcpy(mgi->mgi_marker.cm_tgtname, tgtname, + cplen = strscpy(mgi->mgi_marker.cm_tgtname, tgtname, sizeof(mgi->mgi_marker.cm_tgtname)); - if (cplen >= sizeof(mgi->mgi_marker.cm_tgtname)) - return -E2BIG; - cplen = strlcpy(mgi->mgi_marker.cm_comment, comment, + if (cplen < 0) + return cplen; + cplen = strscpy(mgi->mgi_marker.cm_comment, comment, sizeof(mgi->mgi_marker.cm_comment)); - if (cplen >= sizeof(mgi->mgi_marker.cm_comment)) - return -E2BIG; + if (cplen < 0) + return cplen; mgi->mgi_marker.cm_createtime = ktime_get_real_seconds(); mgi->mgi_marker.cm_canceltime = 0; lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL); @@ -2211,10 +2211,10 @@ static int mgs_steal_client_llog_handler(const struct lu_env *env, (marker->cm_flags & CM_START) && !(marker->cm_flags & CM_SKIP)) { got_an_osc_or_mdc = 1; - cplen = strlcpy(tmti->mti_svname, marker->cm_tgtname, + cplen = strscpy(tmti->mti_svname, marker->cm_tgtname, sizeof(tmti->mti_svname)); - if (cplen >= sizeof(tmti->mti_svname)) - RETURN(-E2BIG); + if (cplen < 0) + RETURN(cplen); rc = record_start_log(env, mgs, &mdt_llh, mti->mti_svname); if (rc) @@ -3499,7 +3499,7 @@ static int mgs_wlp_lcfg(const struct lu_env *env, int rc, del; /* Erase any old settings of this same parameter */ - strlcpy(comment, ptr, sizeof(comment)); + strscpy(comment, ptr, sizeof(comment)); /* But don't try to match the value. */ tmp = strchr(comment, '='); if (tmp != NULL) @@ -4080,11 +4080,9 @@ static int mgs_write_log_param2(const struct lu_env *env, } param = strstr(ptr, PARAM_FAILNODE); - if (strlcpy(mti->mti_params, param, sizeof(mti->mti_params)) >= - sizeof(mti->mti_params)) { - rc = -E2BIG; + rc = strscpy(mti->mti_params, param, sizeof(mti->mti_params)); + if (rc < 0) goto end; - } CDEBUG(D_MGS, "Adding failnode with param %s\n", mti->mti_params); @@ -5403,9 +5401,9 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, "%.*s", (int)len, param); param += len + 1; } else { - if (strlcpy(mti->mti_svname, devname, sizeof(mti->mti_svname)) >= - sizeof(mti->mti_svname)) - RETURN(-E2BIG); + rc = strscpy(mti->mti_svname, devname, sizeof(mti->mti_svname)); + if (rc < 0) + RETURN(rc); } if (!strlen(mti->mti_svname)) { @@ -5419,7 +5417,7 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, /* For this case we have an invalid obd device name */ case -ENXIO: CDEBUG(D_MGS, "%s don't contain an index\n", mti->mti_svname); - strlcpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); + strscpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); dev_type = 0; break; /* Not an obd device, assume devname is the fsname. @@ -5427,7 +5425,7 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, */ case -EINVAL: CDEBUG(D_MGS, "%s is seen as a file system name\n", mti->mti_svname); - strlcpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); + strscpy(mti->mti_fsname, mti->mti_svname, MTI_NAME_MAXLEN); dev_type = 0; break; default: @@ -5452,10 +5450,9 @@ static int mgs_set_conf_param(const struct lu_env *env, struct mgs_device *mgs, } break; } - - if (strlcpy(mti->mti_params, param, sizeof(mti->mti_params)) >= - sizeof(mti->mti_params)) - GOTO(out, rc = -E2BIG); + rc = strscpy(mti->mti_params, param, sizeof(mti->mti_params)); + if (rc < 0) + GOTO(out, rc); CDEBUG(D_MGS, "set_conf_param fs='%s' device='%s' param='%s'\n", mti->mti_fsname, mti->mti_svname, mti->mti_params); @@ -5499,9 +5496,9 @@ static int mgs_set_param2(const struct lu_env *env, struct mgs_device *mgs, size_t len; int rc; - if (strlcpy(mti->mti_params, param, sizeof(mti->mti_params)) >= - sizeof(mti->mti_params)) - GOTO(out, rc = -E2BIG); + rc = strscpy(mti->mti_params, param, sizeof(mti->mti_params)); + if (rc < 0) + GOTO(out, rc); len = strcspn(param, ".="); if (len && param[len] != '=') { diff --git a/lustre/obdclass/dt_object.c b/lustre/obdclass/dt_object.c index 8a732b3..f14f9fb 100644 --- a/lustre/obdclass/dt_object.c +++ b/lustre/obdclass/dt_object.c @@ -342,7 +342,7 @@ dt_store_resolve(const struct lu_env *env, struct dt_device *dt, dfh->dfh_dt = dt; dfh->dfh_fid = fid; - strlcpy(info->dti_buf, path, sizeof(info->dti_buf)); + strscpy(info->dti_buf, path, sizeof(info->dti_buf)); result = dt->dd_ops->dt_root_get(env, dt, fid); if (result == 0) { diff --git a/lustre/obdclass/jobid.c b/lustre/obdclass/jobid.c index 5efc951..1767c17 100644 --- a/lustre/obdclass/jobid.c +++ b/lustre/obdclass/jobid.c @@ -523,7 +523,7 @@ static int jobid_get_from_cache(char *jobid, size_t joblen) rcu_read_lock(); jid = jobid_current(); if (jid) { - strlcpy(jobid, jid, joblen); + strscpy(jobid, jid, joblen); joblen = strlen(jobid); } else { rc = -ENOENT; @@ -602,7 +602,7 @@ static int jobid_get_from_cache(char *jobid, size_t joblen) spin_lock(&pidmap->jp_lock); if (!rc) { pidmap->jp_joblen = env_len; - strlcpy(pidmap->jp_jobid, env_jobid, + strscpy(pidmap->jp_jobid, env_jobid, sizeof(pidmap->jp_jobid)); rc = 0; } else if (rc == -ENOENT) { @@ -619,7 +619,7 @@ static int jobid_get_from_cache(char *jobid, size_t joblen) * If a cached missing entry was found, return -ENOENT. */ if (pidmap->jp_joblen) { - strlcpy(jobid, pidmap->jp_jobid, joblen); + strscpy(jobid, pidmap->jp_jobid, joblen); joblen = pidmap->jp_joblen; rc = 0; } else if (!rc) { @@ -959,7 +959,7 @@ void lustre_jobid_clear(const char *find_jobid) if (jobid_hash == NULL) return; - strlcpy(jobid, find_jobid, sizeof(jobid)); + strscpy(jobid, find_jobid, sizeof(jobid)); /* trim \n off the end of the incoming jobid */ end = strchr(jobid, '\n'); if (end && *end == '\n') diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 37d3563..ed6fa85 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -1257,7 +1257,7 @@ struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg, if (!new_param) GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM)); - strlcpy(new_param, new_name, new_len); + strscpy(new_param, new_name, new_len); if (value) strcat(new_param, value); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index a841692..c921a43 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -848,8 +848,9 @@ int server_name2svname(const char *label, char *svname, const char **endptr, if (endptr != NULL) *endptr = dash; - if (strlcpy(svname, dash + 1, svsize) >= svsize) - return -E2BIG; + rc = strscpy(svname, dash + 1, svsize); + if (rc < 0) + return rc; return 0; } diff --git a/lustre/obdclass/upcall_cache.c b/lustre/obdclass/upcall_cache.c index 4bc61b7..f71901b 100644 --- a/lustre/obdclass/upcall_cache.c +++ b/lustre/obdclass/upcall_cache.c @@ -562,9 +562,9 @@ struct upcall_cache *upcall_cache_init(const char *name, const char *upcall, RETURN(ERR_PTR(-ENOMEM)); for (i = 0; i < cache->uc_hashsize; i++) INIT_LIST_HEAD(&cache->uc_hashtable[i]); - strlcpy(cache->uc_name, name, sizeof(cache->uc_name)); + strscpy(cache->uc_name, name, sizeof(cache->uc_name)); /* upcall pathname proc tunable */ - strlcpy(cache->uc_upcall, upcall, sizeof(cache->uc_upcall)); + strscpy(cache->uc_upcall, upcall, sizeof(cache->uc_upcall)); cache->uc_entry_expire = entry_expire; cache->uc_acquire_expire = acquire_expire; cache->uc_acquire_replay = replayable; diff --git a/lustre/ofd/ofd_access_log.c b/lustre/ofd/ofd_access_log.c index 1024c08..1015203 100644 --- a/lustre/ofd/ofd_access_log.c +++ b/lustre/ofd/ofd_access_log.c @@ -468,7 +468,7 @@ struct ofd_access_log *ofd_access_log_create(const char *ofd_name, size_t size) if (!oal) return ERR_PTR(-ENOMEM); - strlcpy(oal->oal_name, ofd_name, sizeof(oal->oal_name)); + strscpy(oal->oal_name, ofd_name, sizeof(oal->oal_name)); oal->oal_log_size = size; oal->oal_entry_size = entry_size; INIT_LIST_HEAD(&oal->oal_circ_buf_list); diff --git a/lustre/ofd/ofd_io.c b/lustre/ofd/ofd_io.c index a7583cc..54cfe02 100644 --- a/lustre/ofd/ofd_io.c +++ b/lustre/ofd/ofd_io.c @@ -1187,7 +1187,7 @@ static int ofd_soft_sync_cb_add(struct thandle *th, struct obd_export *exp) dcb = &ossc->ossc_cb; dcb->dcb_func = ofd_cb_soft_sync; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "ofd_cb_soft_sync", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "ofd_cb_soft_sync", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { diff --git a/lustre/ofd/ofd_objects.c b/lustre/ofd/ofd_objects.c index 02b4248..fe74fa1 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -206,7 +206,7 @@ static int ofd_precreate_cb_add(const struct lu_env *env, struct thandle *th, dcb = &opc->opc_cb; dcb->dcb_func = ofd_cb_precreate; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "ofd_cb_precreate", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "ofd_cb_precreate", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 7ef62b0..314aa79 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -8209,10 +8209,10 @@ static int osd_device_init(const struct lu_env *env, struct lu_device *d, const char *name, struct lu_device *next) { struct osd_device *osd = osd_dev(d); + int cplen = strscpy(osd->od_svname, name, sizeof(osd->od_svname)); - if (strlcpy(osd->od_svname, name, sizeof(osd->od_svname)) >= - sizeof(osd->od_svname)) - return -E2BIG; + if (cplen < 0) + return cplen; return osd_procfs_init(osd, name); } @@ -8591,12 +8591,10 @@ static int osd_device_init0(const struct lu_env *env, /* default fallocate to unwritten extents: LU-14326/LU-14333 */ o->od_fallocate_zero_blocks = 0; - cplen = strlcpy(o->od_svname, lustre_cfg_string(cfg, 4), + cplen = strscpy(o->od_svname, lustre_cfg_string(cfg, 4), sizeof(o->od_svname)); - if (cplen >= sizeof(o->od_svname)) { - rc = -E2BIG; - GOTO(out, rc); - } + if (cplen < 0) + GOTO(out, rc = cplen); o->od_index_backup_stop = 0; o->od_index = -1; /* -1 means index is invalid */ diff --git a/lustre/osd-ldiskfs/osd_lproc.c b/lustre/osd-ldiskfs/osd_lproc.c index 9e6cbf9..e6b71fb 100644 --- a/lustre/osd-ldiskfs/osd_lproc.c +++ b/lustre/osd-ldiskfs/osd_lproc.c @@ -80,7 +80,7 @@ static void osd_symlink_brw_stats(struct osd_device *osd) if (len_root > (p - path) || len_root + len_path + 16 > PATH_MAX) goto out; - strlcpy(path, root, len_root); + strscpy(path, root, len_root); if (p > path + len_root) { s = path + len_root; while ((*s++ = *p++) != '\0'); diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index 5d265d5..531b89d 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -1106,13 +1106,13 @@ static int osd_mount(const struct lu_env *env, if (mntdev == NULL || svname == NULL) RETURN(-EINVAL); - rc = strlcpy(o->od_mntdev, mntdev, sizeof(o->od_mntdev)); - if (rc >= sizeof(o->od_mntdev)) - RETURN(-E2BIG); + rc = strscpy(o->od_mntdev, mntdev, sizeof(o->od_mntdev)); + if (rc < 0) + RETURN(rc); - rc = strlcpy(o->od_svname, svname, sizeof(o->od_svname)); - if (rc >= sizeof(o->od_svname)) - RETURN(-E2BIG); + rc = strscpy(o->od_svname, svname, sizeof(o->od_svname)); + if (rc < 0) + RETURN(rc); opts = lustre_cfg_string(cfg, 3); diff --git a/lustre/osd-zfs/osd_lproc.c b/lustre/osd-zfs/osd_lproc.c index 05c3a27..a81c6d4 100644 --- a/lustre/osd-zfs/osd_lproc.c +++ b/lustre/osd-zfs/osd_lproc.c @@ -67,7 +67,7 @@ static void osd_symlink_brw_stats(struct osd_device *osd) if (len_root > (p - path) || len_root + len_path + 16 > PATH_MAX) goto out; - strlcpy(path, root, len_root); + strscpy(path, root, len_root); if (p > path + len_root) { s = path + len_root; while ((*s++ = *p++) != '\0'); diff --git a/lustre/osd-zfs/osd_oi.c b/lustre/osd-zfs/osd_oi.c index b51ae1e..9389c2f 100644 --- a/lustre/osd-zfs/osd_oi.c +++ b/lustre/osd-zfs/osd_oi.c @@ -130,9 +130,9 @@ osd_oi_lookup(const struct lu_env *env, struct osd_device *o, if (rc) return rc; - rc = strlcpy(oi->oi_name, name, sizeof(oi->oi_name)); - if (rc >= sizeof(oi->oi_name)) - return -E2BIG; + rc = strscpy(oi->oi_name, name, sizeof(oi->oi_name)); + if (rc < 0) + return rc; oi->oi_zapid = zde->zde_dnode; diff --git a/lustre/osd-zfs/osd_quota.c b/lustre/osd-zfs/osd_quota.c index 7079aeb..33b2d41 100644 --- a/lustre/osd-zfs/osd_quota.c +++ b/lustre/osd-zfs/osd_quota.c @@ -377,7 +377,7 @@ static int osd_it_acct_rec(const struct lu_env *env, /* inode accounting is maintained by DMU since 0.7.0 */ strncpy(info->oti_buf, DMU_OBJACCT_PREFIX, DMU_OBJACCT_PREFIX_LEN); - strlcpy(info->oti_buf + DMU_OBJACCT_PREFIX_LEN, za->za_name, + strscpy(info->oti_buf + DMU_OBJACCT_PREFIX_LEN, za->za_name, sizeof(info->oti_buf) - DMU_OBJACCT_PREFIX_LEN); rc = osd_zap_lookup(osd, it->oiq_obj->oo_dn->dn_object, it->oiq_obj->oo_dn, info->oti_buf, sizeof(uint64_t), diff --git a/lustre/ptlrpc/nodemap_handler.c b/lustre/ptlrpc/nodemap_handler.c index 18a77b9..a6da068 100644 --- a/lustre/ptlrpc/nodemap_handler.c +++ b/lustre/ptlrpc/nodemap_handler.c @@ -972,9 +972,8 @@ static int nodemap_set_fileset_helper(struct nodemap_config *config, nodemap->nm_fileset[0] = '\0'; else if (fileset[0] != '/') rc = -EINVAL; - else if (strlcpy(nodemap->nm_fileset, fileset, - sizeof(nodemap->nm_fileset)) >= - sizeof(nodemap->nm_fileset)) + else if (strscpy(nodemap->nm_fileset, fileset, + sizeof(nodemap->nm_fileset)) < 0) rc = -ENAMETOOLONG; return rc; @@ -1096,7 +1095,7 @@ int nodemap_set_sepol(const char *name, const char *sepol) /* truncation cannot happen, as string length was checked in * nodemap_validate_sepol() */ - strlcpy(nodemap->nm_sepol, sepol, sizeof(nodemap->nm_sepol)); + strscpy(nodemap->nm_sepol, sepol, sizeof(nodemap->nm_sepol)); out_putref: mutex_unlock(&active_config_lock); diff --git a/lustre/ptlrpc/nodemap_storage.c b/lustre/ptlrpc/nodemap_storage.c index 18ec01f..e40f145b 100644 --- a/lustre/ptlrpc/nodemap_storage.c +++ b/lustre/ptlrpc/nodemap_storage.c @@ -805,7 +805,7 @@ static int nodemap_cluster_rec_helper(struct nodemap_config *config, mutex_lock(&active_config_lock); old_nm = nodemap_lookup(rec->ncr.ncr_name); if (!IS_ERR(old_nm) && old_nm->nm_fileset[0] != '\0') - strlcpy(nodemap->nm_fileset, old_nm->nm_fileset, + strscpy(nodemap->nm_fileset, old_nm->nm_fileset, sizeof(nodemap->nm_fileset)); mutex_unlock(&active_config_lock); if (!IS_ERR(old_nm)) diff --git a/lustre/ptlrpc/nrs.c b/lustre/ptlrpc/nrs.c index 3bf42ab..3f5b59d 100644 --- a/lustre/ptlrpc/nrs.c +++ b/lustre/ptlrpc/nrs.c @@ -328,7 +328,7 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg) } if (arg) - strlcpy(policy->pol_arg, arg, sizeof(policy->pol_arg)); + strscpy(policy->pol_arg, arg, sizeof(policy->pol_arg)); /* take the started reference */ refcount_set(&policy->pol_start_ref, 1); @@ -1253,7 +1253,7 @@ static int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf) if (desc == NULL) GOTO(fail, rc = -ENOMEM); - if (strlcpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name)) >= + if (strscpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name)) >= sizeof(desc->pd_name)) { OBD_FREE_PTR(desc); GOTO(fail, rc = -E2BIG); diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 7623174..116bcc16 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -297,7 +297,7 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy, if (rule == NULL) return -ENOMEM; - strlcpy(rule->tr_name, start->tc_name, sizeof(rule->tr_name)); + strscpy(rule->tr_name, start->tc_name, sizeof(rule->tr_name)); rule->tr_rpc_rate = start->u.tc_start.ts_rpc_rate; rule->tr_flags = start->u.tc_start.ts_rule_flags; rule->tr_nsecs_per_rpc = NSEC_PER_SEC / rule->tr_rpc_rate; @@ -1647,8 +1647,8 @@ static inline void nrs_tbf_cli_gen_key(struct nrs_tbf_client *cli, if (cli) { INIT_LIST_HEAD(&cli->tc_lru); - strlcpy(cli->tc_key, keystr, sizeof(cli->tc_key)); - strlcpy(cli->tc_jobid, jobid, sizeof(cli->tc_jobid)); + strscpy(cli->tc_key, keystr, sizeof(cli->tc_key)); + strscpy(cli->tc_jobid, jobid, sizeof(cli->tc_jobid)); cli->tc_nid = req->rq_peer.nid; cli->tc_opcode = opc; cli->tc_id = id; @@ -2621,7 +2621,7 @@ nrs_tbf_id_rule_init(struct ptlrpc_nrs_policy *policy, if (rule->tr_ids_str == NULL) return -ENOMEM; - strlcpy(rule->tr_ids_str, start->u.tc_start.ts_ids_str, + strscpy(rule->tr_ids_str, start->u.tc_start.ts_ids_str, ids_len); if (!list_empty(&start->u.tc_start.ts_ids)) { diff --git a/lustre/ptlrpc/sec_config.c b/lustre/ptlrpc/sec_config.c index be7965b..a818717 100644 --- a/lustre/ptlrpc/sec_config.c +++ b/lustre/ptlrpc/sec_config.c @@ -99,7 +99,7 @@ int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr) return 0; } - strlcpy(buf, str, sizeof(buf)); + strscpy(buf, str, sizeof(buf)); bulk = strchr(buf, '-'); if (bulk) @@ -533,7 +533,7 @@ struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf, OBD_ALLOC_PTR(conf_tgt); if (conf_tgt) { - strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name)); + strscpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name)); sptlrpc_rule_set_init(&conf_tgt->sct_rset); list_add(&conf_tgt->sct_list, &conf->sc_tgts); } @@ -558,9 +558,7 @@ struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname, OBD_ALLOC_PTR(conf); if (conf == NULL) return NULL; - - if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >= - sizeof(conf->sc_fsname)) { + if (strscpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) < 0) { OBD_FREE_PTR(conf); return NULL; } @@ -674,7 +672,7 @@ int sptlrpc_process_config(struct lustre_cfg *lcfg) * is a actual filesystem. */ if (server_name2fsname(target, fsname, NULL)) - strlcpy(fsname, target, sizeof(fsname)); + strscpy(fsname, target, sizeof(fsname)); rc = sptlrpc_parse_rule(param, &rule); if (rc) diff --git a/lustre/ptlrpc/sec_lproc.c b/lustre/ptlrpc/sec_lproc.c index 8e8e875..8531103 100644 --- a/lustre/ptlrpc/sec_lproc.c +++ b/lustre/ptlrpc/sec_lproc.c @@ -178,7 +178,7 @@ static int sptlrpc_sepol_update(struct obd_import *imp, kref_init(&new->ssp_ref); new->ssp_sepol_size = pol_len + 1; new->ssp_mtime = mtime; - strlcpy(new->ssp_sepol, pol, new->ssp_sepol_size); + strscpy(new->ssp_sepol, pol, new->ssp_sepol_size); spin_lock(&imp_sec->ps_lock); old = rcu_dereference_protected(imp_sec->ps_sepol, 1); diff --git a/lustre/quota/qmt_dev.c b/lustre/quota/qmt_dev.c index ae93750..3126355 100644 --- a/lustre/quota/qmt_dev.c +++ b/lustre/quota/qmt_dev.c @@ -221,9 +221,9 @@ static int qmt_device_init0(const struct lu_env *env, struct qmt_device *qmt, RETURN(-EINVAL); /* record who i am, it might be useful ... */ - rc = strlcpy(qmt->qmt_svname, svname, sizeof(qmt->qmt_svname)); - if (rc >= sizeof(qmt->qmt_svname)) - RETURN(-E2BIG); + rc = strscpy(qmt->qmt_svname, svname, sizeof(qmt->qmt_svname)); + if (rc < 0) + RETURN(rc); /* look-up the obd_device associated with the qmt */ obd = class_name2obd(qmt->qmt_svname); diff --git a/lustre/quota/qsd_lib.c b/lustre/quota/qsd_lib.c index 2d27fab..130a311 100644 --- a/lustre/quota/qsd_lib.c +++ b/lustre/quota/qsd_lib.c @@ -713,9 +713,9 @@ struct qsd_instance *qsd_init(const struct lu_env *env, char *svname, qsd->qsd_exclusive = excl; /* copy service name */ - if (strlcpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname)) - >= sizeof(qsd->qsd_svname)) - GOTO(out, rc = -E2BIG); + rc = strscpy(qsd->qsd_svname, svname, sizeof(qsd->qsd_svname)); + if (rc < 0) + GOTO(out, rc); /* grab reference on osd device */ lu_device_get(&dev->dd_lu_dev); diff --git a/lustre/target/tgt_grant.c b/lustre/target/tgt_grant.c index 1f21085..a835071 100644 --- a/lustre/target/tgt_grant.c +++ b/lustre/target/tgt_grant.c @@ -1563,7 +1563,7 @@ int tgt_grant_commit_cb_add(struct thandle *th, struct obd_export *exp, dcb = &tgc->tgc_cb; dcb->dcb_func = tgt_grant_commit_cb; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "tgt_grant_commit_cb", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "tgt_grant_commit_cb", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { diff --git a/lustre/target/tgt_lastrcvd.c b/lustre/target/tgt_lastrcvd.c index 3a748bc..8801607 100644 --- a/lustre/target/tgt_lastrcvd.c +++ b/lustre/target/tgt_lastrcvd.c @@ -575,7 +575,7 @@ static int tgt_new_client_cb_add(struct thandle *th, struct obd_export *exp) dcb = &ccb->lncc_cb; dcb->dcb_func = tgt_cb_new_client; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "tgt_cb_new_client", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "tgt_cb_new_client", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { @@ -995,7 +995,7 @@ static int tgt_last_commit_cb_add(struct thandle *th, struct lu_target *tgt, dcb = &ccb->llcc_cb; dcb->dcb_func = tgt_cb_last_committed; INIT_LIST_HEAD(&dcb->dcb_linkage); - strlcpy(dcb->dcb_name, "tgt_cb_last_committed", sizeof(dcb->dcb_name)); + strscpy(dcb->dcb_name, "tgt_cb_last_committed", sizeof(dcb->dcb_name)); rc = dt_trans_cb_add(th, dcb); if (rc) { diff --git a/lustre/target/tgt_mount.c b/lustre/target/tgt_mount.c index 99bb489..6ca4016 100644 --- a/lustre/target/tgt_mount.c +++ b/lustre/target/tgt_mount.c @@ -1280,9 +1280,9 @@ static struct mgs_target_info *server_lsi2mti(struct lustre_sb_info *lsi) if (!mti) GOTO(free_list, mti = ERR_PTR(-ENOMEM)); - if (strlcpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname)) - >= sizeof(mti->mti_svname)) - GOTO(free_mti, rc = -E2BIG); + rc = strscpy(mti->mti_svname, lsi->lsi_svname, sizeof(mti->mti_svname)); + if (rc < 0) + GOTO(free_mti, rc); mti->mti_nid_count = nid_count; for (i = 0; i < mti->mti_nid_count; i++) { @@ -1314,7 +1314,7 @@ static struct mgs_target_info *server_lsi2mti(struct lustre_sb_info *lsi) /* use NID strings instead */ if (large_nid) mti->mti_flags |= LDD_F_LARGE_NID; - cplen = strlcpy(mti->mti_params, lsi->lsi_lmd->lmd_params, + cplen = strscpy(mti->mti_params, lsi->lsi_lmd->lmd_params, sizeof(mti->mti_params)); if (cplen >= sizeof(mti->mti_params)) rc = -E2BIG; @@ -1635,13 +1635,13 @@ static int lsi_prepare(struct lustre_sb_info *lsi) strlen(fstype) >= sizeof(lsi->lsi_fstype)) RETURN(-ENAMETOOLONG); - strlcpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile, + strscpy(lsi->lsi_svname, lsi->lsi_lmd->lmd_profile, sizeof(lsi->lsi_svname)); - strlcpy(lsi->lsi_osd_type, osd_type, sizeof(lsi->lsi_osd_type)); + strscpy(lsi->lsi_osd_type, osd_type, sizeof(lsi->lsi_osd_type)); /* XXX: a temp. solution for components using ldiskfs * to be removed in one of the subsequent patches */ - strlcpy(lsi->lsi_fstype, fstype, sizeof(lsi->lsi_fstype)); + strscpy(lsi->lsi_fstype, fstype, sizeof(lsi->lsi_fstype)); /* Determine server type */ rc = server_name2index(lsi->lsi_svname, &index, NULL);