svcproc.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 607 行 · 第 1/2 页
C
607 行
dprintk("lockd: CANCEL_MSG called\n"); memset(&res, 0, sizeof(res)); if ((stat = nlmsvc_proc_cancel(rqstp, argp, &res)) == 0) stat = nlmsvc_callback(rqstp, NLMPROC_CANCEL_RES, &res); return stat;}static intnlmsvc_proc_unlock_msg(struct svc_rqst *rqstp, struct nlm_args *argp, void *resp){ struct nlm_res res; u32 stat; dprintk("lockd: UNLOCK_MSG called\n"); memset(&res, 0, sizeof(res)); if ((stat = nlmsvc_proc_unlock(rqstp, argp, &res)) == 0) stat = nlmsvc_callback(rqstp, NLMPROC_UNLOCK_RES, &res); return stat;}static intnlmsvc_proc_granted_msg(struct svc_rqst *rqstp, struct nlm_args *argp, void *resp){ struct nlm_res res; u32 stat; dprintk("lockd: GRANTED_MSG called\n"); memset(&res, 0, sizeof(res)); if ((stat = nlmsvc_proc_granted(rqstp, argp, &res)) == 0) stat = nlmsvc_callback(rqstp, NLMPROC_GRANTED_RES, &res); return stat;}/* * SHARE: create a DOS share or alter existing share. */static intnlmsvc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp, struct nlm_res *resp){ struct nlm_host *host; struct nlm_file *file; dprintk("lockd: SHARE called\n"); resp->cookie = argp->cookie; /* Don't accept new lock requests during grace period */ if (nlmsvc_grace_period && !argp->reclaim) { resp->status = nlm_lck_denied_grace_period; return rpc_success; } /* Obtain client and file */ if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) return rpc_success; /* Now try to create the share */ resp->status = cast_status(nlmsvc_share_file(host, file, argp)); dprintk("lockd: SHARE status %d\n", ntohl(resp->status)); nlm_release_host(host); nlm_release_file(file); return rpc_success;}/* * UNSHARE: Release a DOS share. */static intnlmsvc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp, struct nlm_res *resp){ struct nlm_host *host; struct nlm_file *file; dprintk("lockd: UNSHARE called\n"); resp->cookie = argp->cookie; /* Don't accept requests during grace period */ if (nlmsvc_grace_period) { resp->status = nlm_lck_denied_grace_period; return rpc_success; } /* Obtain client and file */ if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file))) return rpc_success; /* Now try to unshare the file */ resp->status = cast_status(nlmsvc_unshare_file(host, file, argp)); dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status)); nlm_release_host(host); nlm_release_file(file); return rpc_success;}/* * NM_LOCK: Create an unmonitored lock */static intnlmsvc_proc_nm_lock(struct svc_rqst *rqstp, struct nlm_args *argp, struct nlm_res *resp){ dprintk("lockd: NM_LOCK called\n"); argp->monitor = 0; /* just clean the monitor flag */ return nlmsvc_proc_lock(rqstp, argp, resp);}/* * FREE_ALL: Release all locks and shares held by client */static intnlmsvc_proc_free_all(struct svc_rqst *rqstp, struct nlm_args *argp, void *resp){ struct nlm_host *host; /* Obtain client */ if (nlmsvc_retrieve_args(rqstp, argp, &host, NULL)) return rpc_success; nlmsvc_free_host_resources(host); nlm_release_host(host); return rpc_success;}/* * SM_NOTIFY: private callback from statd (not part of official NLM proto) */static intnlmsvc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp, void *resp){ struct sockaddr_in saddr = rqstp->rq_addr; int vers = argp->vers; int prot = argp->proto >> 1; struct nlm_host *host; dprintk("lockd: SM_NOTIFY called\n"); if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK) || ntohs(saddr.sin_port) >= 1024) { printk(KERN_WARNING "lockd: rejected NSM callback from %08x:%d\n", ntohl(rqstp->rq_addr.sin_addr.s_addr), ntohs(rqstp->rq_addr.sin_port)); return rpc_system_err; } /* Obtain the host pointer for this NFS server and try to * reclaim all locks we hold on this server. */ saddr.sin_addr.s_addr = argp->addr; if ((argp->proto & 1)==0) { if ((host = nlmclnt_lookup_host(&saddr, prot, vers)) != NULL) { nlmclnt_recovery(host, argp->state); nlm_release_host(host); } } else { /* If we run on an NFS server, delete all locks held by the client */ if ((host = nlm_lookup_host(1, &saddr, prot, vers)) != NULL) { nlmsvc_free_host_resources(host); nlm_release_host(host); } } return rpc_success;}/* * client sent a GRANTED_RES, let's remove the associated block */static intnlmsvc_proc_granted_res(struct svc_rqst *rqstp, struct nlm_res *argp, void *resp){ if (!nlmsvc_ops) return rpc_success; dprintk("lockd: GRANTED_RES called\n"); nlmsvc_grant_reply(rqstp, &argp->cookie, argp->status); return rpc_success;}/* * This is the generic lockd callback for async RPC calls */static u32nlmsvc_callback(struct svc_rqst *rqstp, u32 proc, struct nlm_res *resp){ struct nlm_host *host; struct nlm_rqst *call; if (!(call = nlmclnt_alloc_call())) return rpc_system_err; host = nlmclnt_lookup_host(&rqstp->rq_addr, rqstp->rq_prot, rqstp->rq_vers); if (!host) { kfree(call); return rpc_system_err; } call->a_flags = RPC_TASK_ASYNC; call->a_host = host; memcpy(&call->a_args, resp, sizeof(*resp)); if (nlmsvc_async_call(call, proc, nlmsvc_callback_exit) < 0) goto error; return rpc_success; error: nlm_release_host(host); kfree(call); return rpc_system_err;}static voidnlmsvc_callback_exit(struct rpc_task *task){ struct nlm_rqst *call = (struct nlm_rqst *) task->tk_calldata; if (task->tk_status < 0) { dprintk("lockd: %4d callback failed (errno = %d)\n", task->tk_pid, -task->tk_status); } nlm_release_host(call->a_host); kfree(call);}/* * NLM Server procedures. */#define nlmsvc_encode_norep nlmsvc_encode_void#define nlmsvc_decode_norep nlmsvc_decode_void#define nlmsvc_decode_testres nlmsvc_decode_void#define nlmsvc_decode_lockres nlmsvc_decode_void#define nlmsvc_decode_unlockres nlmsvc_decode_void#define nlmsvc_decode_cancelres nlmsvc_decode_void#define nlmsvc_decode_grantedres nlmsvc_decode_void#define nlmsvc_proc_none nlmsvc_proc_null#define nlmsvc_proc_test_res nlmsvc_proc_null#define nlmsvc_proc_lock_res nlmsvc_proc_null#define nlmsvc_proc_cancel_res nlmsvc_proc_null#define nlmsvc_proc_unlock_res nlmsvc_proc_nullstruct nlm_void { int dummy; };#define PROC(name, xargt, xrest, argt, rest, respsize) \ { .pc_func = (svc_procfunc) nlmsvc_proc_##name, \ .pc_decode = (kxdrproc_t) nlmsvc_decode_##xargt, \ .pc_encode = (kxdrproc_t) nlmsvc_encode_##xrest, \ .pc_release = NULL, \ .pc_argsize = sizeof(struct nlm_##argt), \ .pc_ressize = sizeof(struct nlm_##rest), \ .pc_xdrressize = respsize, \ }#define Ck (1+8) /* cookie */#define St 1 /* status */#define No (1+1024/4) /* Net Obj */#define Rg 2 /* range - offset + size */struct svc_procedure nlmsvc_procedures[] = { PROC(null, void, void, void, void, 1), PROC(test, testargs, testres, args, res, Ck+St+2+No+Rg), PROC(lock, lockargs, res, args, res, Ck+St), PROC(cancel, cancargs, res, args, res, Ck+St), PROC(unlock, unlockargs, res, args, res, Ck+St), PROC(granted, testargs, res, args, res, Ck+St), PROC(test_msg, testargs, norep, args, void, 1), PROC(lock_msg, lockargs, norep, args, void, 1), PROC(cancel_msg, cancargs, norep, args, void, 1), PROC(unlock_msg, unlockargs, norep, args, void, 1), PROC(granted_msg, testargs, norep, args, void, 1), PROC(test_res, testres, norep, res, void, 1), PROC(lock_res, lockres, norep, res, void, 1), PROC(cancel_res, cancelres, norep, res, void, 1), PROC(unlock_res, unlockres, norep, res, void, 1), PROC(granted_res, res, norep, res, void, 1), /* statd callback */ PROC(sm_notify, reboot, void, reboot, void, 1), PROC(none, void, void, void, void, 1), PROC(none, void, void, void, void, 1), PROC(none, void, void, void, void, 1), PROC(share, shareargs, shareres, args, res, Ck+St+1), PROC(unshare, shareargs, shareres, args, res, Ck+St+1), PROC(nm_lock, lockargs, res, args, res, Ck+St), PROC(free_all, notify, void, args, void, 0),};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?