1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
#include <linux/types.h>
#include <linux/time.h>
#include <linux/sunrpc/svc_xprt.h>
#include "lockd.h"
#undef SM_MAXSTRLEN
#undef SM_PRIV_SIZE
#include "share.h"
#include "nlm4xdr_gen.h"
struct nlm4_testargs_wrapper {
struct nlm4_testargs xdrgen;
struct lockd_lock lock;
};
static_assert(offsetof(struct nlm4_testargs_wrapper, xdrgen) == 0);
struct nlm4_lockargs_wrapper {
struct nlm4_lockargs xdrgen;
struct lockd_cookie cookie;
struct lockd_lock lock;
};
static_assert(offsetof(struct nlm4_lockargs_wrapper, xdrgen) == 0);
struct nlm4_cancargs_wrapper {
struct nlm4_cancargs xdrgen;
struct lockd_lock lock;
};
static_assert(offsetof(struct nlm4_cancargs_wrapper, xdrgen) == 0);
struct nlm4_unlockargs_wrapper {
struct nlm4_unlockargs xdrgen;
struct lockd_lock lock;
};
static_assert(offsetof(struct nlm4_unlockargs_wrapper, xdrgen) == 0);
struct nlm4_notifyargs_wrapper {
struct nlm4_notifyargs xdrgen;
struct lockd_reboot reboot;
};
static_assert(offsetof(struct nlm4_notifyargs_wrapper, xdrgen) == 0);
struct nlm4_notify_wrapper {
struct nlm4_notify xdrgen;
};
static_assert(offsetof(struct nlm4_notify_wrapper, xdrgen) == 0);
struct nlm4_testres_wrapper {
struct nlm4_testres xdrgen;
struct lockd_lock lock;
};
struct nlm4_shareargs_wrapper {
struct nlm4_shareargs xdrgen;
struct lockd_lock lock;
};
static_assert(offsetof(struct nlm4_shareargs_wrapper, xdrgen) == 0);
static_assert(offsetof(struct nlm4_testres_wrapper, xdrgen) == 0);
struct nlm4_res_wrapper {
struct nlm4_res xdrgen;
struct lockd_cookie cookie;
};
static_assert(offsetof(struct nlm4_res_wrapper, xdrgen) == 0);
struct nlm4_shareres_wrapper {
struct nlm4_shareres xdrgen;
};
static_assert(offsetof(struct nlm4_shareres_wrapper, xdrgen) == 0);
static __be32
nlm4_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
{
if (object->len > NLM_MAXCOOKIELEN)
return nlm_lck_denied_nolocks;
cookie->len = object->len;
memcpy(cookie->data, object->data, object->len);
return nlm_granted;
}
static __be32
nlm4_lock_to_lockd_lock(struct lockd_lock *lock, struct nlm4_lock *alock)
{
if (alock->fh.len > NFS_MAXFHSIZE)
return nlm_lck_denied;
lock->fh.size = alock->fh.len;
memcpy(lock->fh.data, alock->fh.data, alock->fh.len);
lock->oh.len = alock->oh.len;
lock->oh.data = alock->oh.data;
lock->svid = alock->svid;
lockd_set_file_lock_range4(&lock->fl, alock->l_offset, alock->l_len);
return nlm_granted;
}
static struct nlm_host *
nlm4svc_lookup_host(struct svc_rqst *rqstp, string caller, bool monitored)
{
struct nlm_host *host;
if (!rcu_access_pointer(nlmsvc_ops))
return NULL;
host = nlmsvc_lookup_host(rqstp, caller.data, caller.len);
if (!host)
return NULL;
if (monitored && nsm_monitor(host) < 0) {
nlmsvc_release_host(host);
return NULL;
}
return host;
}
static __be32
nlm4svc_lookup_file(struct svc_rqst *rqstp, struct nlm_host *host,
struct lockd_lock *lock, struct nlm_file **filp,
struct nlm4_lock *xdr_lock, unsigned char type)
{
bool is_test = (rqstp->rq_proc == NLMPROC4_TEST ||
rqstp->rq_proc == NLMPROC4_TEST_MSG);
struct file_lock *fl = &lock->fl;
struct nlm_file *file = NULL;
int mode;
__be32 error;
if (xdr_lock->fh.len > NFS_MAXFHSIZE)
return nlm_lck_denied_nolocks;
lock->fh.size = xdr_lock->fh.len;
memcpy(lock->fh.data, xdr_lock->fh.data, xdr_lock->fh.len);
if (xdr_lock->fh.len < LOCKD_FH_HASH_SIZE)
memset(lock->fh.data + xdr_lock->fh.len, 0,
LOCKD_FH_HASH_SIZE - xdr_lock->fh.len);
lock->oh.len = xdr_lock->oh.len;
lock->oh.data = xdr_lock->oh.data;
lock->svid = xdr_lock->svid;
lock->lock_start = xdr_lock->l_offset;
lock->lock_len = xdr_lock->l_len;
if (lock->lock_start > OFFSET_MAX ||
(lock->lock_len && ((lock->lock_len - 1) > (OFFSET_MAX - lock->lock_start))))
return nlm4_fbig;
locks_init_lock(fl);
fl->c.flc_type = type;
lockd_set_file_lock_range4(fl, lock->lock_start, lock->lock_len);
mode = is_test ? O_RDWR : lock_to_openmode(fl);
error = nlm_lookup_file(rqstp, &file, lock, mode);
switch (error) {
case nlm_granted:
break;
case nlm__int__stale_fh:
return nlm4_stale_fh;
case nlm__int__failed:
return nlm4_failed;
default:
return error;
}
*filp = file;
fl->c.flc_flags = FL_POSIX;
fl->c.flc_file = is_test ? nlmsvc_file_file(file)
: file->f_file[mode];
fl->c.flc_pid = current->tgid;
fl->fl_lmops = &nlmsvc_lock_operations;
nlmsvc_locks_init_private(fl, host, (pid_t)lock->svid);
if (!fl->c.flc_owner)
return nlm_lck_denied_nolocks;
return nlm_granted;
}
static __be32
nlm4svc_proc_null(struct svc_rqst *rqstp)
{
return rpc_success;
}
static __be32 nlm4svc_proc_test(struct svc_rqst *rqstp)
{
struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
struct nlm4_testres_wrapper *resp = rqstp->rq_resp;
struct nlm_file *file = NULL;
struct nlm_host *host;
resp->xdrgen.cookie = argp->xdrgen.cookie;
resp->xdrgen.stat.stat = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
goto out;
resp->xdrgen.stat.stat = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock,
type);
if (resp->xdrgen.stat.stat)
goto out;
resp->xdrgen.stat.stat = nlmsvc_testlock(rqstp, file, host,
&argp->lock, &resp->lock);
nlmsvc_release_lockowner(&argp->lock);
if (resp->xdrgen.stat.stat == nlm_lck_denied) {
struct lockd_lock *conf = &resp->lock;
struct nlm4_holder *holder = &resp->xdrgen.stat.u.holder;
holder->exclusive = (conf->fl.c.flc_type != F_RDLCK);
holder->svid = conf->svid;
holder->oh.len = conf->oh.len;
holder->oh.data = conf->oh.data;
holder->l_offset = conf->fl.fl_start;
if (conf->fl.fl_end == OFFSET_MAX)
holder->l_len = 0;
else
holder->l_len = conf->fl.fl_end - conf->fl.fl_start + 1;
}
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->xdrgen.stat.stat == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32
nlm4svc_do_lock(struct svc_rqst *rqstp, bool monitored)
{
struct nlm4_lockargs_wrapper *argp = rqstp->rq_argp;
unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
struct nlm4_res_wrapper *resp = rqstp->rq_resp;
struct nlm_file *file = NULL;
struct nlm_host *host = NULL;
resp->xdrgen.cookie = argp->xdrgen.cookie;
resp->xdrgen.stat.stat = nlm4_netobj_to_cookie(&argp->cookie,
&argp->xdrgen.cookie);
if (resp->xdrgen.stat.stat)
goto out;
resp->xdrgen.stat.stat = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name,
monitored);
if (!host)
goto out;
resp->xdrgen.stat.stat = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock,
type);
if (resp->xdrgen.stat.stat)
goto out;
resp->xdrgen.stat.stat = nlmsvc_lock(rqstp, file, host, &argp->lock,
argp->xdrgen.block, &argp->cookie,
argp->xdrgen.reclaim);
if (resp->xdrgen.stat.stat == nlm__int__deadlock)
resp->xdrgen.stat.stat = nlm4_deadlock;
nlmsvc_release_lockowner(&argp->lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->xdrgen.stat.stat == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32
nlm4svc_proc_lock(struct svc_rqst *rqstp)
{
return nlm4svc_do_lock(rqstp, true);
}
static __be32
nlm4svc_proc_cancel(struct svc_rqst *rqstp)
{
struct nlm4_cancargs_wrapper *argp = rqstp->rq_argp;
unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
struct nlm4_res_wrapper *resp = rqstp->rq_resp;
struct net *net = SVC_NET(rqstp);
struct nlm_host *host = NULL;
struct nlm_file *file = NULL;
resp->xdrgen.cookie = argp->xdrgen.cookie;
resp->xdrgen.stat.stat = nlm_lck_denied_grace_period;
if (locks_in_grace(net))
goto out;
resp->xdrgen.stat.stat = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
goto out;
resp->xdrgen.stat.stat = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock,
type);
if (resp->xdrgen.stat.stat)
goto out;
resp->xdrgen.stat.stat = nlmsvc_cancel_blocked(net, file, &argp->lock);
nlmsvc_release_lockowner(&argp->lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->xdrgen.stat.stat == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32
nlm4svc_proc_unlock(struct svc_rqst *rqstp)
{
struct nlm4_unlockargs_wrapper *argp = rqstp->rq_argp;
struct nlm4_res_wrapper *resp = rqstp->rq_resp;
struct net *net = SVC_NET(rqstp);
struct nlm_host *host = NULL;
struct nlm_file *file = NULL;
resp->xdrgen.cookie = argp->xdrgen.cookie;
resp->xdrgen.stat.stat = nlm_lck_denied_grace_period;
if (locks_in_grace(net))
goto out;
resp->xdrgen.stat.stat = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
goto out;
resp->xdrgen.stat.stat = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock,
F_UNLCK);
if (resp->xdrgen.stat.stat)
goto out;
resp->xdrgen.stat.stat = nlmsvc_unlock(net, file, &argp->lock);
nlmsvc_release_lockowner(&argp->lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->xdrgen.stat.stat == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32
nlm4svc_proc_granted(struct svc_rqst *rqstp)
{
struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
struct nlm4_res_wrapper *resp = rqstp->rq_resp;
resp->xdrgen.cookie = argp->xdrgen.cookie;
resp->xdrgen.stat.stat = nlm4_lock_to_lockd_lock(&argp->lock,
&argp->xdrgen.alock);
if (resp->xdrgen.stat.stat)
goto out;
resp->xdrgen.stat.stat = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
out:
return rpc_success;
}
static void nlm4svc_callback_exit(struct rpc_task *task, void *data)
{
}
static void nlm4svc_callback_release(void *data)
{
nlmsvc_release_call(data);
}
static const struct rpc_call_ops nlm4svc_callback_ops = {
.rpc_call_done = nlm4svc_callback_exit,
.rpc_release = nlm4svc_callback_release,
};
static __be32
nlm4svc_callback(struct svc_rqst *rqstp, struct nlm_host *host, u32 proc,
__be32 (*func)(struct svc_rqst *, struct lockd_res *))
{
struct nlm_rqst *call;
__be32 stat;
call = nlm_alloc_call(host);
nlmsvc_release_host(host);
if (call == NULL)
return rpc_system_err;
stat = func(rqstp, &call->a_res);
if (stat != 0) {
nlmsvc_release_call(call);
return stat;
}
call->a_flags = RPC_TASK_ASYNC;
if (nlm_async_reply(call, proc, &nlm4svc_callback_ops) < 0)
return rpc_system_err;
return rpc_success;
}
static __be32
__nlm4svc_proc_test_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
{
struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
struct nlm_lockowner *owner;
struct nlm_file *file = NULL;
struct nlm_host *host = NULL;
resp->status = nlm_lck_denied_nolocks;
if (nlm4_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
goto out;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
goto out;
resp->status = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock, type);
if (resp->status)
goto out;
owner = argp->lock.fl.c.flc_owner;
resp->status = nlmsvc_testlock(rqstp, file, host, &argp->lock,
&resp->lock);
nlmsvc_put_lockowner(owner);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->status == nlm__int__drop_reply ? rpc_drop_reply : rpc_success;
}
static __be32 nlm4svc_proc_test_msg(struct svc_rqst *rqstp)
{
struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
struct nlm_host *host;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
return rpc_system_err;
return nlm4svc_callback(rqstp, host, NLMPROC4_TEST_RES,
__nlm4svc_proc_test_msg);
}
static __be32
__nlm4svc_proc_lock_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
{
struct nlm4_lockargs_wrapper *argp = rqstp->rq_argp;
unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
struct nlm_file *file = NULL;
struct nlm_host *host = NULL;
resp->status = nlm_lck_denied_nolocks;
if (nlm4_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
goto out;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, true);
if (!host)
goto out;
resp->status = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock, type);
if (resp->status)
goto out;
resp->status = nlmsvc_lock(rqstp, file, host, &argp->lock,
argp->xdrgen.block, &resp->cookie,
argp->xdrgen.reclaim);
if (resp->status == nlm__int__deadlock)
resp->status = nlm4_deadlock;
nlmsvc_release_lockowner(&argp->lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->status == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32 nlm4svc_proc_lock_msg(struct svc_rqst *rqstp)
{
struct nlm4_lockargs_wrapper *argp = rqstp->rq_argp;
struct nlm_host *host;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
return rpc_system_err;
return nlm4svc_callback(rqstp, host, NLMPROC4_LOCK_RES,
__nlm4svc_proc_lock_msg);
}
static __be32
__nlm4svc_proc_cancel_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
{
struct nlm4_cancargs_wrapper *argp = rqstp->rq_argp;
unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
struct net *net = SVC_NET(rqstp);
struct nlm_file *file = NULL;
struct nlm_host *host = NULL;
resp->status = nlm_lck_denied_nolocks;
if (nlm4_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
goto out;
resp->status = nlm_lck_denied_grace_period;
if (locks_in_grace(net))
goto out;
resp->status = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
goto out;
resp->status = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock, type);
if (resp->status)
goto out;
resp->status = nlmsvc_cancel_blocked(net, file, &argp->lock);
nlmsvc_release_lockowner(&argp->lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->status == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32 nlm4svc_proc_cancel_msg(struct svc_rqst *rqstp)
{
struct nlm4_cancargs_wrapper *argp = rqstp->rq_argp;
struct nlm_host *host;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
return rpc_system_err;
return nlm4svc_callback(rqstp, host, NLMPROC4_CANCEL_RES,
__nlm4svc_proc_cancel_msg);
}
static __be32
__nlm4svc_proc_unlock_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
{
struct nlm4_unlockargs_wrapper *argp = rqstp->rq_argp;
struct net *net = SVC_NET(rqstp);
struct nlm_file *file = NULL;
struct nlm_host *host = NULL;
resp->status = nlm_lck_denied_nolocks;
if (nlm4_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
goto out;
resp->status = nlm_lck_denied_grace_period;
if (locks_in_grace(net))
goto out;
resp->status = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
goto out;
resp->status = nlm4svc_lookup_file(rqstp, host, &argp->lock,
&file, &argp->xdrgen.alock, F_UNLCK);
if (resp->status)
goto out;
resp->status = nlmsvc_unlock(net, file, &argp->lock);
nlmsvc_release_lockowner(&argp->lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->status == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32 nlm4svc_proc_unlock_msg(struct svc_rqst *rqstp)
{
struct nlm4_unlockargs_wrapper *argp = rqstp->rq_argp;
struct nlm_host *host;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
if (!host)
return rpc_system_err;
return nlm4svc_callback(rqstp, host, NLMPROC4_UNLOCK_RES,
__nlm4svc_proc_unlock_msg);
}
static __be32
__nlm4svc_proc_granted_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
{
struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
resp->status = nlm_lck_denied;
if (nlm4_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
goto out;
if (nlm4_lock_to_lockd_lock(&argp->lock, &argp->xdrgen.alock))
goto out;
resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
out:
return rpc_success;
}
static __be32 nlm4svc_proc_granted_msg(struct svc_rqst *rqstp)
{
struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
struct nlm_host *host;
host = nlmsvc_lookup_host(rqstp, argp->xdrgen.alock.caller_name.data,
argp->xdrgen.alock.caller_name.len);
if (!host)
return rpc_system_err;
return nlm4svc_callback(rqstp, host, NLMPROC4_GRANTED_RES,
__nlm4svc_proc_granted_msg);
}
static __be32 nlm4svc_proc_granted_res(struct svc_rqst *rqstp)
{
struct nlm4_res_wrapper *argp = rqstp->rq_argp;
if (!rcu_access_pointer(nlmsvc_ops))
return rpc_success;
if (nlm4_netobj_to_cookie(&argp->cookie, &argp->xdrgen.cookie))
return rpc_success;
nlmsvc_grant_reply(&argp->cookie, argp->xdrgen.stat.stat);
return rpc_success;
}
static __be32 nlm4svc_proc_sm_notify(struct svc_rqst *rqstp)
{
struct nlm4_notifyargs_wrapper *argp = rqstp->rq_argp;
struct lockd_reboot *reboot = &argp->reboot;
if (!nlm_privileged_requester(rqstp)) {
char buf[RPC_MAX_ADDRBUFLEN];
pr_warn("lockd: rejected NSM callback from %s\n",
svc_print_addr(rqstp, buf, sizeof(buf)));
return rpc_system_err;
}
reboot->len = argp->xdrgen.notify.name.len;
reboot->mon = (char *)argp->xdrgen.notify.name.data;
reboot->state = argp->xdrgen.notify.state;
memcpy(&reboot->priv.data, argp->xdrgen.private,
sizeof(reboot->priv.data));
nlm_host_rebooted(SVC_NET(rqstp), reboot);
return rpc_success;
}
static __be32 nlm4svc_proc_unused(struct svc_rqst *rqstp)
{
return rpc_proc_unavail;
}
static __be32 nlm4svc_proc_share(struct svc_rqst *rqstp)
{
struct nlm4_shareargs_wrapper *argp = rqstp->rq_argp;
struct nlm4_shareres_wrapper *resp = rqstp->rq_resp;
struct lockd_lock *lock = &argp->lock;
struct nlm_host *host = NULL;
struct nlm_file *file = NULL;
struct nlm4_lock xdr_lock = {
.fh = argp->xdrgen.share.fh,
.oh = argp->xdrgen.share.oh,
.svid = LOCKD_SHARE_SVID,
};
resp->xdrgen.cookie = argp->xdrgen.cookie;
resp->xdrgen.stat = nlm_lck_denied_grace_period;
if (locks_in_grace(SVC_NET(rqstp)) && !argp->xdrgen.reclaim)
goto out;
resp->xdrgen.stat = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.share.caller_name, true);
if (!host)
goto out;
resp->xdrgen.stat = nlm4svc_lookup_file(rqstp, host, lock, &file,
&xdr_lock, F_RDLCK);
if (resp->xdrgen.stat)
goto out;
resp->xdrgen.stat = nlmsvc_share_file(host, file, &lock->oh,
argp->xdrgen.share.access,
argp->xdrgen.share.mode);
nlmsvc_release_lockowner(lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->xdrgen.stat == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32 nlm4svc_proc_unshare(struct svc_rqst *rqstp)
{
struct nlm4_shareargs_wrapper *argp = rqstp->rq_argp;
struct nlm4_shareres_wrapper *resp = rqstp->rq_resp;
struct lockd_lock *lock = &argp->lock;
struct nlm4_lock xdr_lock = {
.fh = argp->xdrgen.share.fh,
.oh = argp->xdrgen.share.oh,
.svid = LOCKD_SHARE_SVID,
};
struct nlm_host *host = NULL;
struct nlm_file *file = NULL;
resp->xdrgen.cookie = argp->xdrgen.cookie;
resp->xdrgen.stat = nlm_lck_denied_grace_period;
if (locks_in_grace(SVC_NET(rqstp)))
goto out;
resp->xdrgen.stat = nlm_lck_denied_nolocks;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.share.caller_name, true);
if (!host)
goto out;
resp->xdrgen.stat = nlm4svc_lookup_file(rqstp, host, lock, &file,
&xdr_lock, F_RDLCK);
if (resp->xdrgen.stat)
goto out;
resp->xdrgen.stat = nlmsvc_unshare_file(host, file, &lock->oh,
argp->xdrgen.share.access,
argp->xdrgen.share.mode);
nlmsvc_release_lockowner(lock);
out:
if (file)
nlm_release_file(file);
nlmsvc_release_host(host);
return resp->xdrgen.stat == nlm__int__drop_reply ?
rpc_drop_reply : rpc_success;
}
static __be32 nlm4svc_proc_nm_lock(struct svc_rqst *rqstp)
{
return nlm4svc_do_lock(rqstp, false);
}
static __be32 nlm4svc_proc_free_all(struct svc_rqst *rqstp)
{
struct nlm4_notify_wrapper *argp = rqstp->rq_argp;
struct nlm_host *host;
host = nlm4svc_lookup_host(rqstp, argp->xdrgen.name, false);
if (!host)
goto out;
nlmsvc_free_host_resources(host);
nlmsvc_release_host(host);
out:
return rpc_success;
}
static const struct svc_procedure nlm4svc_procedures[24] = {
[NLMPROC4_NULL] = {
.pc_func = nlm4svc_proc_null,
.pc_decode = xdrgen_svc_decode_void,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = XDR_void,
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "NULL",
},
[NLMPROC4_TEST] = {
.pc_func = nlm4svc_proc_test,
.pc_decode = nlm4_svc_decode_nlm4_testargs,
.pc_encode = nlm4_svc_encode_nlm4_testres,
.pc_argsize = sizeof(struct nlm4_testargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_testres_wrapper),
.pc_xdrressize = NLM4_nlm4_testres_sz,
.pc_name = "TEST",
},
[NLMPROC4_LOCK] = {
.pc_func = nlm4svc_proc_lock,
.pc_decode = nlm4_svc_decode_nlm4_lockargs,
.pc_encode = nlm4_svc_encode_nlm4_res,
.pc_argsize = sizeof(struct nlm4_lockargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_res_wrapper),
.pc_xdrressize = NLM4_nlm4_res_sz,
.pc_name = "LOCK",
},
[NLMPROC4_CANCEL] = {
.pc_func = nlm4svc_proc_cancel,
.pc_decode = nlm4_svc_decode_nlm4_cancargs,
.pc_encode = nlm4_svc_encode_nlm4_res,
.pc_argsize = sizeof(struct nlm4_cancargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_res_wrapper),
.pc_xdrressize = NLM4_nlm4_res_sz,
.pc_name = "CANCEL",
},
[NLMPROC4_UNLOCK] = {
.pc_func = nlm4svc_proc_unlock,
.pc_decode = nlm4_svc_decode_nlm4_unlockargs,
.pc_encode = nlm4_svc_encode_nlm4_res,
.pc_argsize = sizeof(struct nlm4_unlockargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_res_wrapper),
.pc_xdrressize = NLM4_nlm4_res_sz,
.pc_name = "UNLOCK",
},
[NLMPROC4_GRANTED] = {
.pc_func = nlm4svc_proc_granted,
.pc_decode = nlm4_svc_decode_nlm4_testargs,
.pc_encode = nlm4_svc_encode_nlm4_res,
.pc_argsize = sizeof(struct nlm4_testargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_res_wrapper),
.pc_xdrressize = NLM4_nlm4_res_sz,
.pc_name = "GRANTED",
},
[NLMPROC4_TEST_MSG] = {
.pc_func = nlm4svc_proc_test_msg,
.pc_decode = nlm4_svc_decode_nlm4_testargs,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_testargs_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "TEST_MSG",
},
[NLMPROC4_LOCK_MSG] = {
.pc_func = nlm4svc_proc_lock_msg,
.pc_decode = nlm4_svc_decode_nlm4_lockargs,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_lockargs_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "LOCK_MSG",
},
[NLMPROC4_CANCEL_MSG] = {
.pc_func = nlm4svc_proc_cancel_msg,
.pc_decode = nlm4_svc_decode_nlm4_cancargs,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_cancargs_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "CANCEL_MSG",
},
[NLMPROC4_UNLOCK_MSG] = {
.pc_func = nlm4svc_proc_unlock_msg,
.pc_decode = nlm4_svc_decode_nlm4_unlockargs,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_unlockargs_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "UNLOCK_MSG",
},
[NLMPROC4_GRANTED_MSG] = {
.pc_func = nlm4svc_proc_granted_msg,
.pc_decode = nlm4_svc_decode_nlm4_testargs,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_testargs_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "GRANTED_MSG",
},
[NLMPROC4_TEST_RES] = {
.pc_func = nlm4svc_proc_null,
.pc_decode = nlm4_svc_decode_nlm4_testres,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_testres),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "TEST_RES",
},
[NLMPROC4_LOCK_RES] = {
.pc_func = nlm4svc_proc_null,
.pc_decode = nlm4_svc_decode_nlm4_res,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_res),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "LOCK_RES",
},
[NLMPROC4_CANCEL_RES] = {
.pc_func = nlm4svc_proc_null,
.pc_decode = nlm4_svc_decode_nlm4_res,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_res),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "CANCEL_RES",
},
[NLMPROC4_UNLOCK_RES] = {
.pc_func = nlm4svc_proc_null,
.pc_decode = nlm4_svc_decode_nlm4_res,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_res),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "UNLOCK_RES",
},
[NLMPROC4_GRANTED_RES] = {
.pc_func = nlm4svc_proc_granted_res,
.pc_decode = nlm4_svc_decode_nlm4_res,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_res_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "GRANTED_RES",
},
[NLMPROC4_SM_NOTIFY] = {
.pc_func = nlm4svc_proc_sm_notify,
.pc_decode = nlm4_svc_decode_nlm4_notifyargs,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_notifyargs_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "SM_NOTIFY",
},
[17] = {
.pc_func = nlm4svc_proc_unused,
.pc_decode = xdrgen_svc_decode_void,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = 0,
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "UNUSED",
},
[18] = {
.pc_func = nlm4svc_proc_unused,
.pc_decode = xdrgen_svc_decode_void,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = 0,
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "UNUSED",
},
[19] = {
.pc_func = nlm4svc_proc_unused,
.pc_decode = xdrgen_svc_decode_void,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = 0,
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "UNUSED",
},
[NLMPROC4_SHARE] = {
.pc_func = nlm4svc_proc_share,
.pc_decode = nlm4_svc_decode_nlm4_shareargs,
.pc_encode = nlm4_svc_encode_nlm4_shareres,
.pc_argsize = sizeof(struct nlm4_shareargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_shareres_wrapper),
.pc_xdrressize = NLM4_nlm4_shareres_sz,
.pc_name = "SHARE",
},
[NLMPROC4_UNSHARE] = {
.pc_func = nlm4svc_proc_unshare,
.pc_decode = nlm4_svc_decode_nlm4_shareargs,
.pc_encode = nlm4_svc_encode_nlm4_shareres,
.pc_argsize = sizeof(struct nlm4_shareargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_shareres_wrapper),
.pc_xdrressize = NLM4_nlm4_shareres_sz,
.pc_name = "UNSHARE",
},
[NLMPROC4_NM_LOCK] = {
.pc_func = nlm4svc_proc_nm_lock,
.pc_decode = nlm4_svc_decode_nlm4_lockargs,
.pc_encode = nlm4_svc_encode_nlm4_res,
.pc_argsize = sizeof(struct nlm4_lockargs_wrapper),
.pc_argzero = 0,
.pc_ressize = sizeof(struct nlm4_res_wrapper),
.pc_xdrressize = NLM4_nlm4_res_sz,
.pc_name = "NM_LOCK",
},
[NLMPROC4_FREE_ALL] = {
.pc_func = nlm4svc_proc_free_all,
.pc_decode = nlm4_svc_decode_nlm4_notify,
.pc_encode = xdrgen_svc_encode_void,
.pc_argsize = sizeof(struct nlm4_notify_wrapper),
.pc_argzero = 0,
.pc_ressize = 0,
.pc_xdrressize = XDR_void,
.pc_name = "FREE_ALL",
},
};
union nlm4svc_xdrstore {
struct nlm4_testargs_wrapper testargs;
struct nlm4_lockargs_wrapper lockargs;
struct nlm4_cancargs_wrapper cancargs;
struct nlm4_unlockargs_wrapper unlockargs;
struct nlm4_notifyargs_wrapper notifyargs;
struct nlm4_shareargs_wrapper shareargs;
struct nlm4_notify_wrapper notify;
struct nlm4_testres_wrapper testres;
struct nlm4_res_wrapper res;
struct nlm4_shareres_wrapper shareres;
};
const struct svc_version nlmsvc_version4 = {
.vs_vers = 4,
.vs_nproc = ARRAY_SIZE(nlm4svc_procedures),
.vs_proc = nlm4svc_procedures,
.vs_dispatch = nlmsvc_dispatch,
.vs_xdrsize = sizeof(union nlm4svc_xdrstore),
};