return -ENOMEM;
}
- error = svc_set_num_threads(serv, NULL, 1);
+ error = svc_set_num_threads(serv, 1);
if (error < 0) {
svc_destroy(&serv);
return error;
unregister_inet6addr_notifier(&lockd_inet6addr_notifier);
#endif
- svc_set_num_threads(nlmsvc_serv, NULL, 0);
+ svc_set_num_threads(nlmsvc_serv, 0);
timer_delete_sync(&nlmsvc_retry);
svc_destroy(&nlmsvc_serv);
dprintk("lockd_down: service destroyed\n");
if (serv->sv_nrthreads == nrservs)
return 0;
- ret = svc_set_num_threads(serv, NULL, nrservs);
+ ret = svc_set_num_threads(serv, nrservs);
if (ret) {
- svc_set_num_threads(serv, NULL, 0);
+ svc_set_num_threads(serv, 0);
return ret;
}
dprintk("nfs_callback_up: service started\n");
cb_info->users++;
err_net:
if (!cb_info->users) {
- svc_set_num_threads(cb_info->serv, NULL, 0);
+ svc_set_num_threads(cb_info->serv, 0);
svc_destroy(&cb_info->serv);
}
err_create:
nfs_callback_down_net(minorversion, serv, net);
cb_info->users--;
if (cb_info->users == 0) {
- svc_set_num_threads(serv, NULL, 0);
+ svc_set_num_threads(serv, 0);
dprintk("nfs_callback_down: service destroyed\n");
xprt_svc_destroy_nullify_bc(xprt, &cb_info->serv);
}
}
/* Kill outstanding nfsd threads */
- svc_set_num_threads(serv, NULL, 0);
+ svc_set_num_threads(serv, 0);
nfsd_destroy_serv(net);
mutex_unlock(&nfsd_mutex);
}
if (nn->nfsd_serv == NULL || n <= 0)
return 0;
- /*
- * Special case: When n == 1, pass in NULL for the pool, so that the
- * change is distributed equally among them.
- */
+ /* Special case: When n == 1, distribute threads equally among pools. */
if (n == 1)
- return svc_set_num_threads(nn->nfsd_serv, NULL, nthreads[0]);
+ return svc_set_num_threads(nn->nfsd_serv, nthreads[0]);
if (n > nn->nfsd_serv->sv_nrpools)
n = nn->nfsd_serv->sv_nrpools;
/* apply the new numbers */
for (i = 0; i < n; i++) {
- err = svc_set_num_threads(nn->nfsd_serv,
- &nn->nfsd_serv->sv_pools[i],
- nthreads[i]);
+ err = svc_set_pool_threads(nn->nfsd_serv,
+ &nn->nfsd_serv->sv_pools[i],
+ nthreads[i]);
if (err)
goto out;
}
/* Anything undefined in array is considered to be 0 */
for (i = n; i < nn->nfsd_serv->sv_nrpools; ++i) {
- err = svc_set_num_threads(nn->nfsd_serv,
- &nn->nfsd_serv->sv_pools[i],
- 0);
+ err = svc_set_pool_threads(nn->nfsd_serv,
+ &nn->nfsd_serv->sv_pools[i],
+ 0);
if (err)
goto out;
}
struct svc_stat *stats,
unsigned int bufsize,
int (*threadfn)(void *data));
-int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);
+int svc_set_pool_threads(struct svc_serv *serv, struct svc_pool *pool,
+ unsigned int nrservs);
+int svc_set_num_threads(struct svc_serv *serv, unsigned int nrservs);
int svc_pool_stats_open(struct svc_info *si, struct file *file);
void svc_process(struct svc_rqst *rqstp);
void svc_process_bc(struct rpc_rqst *req, struct svc_rqst *rqstp);
}
/**
- * svc_set_num_threads - adjust number of threads per RPC service
+ * svc_set_pool_threads - adjust number of threads per pool
* @serv: RPC service to adjust
- * @pool: Specific pool from which to choose threads, or NULL
- * @nrservs: New number of threads for @serv (0 or less means kill all threads)
+ * @pool: Specific pool from which to choose threads
+ * @nrservs: New number of threads for @serv (0 means kill all threads)
*
- * Create or destroy threads to make the number of threads for @serv the
- * given number. If @pool is non-NULL, change only threads in that pool;
- * otherwise, round-robin between all pools for @serv. @serv's
- * sv_nrthreads is adjusted for each thread created or destroyed.
+ * Create or destroy threads in @pool to bring it to @nrservs.
*
* Caller must ensure mutual exclusion between this and server startup or
* shutdown.
* starting a thread.
*/
int
-svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
+svc_set_pool_threads(struct svc_serv *serv, struct svc_pool *pool,
+ unsigned int nrservs)
{
+ int delta = nrservs;
+
if (!pool)
- nrservs -= serv->sv_nrthreads;
- else
- nrservs -= pool->sp_nrthreads;
+ return -EINVAL;
- if (nrservs > 0)
- return svc_start_kthreads(serv, pool, nrservs);
- if (nrservs < 0)
- return svc_stop_kthreads(serv, pool, nrservs);
+ delta -= pool->sp_nrthreads;
+
+ if (delta > 0)
+ return svc_start_kthreads(serv, pool, delta);
+ if (delta < 0)
+ return svc_stop_kthreads(serv, pool, delta);
return 0;
}
+EXPORT_SYMBOL_GPL(svc_set_pool_threads);
+
+/**
+ * svc_set_num_threads - adjust number of threads in serv
+ * @serv: RPC service to adjust
+ * @nrservs: New number of threads for @serv (0 means kill all threads)
+ *
+ * Create or destroy threads in @serv to bring it to @nrservs. If there
+ * are multiple pools then the new threads or victims will be distributed
+ * evenly among them.
+ *
+ * Caller must ensure mutual exclusion between this and server startup or
+ * shutdown.
+ *
+ * Returns zero on success or a negative errno if an error occurred while
+ * starting a thread. On failure, some pools may have already been
+ * adjusted; the caller is responsible for recovery.
+ */
+int
+svc_set_num_threads(struct svc_serv *serv, unsigned int nrservs)
+{
+ unsigned int base = nrservs / serv->sv_nrpools;
+ unsigned int remain = nrservs % serv->sv_nrpools;
+ int i, err = 0;
+
+ for (i = 0; i < serv->sv_nrpools; ++i) {
+ int threads = base;
+
+ if (remain) {
+ ++threads;
+ --remain;
+ }
+ err = svc_set_pool_threads(serv, &serv->sv_pools[i], threads);
+ if (err)
+ break;
+ }
+ return err;
+}
EXPORT_SYMBOL_GPL(svc_set_num_threads);
/**