1184588Sdfr/*- 2184588Sdfr * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 3184588Sdfr * 4184588Sdfr * Redistribution and use in source and binary forms, with or without 5184588Sdfr * modification, are permitted provided that the following conditions 6184588Sdfr * are met: 7184588Sdfr * 1. Redistributions of source code must retain the above copyright 8184588Sdfr * notice, this list of conditions and the following disclaimer. 9184588Sdfr * 2. Redistributions in binary form must reproduce the above copyright 10184588Sdfr * notice, this list of conditions and the following disclaimer in the 11184588Sdfr * documentation and/or other materials provided with the distribution. 12184588Sdfr * 13184588Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14184588Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15184588Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16184588Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17184588Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18184588Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19184588Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20184588Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21184588Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22184588Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23184588Sdfr * SUCH DAMAGE. 24184588Sdfr */ 25184588Sdfr 26184588Sdfr#include <sys/cdefs.h> 27184588Sdfr__FBSDID("$FreeBSD: releng/10.3/sys/nfs/nfs_fha.c 267753 2014-06-22 21:26:46Z mav $"); 28184588Sdfr 29184588Sdfr#include <sys/param.h> 30184588Sdfr#include <sys/systm.h> 31184588Sdfr#include <sys/sysproto.h> 32184588Sdfr#include <sys/kernel.h> 33184588Sdfr#include <sys/sysctl.h> 34184588Sdfr#include <sys/vnode.h> 35184588Sdfr#include <sys/malloc.h> 36184588Sdfr#include <sys/mount.h> 37184588Sdfr#include <sys/mbuf.h> 38184588Sdfr#include <sys/sbuf.h> 39184588Sdfr 40184588Sdfr#include <rpc/rpc.h> 41249596Sken#include <nfs/nfs_fha.h> 42184588Sdfr 43184588Sdfrstatic MALLOC_DEFINE(M_NFS_FHA, "NFS FHA", "NFS FHA"); 44184588Sdfr 45201899Smarius/* 46249592Sken * XXX need to commonize definitions between old and new NFS code. Define 47249592Sken * this here so we don't include one nfsproto.h over the other. 48184588Sdfr */ 49249592Sken#define NFS_PROG 100003 50184588Sdfr 51249592Skenvoid 52249592Skenfha_init(struct fha_params *softc) 53184588Sdfr{ 54249592Sken char tmpstr[128]; 55261054Smav int i; 56184588Sdfr 57261054Smav for (i = 0; i < FHA_HASH_SIZE; i++) 58261054Smav mtx_init(&softc->fha_hash[i].mtx, "fhalock", NULL, MTX_DEF); 59184588Sdfr 60184588Sdfr /* 61249592Sken * Set the default tuning parameters. 62184588Sdfr */ 63249592Sken softc->ctls.enable = FHA_DEF_ENABLE; 64249592Sken softc->ctls.bin_shift = FHA_DEF_BIN_SHIFT; 65249592Sken softc->ctls.max_nfsds_per_fh = FHA_DEF_MAX_NFSDS_PER_FH; 66249592Sken softc->ctls.max_reqs_per_nfsd = FHA_DEF_MAX_REQS_PER_NFSD; 67184588Sdfr 68249592Sken /* 69249592Sken * Allow the user to override the defaults at boot time with 70249592Sken * tunables. 71249592Sken */ 72249592Sken snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.enable", 73249592Sken softc->server_name); 74249592Sken TUNABLE_INT_FETCH(tmpstr, &softc->ctls.enable); 75249592Sken snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.bin_shift", 76249592Sken softc->server_name); 77249592Sken TUNABLE_INT_FETCH(tmpstr, &softc->ctls.bin_shift); 78249592Sken snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.max_nfsds_per_fh", 79249592Sken softc->server_name); 80249592Sken TUNABLE_INT_FETCH(tmpstr, &softc->ctls.max_nfsds_per_fh); 81249592Sken snprintf(tmpstr, sizeof(tmpstr), "vfs.%s.fha.max_reqs_per_nfsd", 82249592Sken softc->server_name); 83249592Sken TUNABLE_INT_FETCH(tmpstr, &softc->ctls.max_reqs_per_nfsd); 84184588Sdfr 85249592Sken /* 86249592Sken * Add sysctls so the user can change the tuning parameters at 87249592Sken * runtime. 88249592Sken */ 89249592Sken SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 90249592Sken OID_AUTO, "enable", CTLFLAG_RW, 91249592Sken &softc->ctls.enable, 0, "Enable NFS File Handle Affinity (FHA)"); 92249592Sken 93249592Sken SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 94184588Sdfr OID_AUTO, "bin_shift", CTLFLAG_RW, 95249592Sken &softc->ctls.bin_shift, 0, "For FHA reads, no two requests will " 96184588Sdfr "contend if they're 2^(bin_shift) bytes apart"); 97184588Sdfr 98249592Sken SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 99184588Sdfr OID_AUTO, "max_nfsds_per_fh", CTLFLAG_RW, 100249592Sken &softc->ctls.max_nfsds_per_fh, 0, "Maximum nfsd threads that " 101184588Sdfr "should be working on requests for the same file handle"); 102184588Sdfr 103249592Sken SYSCTL_ADD_UINT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 104184588Sdfr OID_AUTO, "max_reqs_per_nfsd", CTLFLAG_RW, 105249592Sken &softc->ctls.max_reqs_per_nfsd, 0, "Maximum requests that " 106184588Sdfr "single nfsd thread should be working on at any time"); 107184588Sdfr 108249592Sken SYSCTL_ADD_OID(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 109184588Sdfr OID_AUTO, "fhe_stats", CTLTYPE_STRING | CTLFLAG_RD, 0, 0, 110249592Sken softc->callbacks.fhe_stats_sysctl, "A", ""); 111249592Sken 112184588Sdfr} 113184588Sdfr 114249592Skenvoid 115249592Skenfha_uninit(struct fha_params *softc) 116184588Sdfr{ 117261054Smav int i; 118261054Smav 119249592Sken sysctl_ctx_free(&softc->sysctl_ctx); 120261054Smav for (i = 0; i < FHA_HASH_SIZE; i++) 121261054Smav mtx_destroy(&softc->fha_hash[i].mtx); 122184588Sdfr} 123184588Sdfr 124201899Smarius/* 125184588Sdfr * This just specifies that offsets should obey affinity when within 126184588Sdfr * the same 1Mbyte (1<<20) chunk for the file (reads only for now). 127184588Sdfr */ 128184588Sdfrstatic void 129249592Skenfha_extract_info(struct svc_req *req, struct fha_info *i, 130249592Sken struct fha_callbacks *cb) 131184588Sdfr{ 132201896Smarius struct mbuf *md; 133201896Smarius caddr_t dpos; 134184588Sdfr static u_int64_t random_fh = 0; 135184588Sdfr int error; 136184588Sdfr int v3 = (req->rq_vers == 3); 137184588Sdfr rpcproc_t procnum; 138184588Sdfr 139201899Smarius /* 140201899Smarius * We start off with a random fh. If we get a reasonable 141201899Smarius * procnum, we set the fh. If there's a concept of offset 142184588Sdfr * that we're interested in, we set that. 143184588Sdfr */ 144184588Sdfr i->fh = ++random_fh; 145184588Sdfr i->offset = 0; 146184588Sdfr i->locktype = LK_EXCLUSIVE; 147201899Smarius 148184588Sdfr /* 149184744Sdfr * Extract the procnum and convert to v3 form if necessary, 150201899Smarius * taking care to deal with out-of-range procnums. Caller will 151184744Sdfr * ensure that rq_vers is either 2 or 3. 152184588Sdfr */ 153184588Sdfr procnum = req->rq_proc; 154184744Sdfr if (!v3) { 155249592Sken rpcproc_t tmp_procnum; 156249592Sken 157249592Sken tmp_procnum = cb->get_procnum(procnum); 158249592Sken if (tmp_procnum == -1) 159184744Sdfr goto out; 160249592Sken procnum = tmp_procnum; 161184744Sdfr } 162184588Sdfr 163201899Smarius /* 164201899Smarius * We do affinity for most. However, we divide a realm of affinity 165201899Smarius * by file offset so as to allow for concurrent random access. We 166201899Smarius * only do this for reads today, but this may change when IFS supports 167184588Sdfr * efficient concurrent writes. 168184588Sdfr */ 169249592Sken if (cb->no_offset(procnum)) 170184588Sdfr goto out; 171201899Smarius 172249592Sken error = cb->realign(&req->rq_args, M_NOWAIT); 173203732Smarius if (error) 174203732Smarius goto out; 175201896Smarius md = req->rq_args; 176201896Smarius dpos = mtod(md, caddr_t); 177201896Smarius 178184588Sdfr /* Grab the filehandle. */ 179261049Smav error = cb->get_fh(&i->fh, v3, &md, &dpos); 180184588Sdfr if (error) 181184588Sdfr goto out; 182184588Sdfr 183184588Sdfr /* Content ourselves with zero offset for all but reads. */ 184249592Sken if (cb->is_read(procnum) || cb->is_write(procnum)) 185249592Sken cb->get_offset(&md, &dpos, v3, i); 186184588Sdfr 187249592Skenout: 188249592Sken cb->set_locktype(procnum, i); 189184588Sdfr} 190184588Sdfr 191184588Sdfrstatic struct fha_hash_entry * 192184588Sdfrfha_hash_entry_new(u_int64_t fh) 193184588Sdfr{ 194184588Sdfr struct fha_hash_entry *e; 195184588Sdfr 196184588Sdfr e = malloc(sizeof(*e), M_NFS_FHA, M_WAITOK); 197184588Sdfr e->fh = fh; 198249592Sken e->num_rw = 0; 199249592Sken e->num_exclusive = 0; 200184588Sdfr e->num_threads = 0; 201184588Sdfr LIST_INIT(&e->threads); 202201899Smarius 203201899Smarius return (e); 204184588Sdfr} 205184588Sdfr 206184588Sdfrstatic void 207184588Sdfrfha_hash_entry_destroy(struct fha_hash_entry *e) 208184588Sdfr{ 209184588Sdfr 210261054Smav mtx_assert(e->mtx, MA_OWNED); 211261054Smav KASSERT(e->num_rw == 0, 212261054Smav ("%d reqs on destroyed fhe %p", e->num_rw, e)); 213261054Smav KASSERT(e->num_exclusive == 0, 214261054Smav ("%d exclusive reqs on destroyed fhe %p", e->num_exclusive, e)); 215261054Smav KASSERT(e->num_threads == 0, 216261054Smav ("%d threads on destroyed fhe %p", e->num_threads, e)); 217184588Sdfr free(e, M_NFS_FHA); 218184588Sdfr} 219184588Sdfr 220184588Sdfrstatic void 221184588Sdfrfha_hash_entry_remove(struct fha_hash_entry *e) 222184588Sdfr{ 223184588Sdfr 224261054Smav mtx_assert(e->mtx, MA_OWNED); 225184588Sdfr LIST_REMOVE(e, link); 226184588Sdfr fha_hash_entry_destroy(e); 227184588Sdfr} 228184588Sdfr 229184588Sdfrstatic struct fha_hash_entry * 230249592Skenfha_hash_entry_lookup(struct fha_params *softc, u_int64_t fh) 231184588Sdfr{ 232249592Sken SVCPOOL *pool; 233261054Smav struct fha_hash_slot *fhs; 234261054Smav struct fha_hash_entry *fhe, *new_fhe; 235249592Sken 236249592Sken pool = *softc->pool; 237261054Smav fhs = &softc->fha_hash[fh % FHA_HASH_SIZE]; 238261054Smav new_fhe = fha_hash_entry_new(fh); 239261054Smav new_fhe->mtx = &fhs->mtx; 240261054Smav mtx_lock(&fhs->mtx); 241261054Smav LIST_FOREACH(fhe, &fhs->list, link) 242184588Sdfr if (fhe->fh == fh) 243184588Sdfr break; 244184588Sdfr if (!fhe) { 245261054Smav fhe = new_fhe; 246261054Smav LIST_INSERT_HEAD(&fhs->list, fhe, link); 247261054Smav } else 248261054Smav fha_hash_entry_destroy(new_fhe); 249201899Smarius return (fhe); 250184588Sdfr} 251184588Sdfr 252184588Sdfrstatic void 253184588Sdfrfha_hash_entry_add_thread(struct fha_hash_entry *fhe, SVCTHREAD *thread) 254184588Sdfr{ 255201899Smarius 256261054Smav mtx_assert(fhe->mtx, MA_OWNED); 257261054Smav thread->st_p2 = 0; 258184588Sdfr LIST_INSERT_HEAD(&fhe->threads, thread, st_alink); 259184588Sdfr fhe->num_threads++; 260184588Sdfr} 261184588Sdfr 262184588Sdfrstatic void 263184588Sdfrfha_hash_entry_remove_thread(struct fha_hash_entry *fhe, SVCTHREAD *thread) 264184588Sdfr{ 265184588Sdfr 266261054Smav mtx_assert(fhe->mtx, MA_OWNED); 267261054Smav KASSERT(thread->st_p2 == 0, 268261054Smav ("%d reqs on removed thread %p", thread->st_p2, thread)); 269184588Sdfr LIST_REMOVE(thread, st_alink); 270184588Sdfr fhe->num_threads--; 271184588Sdfr} 272184588Sdfr 273201899Smarius/* 274184588Sdfr * Account for an ongoing operation associated with this file. 275184588Sdfr */ 276184588Sdfrstatic void 277184588Sdfrfha_hash_entry_add_op(struct fha_hash_entry *fhe, int locktype, int count) 278184588Sdfr{ 279184588Sdfr 280261054Smav mtx_assert(fhe->mtx, MA_OWNED); 281184588Sdfr if (LK_EXCLUSIVE == locktype) 282249592Sken fhe->num_exclusive += count; 283184588Sdfr else 284249592Sken fhe->num_rw += count; 285184588Sdfr} 286184588Sdfr 287201899Smarius/* 288184588Sdfr * Get the service thread currently associated with the fhe that is 289184588Sdfr * appropriate to handle this operation. 290184588Sdfr */ 291267740Smavstatic SVCTHREAD * 292249592Skenfha_hash_entry_choose_thread(struct fha_params *softc, 293249592Sken struct fha_hash_entry *fhe, struct fha_info *i, SVCTHREAD *this_thread) 294184588Sdfr{ 295184588Sdfr SVCTHREAD *thread, *min_thread = NULL; 296249592Sken SVCPOOL *pool; 297184588Sdfr int req_count, min_count = 0; 298184588Sdfr off_t offset1, offset2; 299184588Sdfr 300249592Sken pool = *softc->pool; 301249592Sken 302184588Sdfr LIST_FOREACH(thread, &fhe->threads, st_alink) { 303261054Smav req_count = thread->st_p2; 304184588Sdfr 305184588Sdfr /* If there are any writes in progress, use the first thread. */ 306249592Sken if (fhe->num_exclusive) { 307184588Sdfr#if 0 308201899Smarius ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO, 309184588Sdfr "fha: %p(%d)w", thread, req_count); 310184588Sdfr#endif 311184588Sdfr return (thread); 312184588Sdfr } 313184588Sdfr 314201899Smarius /* 315201899Smarius * Check for read locality, making sure that we won't 316201899Smarius * exceed our per-thread load limit in the process. 317184588Sdfr */ 318249592Sken offset1 = i->offset; 319261054Smav offset2 = thread->st_p3; 320249592Sken 321249592Sken if (((offset1 >= offset2) 322249592Sken && ((offset1 - offset2) < (1 << softc->ctls.bin_shift))) 323249592Sken || ((offset2 > offset1) 324249592Sken && ((offset2 - offset1) < (1 << softc->ctls.bin_shift)))) { 325249592Sken if ((softc->ctls.max_reqs_per_nfsd == 0) || 326249592Sken (req_count < softc->ctls.max_reqs_per_nfsd)) { 327184588Sdfr#if 0 328201899Smarius ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO, 329184588Sdfr "fha: %p(%d)r", thread, req_count); 330184588Sdfr#endif 331184588Sdfr return (thread); 332184588Sdfr } 333184588Sdfr } 334184588Sdfr 335201899Smarius /* 336184588Sdfr * We don't have a locality match, so skip this thread, 337201899Smarius * but keep track of the most attractive thread in case 338184588Sdfr * we need to come back to it later. 339184588Sdfr */ 340184588Sdfr#if 0 341201899Smarius ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO, 342201899Smarius "fha: %p(%d)s off1 %llu off2 %llu", thread, 343184588Sdfr req_count, offset1, offset2); 344184588Sdfr#endif 345184588Sdfr if ((min_thread == NULL) || (req_count < min_count)) { 346184588Sdfr min_count = req_count; 347184588Sdfr min_thread = thread; 348184588Sdfr } 349184588Sdfr } 350184588Sdfr 351201899Smarius /* 352201899Smarius * We didn't find a good match yet. See if we can add 353184588Sdfr * a new thread to this file handle entry's thread list. 354184588Sdfr */ 355249592Sken if ((softc->ctls.max_nfsds_per_fh == 0) || 356249592Sken (fhe->num_threads < softc->ctls.max_nfsds_per_fh)) { 357261054Smav thread = this_thread; 358184588Sdfr#if 0 359261054Smav ITRACE_CURPROC(ITRACE_NFS, ITRACE_INFO, 360261054Smav "fha: %p(%d)t", thread, thread->st_p2); 361184588Sdfr#endif 362184588Sdfr fha_hash_entry_add_thread(fhe, thread); 363184588Sdfr } else { 364201899Smarius /* 365201899Smarius * We don't want to use any more threads for this file, so 366184588Sdfr * go back to the most attractive nfsd we're already using. 367184588Sdfr */ 368184588Sdfr thread = min_thread; 369184588Sdfr } 370184588Sdfr 371184588Sdfr return (thread); 372184588Sdfr} 373184588Sdfr 374201899Smarius/* 375201899Smarius * After getting a request, try to assign it to some thread. Usually we 376184588Sdfr * handle it ourselves. 377184588Sdfr */ 378184588SdfrSVCTHREAD * 379249592Skenfha_assign(SVCTHREAD *this_thread, struct svc_req *req, 380249592Sken struct fha_params *softc) 381184588Sdfr{ 382184588Sdfr SVCTHREAD *thread; 383184588Sdfr struct fha_info i; 384184588Sdfr struct fha_hash_entry *fhe; 385249592Sken struct fha_callbacks *cb; 386184588Sdfr 387249592Sken cb = &softc->callbacks; 388249592Sken 389249592Sken /* Check to see whether we're enabled. */ 390249592Sken if (softc->ctls.enable == 0) 391261054Smav goto thist; 392249592Sken 393184588Sdfr /* 394184588Sdfr * Only do placement if this is an NFS request. 395184588Sdfr */ 396184588Sdfr if (req->rq_prog != NFS_PROG) 397261054Smav goto thist; 398184588Sdfr 399184588Sdfr if (req->rq_vers != 2 && req->rq_vers != 3) 400261054Smav goto thist; 401184588Sdfr 402249592Sken fha_extract_info(req, &i, cb); 403184588Sdfr 404201899Smarius /* 405201899Smarius * We save the offset associated with this request for later 406184588Sdfr * nfsd matching. 407184588Sdfr */ 408249592Sken fhe = fha_hash_entry_lookup(softc, i.fh); 409184588Sdfr req->rq_p1 = fhe; 410184588Sdfr req->rq_p2 = i.locktype; 411184588Sdfr req->rq_p3 = i.offset; 412201899Smarius 413201899Smarius /* 414184588Sdfr * Choose a thread, taking into consideration locality, thread load, 415184588Sdfr * and the number of threads already working on this file. 416184588Sdfr */ 417249592Sken thread = fha_hash_entry_choose_thread(softc, fhe, &i, this_thread); 418184588Sdfr KASSERT(thread, ("fha_assign: NULL thread!")); 419184588Sdfr fha_hash_entry_add_op(fhe, i.locktype, 1); 420261054Smav thread->st_p2++; 421261054Smav thread->st_p3 = i.offset; 422184588Sdfr 423261054Smav /* 424261054Smav * Grab the pool lock here to not let chosen thread go away before 425261054Smav * the new request inserted to its queue while we drop fhe lock. 426261054Smav */ 427267740Smav mtx_lock(&thread->st_lock); 428261054Smav mtx_unlock(fhe->mtx); 429261054Smav 430184588Sdfr return (thread); 431261054Smavthist: 432261054Smav req->rq_p1 = NULL; 433267740Smav mtx_lock(&this_thread->st_lock); 434261054Smav return (this_thread); 435184588Sdfr} 436184588Sdfr 437201899Smarius/* 438201899Smarius * Called when we're done with an operation. The request has already 439184588Sdfr * been de-queued. 440184588Sdfr */ 441184588Sdfrvoid 442184588Sdfrfha_nd_complete(SVCTHREAD *thread, struct svc_req *req) 443184588Sdfr{ 444184588Sdfr struct fha_hash_entry *fhe = req->rq_p1; 445261054Smav struct mtx *mtx; 446184588Sdfr 447184588Sdfr /* 448184588Sdfr * This may be called for reqs that didn't go through 449184588Sdfr * fha_assign (e.g. extra NULL ops used for RPCSEC_GSS. 450184588Sdfr */ 451184588Sdfr if (!fhe) 452184588Sdfr return; 453184588Sdfr 454261054Smav mtx = fhe->mtx; 455261054Smav mtx_lock(mtx); 456184588Sdfr fha_hash_entry_add_op(fhe, req->rq_p2, -1); 457261054Smav thread->st_p2--; 458261054Smav KASSERT(thread->st_p2 >= 0, ("Negative request count %d on %p", 459261054Smav thread->st_p2, thread)); 460261054Smav if (thread->st_p2 == 0) { 461184588Sdfr fha_hash_entry_remove_thread(fhe, thread); 462249592Sken if (0 == fhe->num_rw + fhe->num_exclusive) 463184588Sdfr fha_hash_entry_remove(fhe); 464184588Sdfr } 465261054Smav mtx_unlock(mtx); 466184588Sdfr} 467184588Sdfr 468249592Skenint 469249592Skenfhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc) 470184588Sdfr{ 471267753Smav int error, i; 472184588Sdfr struct sbuf sb; 473184588Sdfr struct fha_hash_entry *fhe; 474267753Smav bool_t first, hfirst; 475184588Sdfr SVCTHREAD *thread; 476249592Sken SVCPOOL *pool; 477184588Sdfr 478267753Smav sbuf_new(&sb, NULL, 65536, SBUF_FIXEDLEN); 479184588Sdfr 480249592Sken pool = NULL; 481249592Sken 482249592Sken if (!*softc->pool) { 483184588Sdfr sbuf_printf(&sb, "NFSD not running\n"); 484184588Sdfr goto out; 485184588Sdfr } 486249592Sken pool = *softc->pool; 487184588Sdfr 488261054Smav for (i = 0; i < FHA_HASH_SIZE; i++) 489261054Smav if (!LIST_EMPTY(&softc->fha_hash[i].list)) 490267753Smav break; 491184588Sdfr 492267753Smav if (i == FHA_HASH_SIZE) { 493184588Sdfr sbuf_printf(&sb, "No file handle entries.\n"); 494184588Sdfr goto out; 495184588Sdfr } 496184588Sdfr 497267753Smav hfirst = TRUE; 498267753Smav for (; i < FHA_HASH_SIZE; i++) { 499261054Smav mtx_lock(&softc->fha_hash[i].mtx); 500267753Smav if (LIST_EMPTY(&softc->fha_hash[i].list)) { 501267753Smav mtx_unlock(&softc->fha_hash[i].mtx); 502267753Smav continue; 503267753Smav } 504267753Smav sbuf_printf(&sb, "%shash %d: {\n", hfirst ? "" : ", ", i); 505267753Smav first = TRUE; 506261054Smav LIST_FOREACH(fhe, &softc->fha_hash[i].list, link) { 507267753Smav sbuf_printf(&sb, "%sfhe %p: {\n", first ? " " : ", ", fhe); 508184588Sdfr 509184588Sdfr sbuf_printf(&sb, " fh: %ju\n", (uintmax_t) fhe->fh); 510267753Smav sbuf_printf(&sb, " num_rw/exclusive: %d/%d\n", 511267753Smav fhe->num_rw, fhe->num_exclusive); 512184588Sdfr sbuf_printf(&sb, " num_threads: %d\n", fhe->num_threads); 513184588Sdfr 514184588Sdfr LIST_FOREACH(thread, &fhe->threads, st_alink) { 515267753Smav sbuf_printf(&sb, " thread %p offset %ju " 516267753Smav "reqs %d\n", thread, 517261054Smav thread->st_p3, thread->st_p2); 518184588Sdfr } 519184588Sdfr 520267753Smav sbuf_printf(&sb, " }"); 521184588Sdfr first = FALSE; 522184588Sdfr } 523267753Smav sbuf_printf(&sb, "\n}"); 524261054Smav mtx_unlock(&softc->fha_hash[i].mtx); 525267753Smav hfirst = FALSE; 526184588Sdfr } 527184588Sdfr 528184588Sdfr out: 529184588Sdfr sbuf_trim(&sb); 530184588Sdfr sbuf_finish(&sb); 531184588Sdfr error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); 532184588Sdfr sbuf_delete(&sb); 533184588Sdfr return (error); 534184588Sdfr} 535