X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fnrs_orr.c;h=38e2d05adb67c7e718c83141bed8dab75f692712;hb=5315db3f1066619d6effe4f778d2df3ad1ba738f;hp=53636293b219599ff0dd8534abcd9861e656a47b;hpb=e3afa6f49cd12e746f579d38c081b88f3db855cc;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/nrs_orr.c b/lustre/ptlrpc/nrs_orr.c index 5363629..38e2d05 100644 --- a/lustre/ptlrpc/nrs_orr.c +++ b/lustre/ptlrpc/nrs_orr.c @@ -20,7 +20,7 @@ * GPL HEADER END */ /* - * Copyright (c) 2013, Intel Corporation. + * Copyright (c) 2013, 2017, Intel Corporation. * * Copyright 2012 Xyratex Technology Limited */ @@ -45,7 +45,6 @@ #include #include #include -#include #include #include "ptlrpc_internal.h" @@ -154,6 +153,10 @@ static int nrs_orr_key_fill(struct nrs_orr_data *orrd, return 0; } + /* Bounce unconnected requests to the default policy. */ + if (req->rq_export == NULL) + return -ENOTCONN; + if (nrq->nr_u.orr.or_orr_set || nrq->nr_u.orr.or_trr_set) memset(&nrq->nr_u.orr.or_key, 0, sizeof(nrq->nr_u.orr.or_key)); @@ -196,9 +199,9 @@ static void nrs_orr_range_fill_logical(struct niobuf_remote *nb, int niocount, struct nrs_orr_req_range *range) { /* Should we do this at page boundaries ? */ - range->or_start = nb[0].offset & CFS_PAGE_MASK; - range->or_end = (nb[niocount - 1].offset + - nb[niocount - 1].len - 1) | ~CFS_PAGE_MASK; + range->or_start = nb[0].rnb_offset & PAGE_MASK; + range->or_end = (nb[niocount - 1].rnb_offset + + nb[niocount - 1].rnb_len - 1) | ~PAGE_MASK; } /** @@ -228,18 +231,18 @@ static int nrs_orr_range_fill_physical(struct ptlrpc_nrs_request *nrq, struct ptlrpc_request *req = container_of(nrq, struct ptlrpc_request, rq_nrq); - char fiemap_buf[offsetof(struct ll_user_fiemap, + char fiemap_buf[offsetof(struct fiemap, fm_extents[ORR_NUM_EXTENTS])]; - struct ll_user_fiemap *fiemap = (struct ll_user_fiemap *)fiemap_buf; + struct fiemap *fiemap = (struct fiemap *)fiemap_buf; struct ll_fiemap_info_key key; loff_t start; loff_t end; int rc; key = (typeof(key)) { - .name = KEY_FIEMAP, - .oa = *oa, - .fiemap = { + .lfik_name = KEY_FIEMAP, + .lfik_oa = *oa, + .lfik_fiemap = { .fm_start = range->or_start, .fm_length = range->or_end - range->or_start, .fm_extent_count = ORR_NUM_EXTENTS @@ -247,7 +250,7 @@ static int nrs_orr_range_fill_physical(struct ptlrpc_nrs_request *nrq, }; rc = obd_get_info(req->rq_svc_thread->t_env, req->rq_export, - sizeof(key), &key, NULL, fiemap, NULL); + sizeof(key), &key, NULL, fiemap); if (rc < 0) GOTO(out, rc); @@ -378,28 +381,29 @@ static void nrs_orr_genobjname(struct ptlrpc_nrs_policy *policy, char *name) */ #define NRS_ORR_BITS 24 #define NRS_ORR_BKT_BITS 12 -#define NRS_ORR_HASH_FLAGS (CFS_HASH_RW_BKTLOCK | CFS_HASH_ASSERT_EMPTY) +#define NRS_ORR_HASH_FLAGS (CFS_HASH_SPIN_BKTLOCK | CFS_HASH_ASSERT_EMPTY) #define NRS_TRR_BITS 4 #define NRS_TRR_BKT_BITS 2 -#define NRS_TRR_HASH_FLAGS CFS_HASH_RW_BKTLOCK +#define NRS_TRR_HASH_FLAGS CFS_HASH_SPIN_BKTLOCK -static unsigned nrs_orr_hop_hash(cfs_hash_t *hs, const void *key, unsigned mask) +static unsigned +nrs_orr_hop_hash(struct cfs_hash *hs, const void *key, unsigned mask) { return cfs_hash_djb2_hash(key, sizeof(struct nrs_orr_key), mask); } -static void *nrs_orr_hop_key(cfs_hlist_node_t *hnode) +static void *nrs_orr_hop_key(struct hlist_node *hnode) { - struct nrs_orr_object *orro = cfs_hlist_entry(hnode, + struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); return &orro->oo_key; } -static int nrs_orr_hop_keycmp(const void *key, cfs_hlist_node_t *hnode) +static int nrs_orr_hop_keycmp(const void *key, struct hlist_node *hnode) { - struct nrs_orr_object *orro = cfs_hlist_entry(hnode, + struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); @@ -407,93 +411,80 @@ static int nrs_orr_hop_keycmp(const void *key, cfs_hlist_node_t *hnode) &((struct nrs_orr_key *)key)->ok_fid); } -static void *nrs_orr_hop_object(cfs_hlist_node_t *hnode) +static void *nrs_orr_hop_object(struct hlist_node *hnode) { - return cfs_hlist_entry(hnode, struct nrs_orr_object, oo_hnode); + return hlist_entry(hnode, struct nrs_orr_object, oo_hnode); } -static void nrs_orr_hop_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void nrs_orr_hop_get(struct cfs_hash *hs, struct hlist_node *hnode) { - struct nrs_orr_object *orro = cfs_hlist_entry(hnode, + struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); - cfs_atomic_inc(&orro->oo_ref); + orro->oo_ref++; } /** * Removes an nrs_orr_object the hash and frees its memory, if the object has * no active users. */ -static void nrs_orr_hop_put_free(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void nrs_orr_hop_put_free(struct cfs_hash *hs, struct hlist_node *hnode) { - struct nrs_orr_object *orro = cfs_hlist_entry(hnode, + struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); struct nrs_orr_data *orrd = container_of(orro->oo_res.res_parent, struct nrs_orr_data, od_res); - cfs_hash_bd_t bds[2]; + struct cfs_hash_bd bd; - if (cfs_atomic_dec_return(&orro->oo_ref) > 1) - return; + cfs_hash_bd_get_and_lock(hs, &orro->oo_key, &bd, 1); - cfs_hash_lock(hs, 0); - cfs_hash_dual_bd_get_and_lock(hs, &orro->oo_key, bds, 1); + if (--orro->oo_ref > 1) { + cfs_hash_bd_unlock(hs, &bd, 1); - /** - * Another thread may have won the race and taken a reference on the - * nrs_orr_object. - */ - if (cfs_atomic_read(&orro->oo_ref) > 1) - goto lost_race; + return; + } + LASSERT(orro->oo_ref == 1); - if (bds[1].bd_bucket == NULL) - cfs_hash_bd_del_locked(hs, &bds[0], hnode); - else - hnode = cfs_hash_dual_bd_finddel_locked(hs, bds, &orro->oo_key, - hnode); - LASSERT(hnode != NULL); + cfs_hash_bd_del_locked(hs, &bd, hnode); + cfs_hash_bd_unlock(hs, &bd, 1); OBD_SLAB_FREE_PTR(orro, orrd->od_cache); - -lost_race: - - cfs_hash_dual_bd_unlock(hs, bds, 1); - cfs_hash_unlock(hs, 0); } -static void nrs_orr_hop_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void nrs_orr_hop_put(struct cfs_hash *hs, struct hlist_node *hnode) { - struct nrs_orr_object *orro = cfs_hlist_entry(hnode, + struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); - cfs_atomic_dec(&orro->oo_ref); + orro->oo_ref--; } -static int nrs_trr_hop_keycmp(const void *key, cfs_hlist_node_t *hnode) +static int nrs_trr_hop_keycmp(const void *key, struct hlist_node *hnode) { - struct nrs_orr_object *orro = cfs_hlist_entry(hnode, + struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); return orro->oo_key.ok_idx == ((struct nrs_orr_key *)key)->ok_idx; } -static void nrs_trr_hop_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode) +static void nrs_trr_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode) { - struct nrs_orr_object *orro = cfs_hlist_entry(hnode, + struct nrs_orr_object *orro = hlist_entry(hnode, struct nrs_orr_object, oo_hnode); struct nrs_orr_data *orrd = container_of(orro->oo_res.res_parent, struct nrs_orr_data, od_res); - LASSERTF(cfs_atomic_read(&orro->oo_ref) == 0, - "Busy NRS TRR policy object for OST with index %u, with %d " - "refs\n", orro->oo_key.ok_idx, cfs_atomic_read(&orro->oo_ref)); + LASSERTF(orro->oo_ref == 0, + "Busy NRS TRR policy object for OST with index %u, with %ld " + "refs\n", orro->oo_key.ok_idx, orro->oo_ref); OBD_SLAB_FREE_PTR(orro, orrd->od_cache); } -static cfs_hash_ops_t nrs_orr_hash_ops = { +static struct cfs_hash_ops nrs_orr_hash_ops = { .hs_hash = nrs_orr_hop_hash, .hs_key = nrs_orr_hop_key, .hs_keycmp = nrs_orr_hop_keycmp, @@ -503,7 +494,7 @@ static cfs_hash_ops_t nrs_orr_hash_ops = { .hs_put_locked = nrs_orr_hop_put, }; -static cfs_hash_ops_t nrs_trr_hash_ops = { +static struct cfs_hash_ops nrs_trr_hash_ops = { .hs_hash = nrs_orr_hop_hash, .hs_key = nrs_orr_hop_key, .hs_keycmp = nrs_trr_hop_keycmp, @@ -532,7 +523,8 @@ static cfs_hash_ops_t nrs_trr_hash_ops = { * \retval 0 e1 > e2 * \retval 1 e1 < e2 */ -static int orr_req_compare(cfs_binheap_node_t *e1, cfs_binheap_node_t *e2) +static int +orr_req_compare(struct cfs_binheap_node *e1, struct cfs_binheap_node *e2) { struct ptlrpc_nrs_request *nrq1; struct ptlrpc_nrs_request *nrq2; @@ -554,9 +546,9 @@ static int orr_req_compare(cfs_binheap_node_t *e1, cfs_binheap_node_t *e2) * backend-fs object (for ORR policy instances) or OST (for TRR policy * instances). */ - if (nrq1->nr_u.orr.or_sequence < nrq2->nr_u.crr.cr_sequence) + if (nrq1->nr_u.orr.or_sequence < nrq2->nr_u.orr.or_sequence) return 1; - else if (nrq1->nr_u.orr.or_sequence > nrq2->nr_u.crr.cr_sequence) + else if (nrq1->nr_u.orr.or_sequence > nrq2->nr_u.orr.or_sequence) return 0; /** @@ -587,7 +579,7 @@ static int orr_req_compare(cfs_binheap_node_t *e1, cfs_binheap_node_t *e2) /** * ORR binary heap operations */ -static cfs_binheap_ops_t nrs_orr_heap_ops = { +static struct cfs_binheap_ops nrs_orr_heap_ops = { .hop_enter = NULL, .hop_exit = NULL, .hop_compare = orr_req_compare, @@ -622,10 +614,10 @@ static int nrs_orr_init(struct ptlrpc_nrs_policy *policy) * \retval -ENOMEM OOM error * \retval 0 success */ -static int nrs_orr_start(struct ptlrpc_nrs_policy *policy) +static int nrs_orr_start(struct ptlrpc_nrs_policy *policy, char *arg) { struct nrs_orr_data *orrd; - cfs_hash_ops_t *ops; + struct cfs_hash_ops *ops; unsigned cur_bits; unsigned max_bits; unsigned bkt_bits; @@ -645,18 +637,18 @@ static int nrs_orr_start(struct ptlrpc_nrs_policy *policy) nrs_pol2cptab(policy), nrs_pol2cptid(policy)); if (orrd->od_binheap == NULL) - GOTO(failed, rc = -ENOMEM); + GOTO(out_orrd, rc = -ENOMEM); nrs_orr_genobjname(policy, orrd->od_objname); /** * Slab cache for NRS ORR/TRR objects. */ - orrd->od_cache = cfs_mem_cache_create(orrd->od_objname, - sizeof(struct nrs_orr_object), - 0, 0); + orrd->od_cache = kmem_cache_create(orrd->od_objname, + sizeof(struct nrs_orr_object), + 0, 0, NULL); if (orrd->od_cache == NULL) - GOTO(failed, rc = -ENOMEM); + GOTO(out_binheap, rc = -ENOMEM); if (strncmp(policy->pol_desc->pd_name, NRS_POL_NAME_ORR, NRS_POL_NAME_MAX) == 0) { @@ -684,7 +676,7 @@ static int nrs_orr_start(struct ptlrpc_nrs_policy *policy) CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA, ops, flags); if (orrd->od_obj_hash == NULL) - GOTO(failed, rc = -ENOMEM); + GOTO(out_cache, rc = -ENOMEM); /* XXX: Fields accessed unlocked */ orrd->od_quantum = NRS_ORR_QUANTUM_DFLT; @@ -700,14 +692,11 @@ static int nrs_orr_start(struct ptlrpc_nrs_policy *policy) RETURN(rc); -failed: - if (orrd->od_cache) { - rc = cfs_mem_cache_destroy(orrd->od_cache); - LASSERTF(rc == 0, "Could not destroy od_cache slab\n"); - } - if (orrd->od_binheap != NULL) - cfs_binheap_destroy(orrd->od_binheap); - +out_cache: + kmem_cache_destroy(orrd->od_cache); +out_binheap: + cfs_binheap_destroy(orrd->od_binheap); +out_orrd: OBD_FREE_PTR(orrd); RETURN(rc); @@ -735,7 +724,7 @@ static void nrs_orr_stop(struct ptlrpc_nrs_policy *policy) cfs_binheap_destroy(orrd->od_binheap); cfs_hash_putref(orrd->od_obj_hash); - cfs_mem_cache_destroy(orrd->od_cache); + kmem_cache_destroy(orrd->od_cache); OBD_FREE_PTR(orrd); } @@ -748,16 +737,16 @@ static void nrs_orr_stop(struct ptlrpc_nrs_policy *policy) * \param[in] opc the opcode * \param[in,out] arg used for passing parameters and information * - * \pre spin_is_locked(&policy->pol_nrs->->nrs_lock) - * \post spin_is_locked(&policy->pol_nrs->->nrs_lock) + * \pre assert_spin_locked(&policy->pol_nrs->->nrs_lock) + * \post assert_spin_locked(&policy->pol_nrs->->nrs_lock) * * \retval 0 operation carried successfully * \retval -ve error */ -int nrs_orr_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc, - void *arg) +static int nrs_orr_ctl(struct ptlrpc_nrs_policy *policy, + enum ptlrpc_nrs_ctl opc, void *arg) { - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_lock); switch((enum nrs_ctl_orr)opc) { default: @@ -832,10 +821,10 @@ int nrs_orr_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc, * * \see nrs_resource_get_safe() */ -int nrs_orr_res_get(struct ptlrpc_nrs_policy *policy, - struct ptlrpc_nrs_request *nrq, - const struct ptlrpc_nrs_resource *parent, - struct ptlrpc_nrs_resource **resp, bool moving_req) +static int nrs_orr_res_get(struct ptlrpc_nrs_policy *policy, + struct ptlrpc_nrs_request *nrq, + const struct ptlrpc_nrs_resource *parent, + struct ptlrpc_nrs_resource **resp, bool moving_req) { struct nrs_orr_data *orrd; struct nrs_orr_object *orro; @@ -882,13 +871,12 @@ int nrs_orr_res_get(struct ptlrpc_nrs_policy *policy, OBD_SLAB_CPT_ALLOC_PTR_GFP(orro, orrd->od_cache, nrs_pol2cptab(policy), nrs_pol2cptid(policy), - (moving_req ? CFS_ALLOC_ATOMIC : - CFS_ALLOC_IO)); + moving_req ? GFP_ATOMIC : GFP_NOFS); if (orro == NULL) RETURN(-ENOMEM); orro->oo_key = key; - cfs_atomic_set(&orro->oo_ref, 1); + orro->oo_ref = 1; tmp = cfs_hash_findadd_unique(orrd->od_obj_hash, &orro->oo_key, &orro->oo_hnode); @@ -955,7 +943,7 @@ struct ptlrpc_nrs_request *nrs_orr_req_get(struct ptlrpc_nrs_policy *policy, bool peek, bool force) { struct nrs_orr_data *orrd = policy->pol_private; - cfs_binheap_node_t *node = cfs_binheap_root(orrd->od_binheap); + struct cfs_binheap_node *node = cfs_binheap_root(orrd->od_binheap); struct ptlrpc_nrs_request *nrq; nrq = unlikely(node == NULL) ? NULL : @@ -977,14 +965,14 @@ struct ptlrpc_nrs_request *nrs_orr_req_get(struct ptlrpc_nrs_policy *policy, CDEBUG(D_RPCTRACE, "NRS: starting to handle %s request for object " "with FID "DFID", from OST with index %u, with " - "round "LPU64"\n", NRS_POL_NAME_ORR, + "round %llu\n", NRS_POL_NAME_ORR, PFID(&orro->oo_key.ok_fid), nrq->nr_u.orr.or_key.ok_idx, nrq->nr_u.orr.or_round); else CDEBUG(D_RPCTRACE, "NRS: starting to handle %s request from OST " - "with index %u, with round "LPU64"\n", + "with index %u, with round %llu\n", NRS_POL_NAME_TRR, nrq->nr_u.orr.or_key.ok_idx, nrq->nr_u.orr.or_round); @@ -1086,8 +1074,8 @@ static int nrs_orr_req_add(struct ptlrpc_nrs_policy *policy, orro->oo_quantum = orrd->od_quantum; } - nrq->nr_u.crr.cr_round = orro->oo_round; - nrq->nr_u.crr.cr_sequence = orro->oo_sequence; + nrq->nr_u.orr.or_round = orro->oo_round; + nrq->nr_u.orr.or_sequence = orro->oo_sequence; rc = cfs_binheap_insert(orrd->od_binheap, &nrq->nr_node); if (rc == 0) { @@ -1130,7 +1118,7 @@ static void nrs_orr_req_del(struct ptlrpc_nrs_policy *policy, */ if (unlikely(is_root)) { /** Peek at the next request to be served */ - cfs_binheap_node_t *node = cfs_binheap_root(orrd->od_binheap); + struct cfs_binheap_node *node = cfs_binheap_root(orrd->od_binheap); /** No more requests */ if (unlikely(node == NULL)) { @@ -1160,29 +1148,27 @@ static void nrs_orr_req_stop(struct ptlrpc_nrs_policy *policy, NRS_POL_NAME_MAX) == 0) CDEBUG(D_RPCTRACE, "NRS: finished handling %s request for object with FID " - DFID", from OST with index %u, with round "LPU64"\n", + DFID", from OST with index %u, with round %llu\n", NRS_POL_NAME_ORR, PFID(&nrq->nr_u.orr.or_key.ok_fid), nrq->nr_u.orr.or_key.ok_idx, nrq->nr_u.orr.or_round); else CDEBUG(D_RPCTRACE, "NRS: finished handling %s request from OST with index %u," - " with round "LPU64"\n", + " with round %llu\n", NRS_POL_NAME_TRR, nrq->nr_u.orr.or_key.ok_idx, nrq->nr_u.orr.or_round); } /** - * lprocfs interface + * debugfs interface */ -#ifdef LPROCFS - /** * This allows to bundle the policy name into the lprocfs_vars::data pointer * so that lprocfs read/write functions can be used by both the ORR and TRR * policies. */ -struct nrs_lprocfs_orr_data { +static struct nrs_lprocfs_orr_data { struct ptlrpc_service *svc; char *name; } lprocfs_orr_data = { @@ -1208,15 +1194,13 @@ struct nrs_lprocfs_orr_data { * XXX: the CRR-N version of this, ptlrpc_lprocfs_rd_nrs_crrn_quantum() is * almost identical; it can be reworked and then reused for ORR/TRR. */ -static int ptlrpc_lprocfs_rd_nrs_orr_quantum(char *page, char **start, - off_t off, int count, int *eof, - void *data) +static int +ptlrpc_lprocfs_nrs_orr_quantum_seq_show(struct seq_file *m, void *data) { - struct nrs_lprocfs_orr_data *orr_data = data; + struct nrs_lprocfs_orr_data *orr_data = m->private; struct ptlrpc_service *svc = orr_data->svc; __u16 quantum; int rc; - int rc2 = 0; /** * Perform two separate calls to this as only one of the NRS heads' @@ -1228,9 +1212,7 @@ static int ptlrpc_lprocfs_rd_nrs_orr_quantum(char *page, char **start, NRS_CTL_ORR_RD_QUANTUM, true, &quantum); if (rc == 0) { - *eof = 1; - rc2 = snprintf(page, count, NRS_LPROCFS_QUANTUM_NAME_REG - "%-5d\n", quantum); + seq_printf(m, NRS_LPROCFS_QUANTUM_NAME_REG "%-5d\n", quantum); /** * Ignore -ENODEV as the regular NRS head's policy may be in the * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state. @@ -1251,9 +1233,7 @@ static int ptlrpc_lprocfs_rd_nrs_orr_quantum(char *page, char **start, orr_data->name, NRS_CTL_ORR_RD_QUANTUM, true, &quantum); if (rc == 0) { - *eof = 1; - rc2 += snprintf(page + rc2, count - rc2, - NRS_LPROCFS_QUANTUM_NAME_HP"%-5d\n", quantum); + seq_printf(m, NRS_LPROCFS_QUANTUM_NAME_HP"%-5d\n", quantum); /** * Ignore -ENODEV as the high priority NRS head's policy may be * in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state. @@ -1264,7 +1244,7 @@ static int ptlrpc_lprocfs_rd_nrs_orr_quantum(char *page, char **start, no_hp: - return rc2 ? : rc; + return rc; } /** @@ -1293,11 +1273,13 @@ no_hp: * XXX: the CRR-N version of this, ptlrpc_lprocfs_wr_nrs_crrn_quantum() is * almost identical; it can be reworked and then reused for ORR/TRR. */ -static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, - const char *buffer, - unsigned long count, void *data) +static ssize_t +ptlrpc_lprocfs_nrs_orr_quantum_seq_write(struct file *file, + const char __user *buffer, + size_t count, loff_t *off) { - struct nrs_lprocfs_orr_data *orr_data = data; + struct seq_file *m = file->private_data; + struct nrs_lprocfs_orr_data *orr_data = m->private; struct ptlrpc_service *svc = orr_data->svc; enum ptlrpc_nrs_queue_type queue = 0; char kernbuf[LPROCFS_NRS_WR_QUANTUM_MAX_CMD]; @@ -1305,14 +1287,14 @@ static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, long quantum_reg; long quantum_hp; /** lprocfs_find_named_value() modifies its argument, so keep a copy */ - unsigned long count_copy; + size_t count_copy; int rc = 0; int rc2 = 0; if (count > (sizeof(kernbuf) - 1)) return -EINVAL; - if (cfs_copy_from_user(kernbuf, buffer, count)) + if (copy_from_user(kernbuf, buffer, count)) return -EFAULT; kernbuf[count] = '\0'; @@ -1325,8 +1307,9 @@ static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, val = lprocfs_find_named_value(kernbuf, NRS_LPROCFS_QUANTUM_NAME_REG, &count_copy); if (val != kernbuf) { - quantum_reg = simple_strtol(val, NULL, 10); - + rc = kstrtol(val, 10, &quantum_reg); + if (rc) + return rc; queue |= PTLRPC_NRS_QUEUE_REG; } @@ -1341,7 +1324,9 @@ static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, if (!nrs_svc_has_hp(svc)) return -ENODEV; - quantum_hp = simple_strtol(val, NULL, 10); + rc = kstrtol(val, 10, &quantum_hp); + if (rc) + return rc; queue |= PTLRPC_NRS_QUEUE_HP; } @@ -1351,10 +1336,9 @@ static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, * value */ if (queue == 0) { - if (!isdigit(kernbuf[0])) - return -EINVAL; - - quantum_reg = simple_strtol(kernbuf, NULL, 10); + rc = kstrtol(kernbuf, 10, &quantum_reg); + if (rc) + return rc; queue = PTLRPC_NRS_QUEUE_REG; @@ -1403,6 +1387,8 @@ static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, return rc == -ENODEV && rc2 == -ENODEV ? -ENODEV : count; } +LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_nrs_orr_quantum); + #define LPROCFS_NRS_OFF_NAME_REG "reg_offset_type:" #define LPROCFS_NRS_OFF_NAME_HP "hp_offset_type:" @@ -1423,15 +1409,13 @@ static int ptlrpc_lprocfs_wr_nrs_orr_quantum(struct file *file, * reg_offset_type:physical * hp_offset_type:logical */ -static int ptlrpc_lprocfs_rd_nrs_orr_offset_type(char *page, char **start, - off_t off, int count, int *eof, - void *data) +static int +ptlrpc_lprocfs_nrs_orr_offset_type_seq_show(struct seq_file *m, void *data) { - struct nrs_lprocfs_orr_data *orr_data = data; + struct nrs_lprocfs_orr_data *orr_data = m->private; struct ptlrpc_service *svc = orr_data->svc; bool physical; int rc; - int rc2 = 0; /** * Perform two separate calls to this as only one of the NRS heads' @@ -1442,11 +1426,9 @@ static int ptlrpc_lprocfs_rd_nrs_orr_offset_type(char *page, char **start, orr_data->name, NRS_CTL_ORR_RD_OFF_TYPE, true, &physical); if (rc == 0) { - *eof = 1; - rc2 = snprintf(page, count, - LPROCFS_NRS_OFF_NAME_REG"%s\n", - physical ? LPROCFS_NRS_OFF_NAME_PHYSICAL : - LPROCFS_NRS_OFF_NAME_LOGICAL); + seq_printf(m, LPROCFS_NRS_OFF_NAME_REG"%s\n", + physical ? LPROCFS_NRS_OFF_NAME_PHYSICAL : + LPROCFS_NRS_OFF_NAME_LOGICAL); /** * Ignore -ENODEV as the regular NRS head's policy may be in the * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state. @@ -1467,11 +1449,9 @@ static int ptlrpc_lprocfs_rd_nrs_orr_offset_type(char *page, char **start, orr_data->name, NRS_CTL_ORR_RD_OFF_TYPE, true, &physical); if (rc == 0) { - *eof = 1; - rc2 += snprintf(page + rc2, count - rc2, - LPROCFS_NRS_OFF_NAME_HP"%s\n", - physical ? LPROCFS_NRS_OFF_NAME_PHYSICAL : - LPROCFS_NRS_OFF_NAME_LOGICAL); + seq_printf(m, LPROCFS_NRS_OFF_NAME_HP"%s\n", + physical ? LPROCFS_NRS_OFF_NAME_PHYSICAL : + LPROCFS_NRS_OFF_NAME_LOGICAL); /** * Ignore -ENODEV as the high priority NRS head's policy may be * in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state. @@ -1481,8 +1461,7 @@ static int ptlrpc_lprocfs_rd_nrs_orr_offset_type(char *page, char **start, } no_hp: - - return rc2 ? : rc; + return rc; } /** @@ -1511,12 +1490,14 @@ no_hp: * policy instances in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state are * are skipped later by nrs_orr_ctl(). */ -static int ptlrpc_lprocfs_wr_nrs_orr_offset_type(struct file *file, - const char *buffer, - unsigned long count, - void *data) +static ssize_t +ptlrpc_lprocfs_nrs_orr_offset_type_seq_write(struct file *file, + const char __user *buffer, + size_t count, + loff_t *off) { - struct nrs_lprocfs_orr_data *orr_data = data; + struct seq_file *m = file->private_data; + struct nrs_lprocfs_orr_data *orr_data = m->private; struct ptlrpc_service *svc = orr_data->svc; enum ptlrpc_nrs_queue_type queue = 0; char kernbuf[LPROCFS_NRS_WR_OFF_TYPE_MAX_CMD]; @@ -1524,14 +1505,14 @@ static int ptlrpc_lprocfs_wr_nrs_orr_offset_type(struct file *file, char *val_hp; bool physical_reg; bool physical_hp; - unsigned long count_copy; + size_t count_copy; int rc = 0; int rc2 = 0; if (count > (sizeof(kernbuf) - 1)) return -EINVAL; - if (cfs_copy_from_user(kernbuf, buffer, count)) + if (copy_from_user(kernbuf, buffer, count)) return -EFAULT; kernbuf[count] = '\0'; @@ -1627,6 +1608,8 @@ static int ptlrpc_lprocfs_wr_nrs_orr_offset_type(struct file *file, return rc == -ENODEV && rc2 == -ENODEV ? -ENODEV : count; } +LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_nrs_orr_offset_type); + #define NRS_LPROCFS_REQ_SUPP_NAME_REG "reg_supported:" #define NRS_LPROCFS_REQ_SUPP_NAME_HP "hp_supported:" @@ -1684,15 +1667,13 @@ static enum nrs_orr_supp nrs_orr_str2supp(const char *val) * reg_supported:reads * hp_supported:reads_and_writes */ -static int ptlrpc_lprocfs_rd_nrs_orr_supported(char *page, char **start, - off_t off, int count, int *eof, - void *data) +static int +ptlrpc_lprocfs_nrs_orr_supported_seq_show(struct seq_file *m, void *data) { - struct nrs_lprocfs_orr_data *orr_data = data; + struct nrs_lprocfs_orr_data *orr_data = m->private; struct ptlrpc_service *svc = orr_data->svc; enum nrs_orr_supp supported; int rc; - int rc2 = 0; /** * Perform two separate calls to this as only one of the NRS heads' @@ -1705,10 +1686,8 @@ static int ptlrpc_lprocfs_rd_nrs_orr_supported(char *page, char **start, &supported); if (rc == 0) { - *eof = 1; - rc2 = snprintf(page, count, - NRS_LPROCFS_REQ_SUPP_NAME_REG"%s\n", - nrs_orr_supp2str(supported)); + seq_printf(m, NRS_LPROCFS_REQ_SUPP_NAME_REG"%s\n", + nrs_orr_supp2str(supported)); /** * Ignore -ENODEV as the regular NRS head's policy may be in the * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state. @@ -1730,10 +1709,8 @@ static int ptlrpc_lprocfs_rd_nrs_orr_supported(char *page, char **start, NRS_CTL_ORR_RD_SUPP_REQ, true, &supported); if (rc == 0) { - *eof = 1; - rc2 += snprintf(page + rc2, count - rc2, - NRS_LPROCFS_REQ_SUPP_NAME_HP"%s\n", - nrs_orr_supp2str(supported)); + seq_printf(m, NRS_LPROCFS_REQ_SUPP_NAME_HP"%s\n", + nrs_orr_supp2str(supported)); /** * Ignore -ENODEV as the high priority NRS head's policy may be * in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state. @@ -1744,7 +1721,7 @@ static int ptlrpc_lprocfs_rd_nrs_orr_supported(char *page, char **start, no_hp: - return rc2 ? : rc; + return rc; } /** @@ -1774,11 +1751,14 @@ no_hp: * policy instances in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state are * are skipped later by nrs_orr_ctl(). */ -static int ptlrpc_lprocfs_wr_nrs_orr_supported(struct file *file, - const char *buffer, - unsigned long count, void *data) +static ssize_t +ptlrpc_lprocfs_nrs_orr_supported_seq_write(struct file *file, + const char __user *buffer, + size_t count, + loff_t *off) { - struct nrs_lprocfs_orr_data *orr_data = data; + struct seq_file *m = file->private_data; + struct nrs_lprocfs_orr_data *orr_data = m->private; struct ptlrpc_service *svc = orr_data->svc; enum ptlrpc_nrs_queue_type queue = 0; char kernbuf[LPROCFS_NRS_WR_REQ_SUPP_MAX_CMD]; @@ -1786,14 +1766,14 @@ static int ptlrpc_lprocfs_wr_nrs_orr_supported(struct file *file, char *val_hp; enum nrs_orr_supp supp_reg; enum nrs_orr_supp supp_hp; - unsigned long count_copy; + size_t count_copy; int rc = 0; int rc2 = 0; if (count > (sizeof(kernbuf) - 1)) return -EINVAL; - if (cfs_copy_from_user(kernbuf, buffer, count)) + if (copy_from_user(kernbuf, buffer, count)) return -EFAULT; kernbuf[count] = '\0'; @@ -1880,25 +1860,23 @@ static int ptlrpc_lprocfs_wr_nrs_orr_supported(struct file *file, return rc == -ENODEV && rc2 == -ENODEV ? -ENODEV : count; } -int nrs_orr_lprocfs_init(struct ptlrpc_service *svc) +LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_nrs_orr_supported); + +static int nrs_orr_lprocfs_init(struct ptlrpc_service *svc) { - int rc; int i; struct lprocfs_vars nrs_orr_lprocfs_vars[] = { { .name = "nrs_orr_quantum", - .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_quantum, - .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_quantum }, + .fops = &ptlrpc_lprocfs_nrs_orr_quantum_fops }, { .name = "nrs_orr_offset_type", - .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_offset_type, - .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_offset_type }, + .fops = &ptlrpc_lprocfs_nrs_orr_offset_type_fops }, { .name = "nrs_orr_supported", - .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_supported, - .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_supported }, + .fops = &ptlrpc_lprocfs_nrs_orr_supported_fops }, { NULL } }; - if (svc->srv_procroot == NULL) + if (!svc->srv_debugfs_entry) return 0; lprocfs_orr_data.svc = svc; @@ -1906,23 +1884,10 @@ int nrs_orr_lprocfs_init(struct ptlrpc_service *svc) for (i = 0; i < ARRAY_SIZE(nrs_orr_lprocfs_vars); i++) nrs_orr_lprocfs_vars[i].data = &lprocfs_orr_data; - rc = lprocfs_add_vars(svc->srv_procroot, nrs_orr_lprocfs_vars, NULL); - - return rc; -} - -void nrs_orr_lprocfs_fini(struct ptlrpc_service *svc) -{ - if (svc->srv_procroot == NULL) - return; - - lprocfs_remove_proc_entry("nrs_orr_quantum", svc->srv_procroot); - lprocfs_remove_proc_entry("nrs_orr_offset_type", svc->srv_procroot); - lprocfs_remove_proc_entry("nrs_orr_supported", svc->srv_procroot); + return ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_orr_lprocfs_vars, + NULL); } -#endif /* LPROCFS */ - static const struct ptlrpc_nrs_pol_ops nrs_orr_ops = { .op_policy_init = nrs_orr_init, .op_policy_start = nrs_orr_start, @@ -1934,10 +1899,7 @@ static const struct ptlrpc_nrs_pol_ops nrs_orr_ops = { .op_req_enqueue = nrs_orr_req_add, .op_req_dequeue = nrs_orr_req_del, .op_req_stop = nrs_orr_req_stop, -#ifdef LPROCFS .op_lprocfs_init = nrs_orr_lprocfs_init, - .op_lprocfs_fini = nrs_orr_lprocfs_fini, -#endif }; struct ptlrpc_nrs_pol_conf nrs_conf_orr = { @@ -1952,28 +1914,21 @@ struct ptlrpc_nrs_pol_conf nrs_conf_orr = { * * TRR reuses much of the functions and data structures of ORR */ - -#ifdef LPROCFS - -int nrs_trr_lprocfs_init(struct ptlrpc_service *svc) +static int nrs_trr_lprocfs_init(struct ptlrpc_service *svc) { - int rc; int i; struct lprocfs_vars nrs_trr_lprocfs_vars[] = { { .name = "nrs_trr_quantum", - .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_quantum, - .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_quantum }, + .fops = &ptlrpc_lprocfs_nrs_orr_quantum_fops }, { .name = "nrs_trr_offset_type", - .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_offset_type, - .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_offset_type }, + .fops = &ptlrpc_lprocfs_nrs_orr_offset_type_fops }, { .name = "nrs_trr_supported", - .read_fptr = ptlrpc_lprocfs_rd_nrs_orr_supported, - .write_fptr = ptlrpc_lprocfs_wr_nrs_orr_supported }, + .fops = &ptlrpc_lprocfs_nrs_orr_supported_fops }, { NULL } }; - if (svc->srv_procroot == NULL) + if (!svc->srv_debugfs_entry) return 0; lprocfs_trr_data.svc = svc; @@ -1981,23 +1936,10 @@ int nrs_trr_lprocfs_init(struct ptlrpc_service *svc) for (i = 0; i < ARRAY_SIZE(nrs_trr_lprocfs_vars); i++) nrs_trr_lprocfs_vars[i].data = &lprocfs_trr_data; - rc = lprocfs_add_vars(svc->srv_procroot, nrs_trr_lprocfs_vars, NULL); - - return rc; + return ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_trr_lprocfs_vars, + NULL); } -void nrs_trr_lprocfs_fini(struct ptlrpc_service *svc) -{ - if (svc->srv_procroot == NULL) - return; - - lprocfs_remove_proc_entry("nrs_trr_quantum", svc->srv_procroot); - lprocfs_remove_proc_entry("nrs_trr_offset_type", svc->srv_procroot); - lprocfs_remove_proc_entry("nrs_trr_supported", svc->srv_procroot); -} - -#endif /* LPROCFS */ - /** * Reuse much of the ORR functionality for TRR. */ @@ -2012,10 +1954,7 @@ static const struct ptlrpc_nrs_pol_ops nrs_trr_ops = { .op_req_enqueue = nrs_orr_req_add, .op_req_dequeue = nrs_orr_req_del, .op_req_stop = nrs_orr_req_stop, -#ifdef LPROCFS .op_lprocfs_init = nrs_trr_lprocfs_init, - .op_lprocfs_fini = nrs_trr_lprocfs_fini, -#endif }; struct ptlrpc_nrs_pol_conf nrs_conf_trr = {