Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lockd: Relocate svc_version definitions to XDR layer

Public RPC server interfaces become cluttered when internal
XDR implementation details leak into them. The procedure count,
maximum XDR buffer size, and per-CPU call counters serve no
purpose outside the code that encodes and decodes NLM protocol
messages. Exposing these values through global headers creates
unnecessary coupling between the RPC dispatch logic and the
XDR layer.

Relocating the svc_version structure definitions confines this
implementation information to the files where XDR encoding and
decoding occur. In svc.c, the buffer size computation now reads
vs_xdrsize from the version structures rather than relying on a
preprocessor constant. This calculation occurs at service
initialization, after the linker has resolved the version
structure definitions. The dispatch function becomes non-static
because both the version structures and the dispatcher reside in
different translation units.

The NLMSVC_XDRSIZE macro is removed from xdr.h because buffer
size is now computed from the union of XDR argument and result
structures, matching the pattern used in other RPC services.
Version 1 and 3 share the same procedure table but maintain
separate counter arrays. Version 4 remains separate due to its
distinct procedure definitions.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

+74 -46
+4 -2
fs/lockd/lockd.h
··· 221 221 * Global variables 222 222 */ 223 223 extern const struct rpc_program nlm_program; 224 - extern const struct svc_procedure nlmsvc_procedures[24]; 224 + extern const struct svc_version nlmsvc_version1; 225 + extern const struct svc_version nlmsvc_version3; 225 226 #ifdef CONFIG_LOCKD_V4 226 - extern const struct svc_procedure nlmsvc_procedures4[24]; 227 + extern const struct svc_version nlmsvc_version4; 227 228 #endif 228 229 extern int nlmsvc_grace_period; 229 230 extern unsigned long nlm_timeout; ··· 319 318 void nlmsvc_grant_reply(struct nlm_cookie *, __be32); 320 319 void nlmsvc_release_call(struct nlm_rqst *); 321 320 void nlmsvc_locks_init_private(struct file_lock *, struct nlm_host *, pid_t); 321 + int nlmsvc_dispatch(struct svc_rqst *rqstp); 322 322 323 323 /* 324 324 * File handling for the server personality
+11 -37
fs/lockd/svc.c
··· 44 44 #include "netlink.h" 45 45 46 46 #define NLMDBG_FACILITY NLMDBG_SVC 47 - #define LOCKD_BUFSIZE (1024 + NLMSVC_XDRSIZE) 48 47 49 48 static struct svc_program nlmsvc_program; 50 49 ··· 318 319 static int lockd_get(void) 319 320 { 320 321 struct svc_serv *serv; 322 + unsigned int bufsize; 321 323 int error; 322 324 323 325 if (nlmsvc_serv) { ··· 334 334 printk(KERN_WARNING 335 335 "lockd_up: no pid, %d users??\n", nlmsvc_users); 336 336 337 - serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, lockd); 337 + #ifdef CONFIG_LOCKD_V4 338 + bufsize = 1024 + max3(nlmsvc_version1.vs_xdrsize, 339 + nlmsvc_version3.vs_xdrsize, 340 + nlmsvc_version4.vs_xdrsize); 341 + #else 342 + bufsize = 1024 + max(nlmsvc_version1.vs_xdrsize, 343 + nlmsvc_version3.vs_xdrsize); 344 + #endif 345 + serv = svc_create(&nlmsvc_program, bufsize, lockd); 338 346 if (!serv) { 339 347 printk(KERN_WARNING "lockd_up: create service failed\n"); 340 348 return -ENOMEM; ··· 648 640 * %0: Processing complete; do not send a Reply 649 641 * %1: Processing complete; send Reply in rqstp->rq_res 650 642 */ 651 - static int nlmsvc_dispatch(struct svc_rqst *rqstp) 643 + int nlmsvc_dispatch(struct svc_rqst *rqstp) 652 644 { 653 645 const struct svc_procedure *procp = rqstp->rq_procinfo; 654 646 __be32 *statp = rqstp->rq_accept_statp; ··· 679 671 /* 680 672 * Define NLM program and procedures 681 673 */ 682 - static DEFINE_PER_CPU_ALIGNED(unsigned long, nlmsvc_version1_count[17]); 683 - static const struct svc_version nlmsvc_version1 = { 684 - .vs_vers = 1, 685 - .vs_nproc = 17, 686 - .vs_proc = nlmsvc_procedures, 687 - .vs_count = nlmsvc_version1_count, 688 - .vs_dispatch = nlmsvc_dispatch, 689 - .vs_xdrsize = NLMSVC_XDRSIZE, 690 - }; 691 - 692 - static DEFINE_PER_CPU_ALIGNED(unsigned long, 693 - nlmsvc_version3_count[ARRAY_SIZE(nlmsvc_procedures)]); 694 - static const struct svc_version nlmsvc_version3 = { 695 - .vs_vers = 3, 696 - .vs_nproc = ARRAY_SIZE(nlmsvc_procedures), 697 - .vs_proc = nlmsvc_procedures, 698 - .vs_count = nlmsvc_version3_count, 699 - .vs_dispatch = nlmsvc_dispatch, 700 - .vs_xdrsize = NLMSVC_XDRSIZE, 701 - }; 702 - 703 - #ifdef CONFIG_LOCKD_V4 704 - static DEFINE_PER_CPU_ALIGNED(unsigned long, 705 - nlmsvc_version4_count[ARRAY_SIZE(nlmsvc_procedures4)]); 706 - static const struct svc_version nlmsvc_version4 = { 707 - .vs_vers = 4, 708 - .vs_nproc = ARRAY_SIZE(nlmsvc_procedures4), 709 - .vs_proc = nlmsvc_procedures4, 710 - .vs_count = nlmsvc_version4_count, 711 - .vs_dispatch = nlmsvc_dispatch, 712 - .vs_xdrsize = NLMSVC_XDRSIZE, 713 - }; 714 - #endif 715 - 716 674 static const struct svc_version *nlmsvc_version[] = { 717 675 [1] = &nlmsvc_version1, 718 676 [3] = &nlmsvc_version3,
+22 -1
fs/lockd/svc4proc.c
··· 530 530 #define St 1 /* status */ 531 531 #define Rg 4 /* range (offset + length) */ 532 532 533 - const struct svc_procedure nlmsvc_procedures4[24] = { 533 + static const struct svc_procedure nlm4svc_procedures[24] = { 534 534 [NLMPROC_NULL] = { 535 535 .pc_func = nlm4svc_proc_null, 536 536 .pc_decode = nlm4svc_decode_void, ··· 771 771 .pc_xdrressize = St, 772 772 .pc_name = "FREE_ALL", 773 773 }, 774 + }; 775 + 776 + /* 777 + * Storage requirements for XDR arguments and results 778 + */ 779 + union nlm4svc_xdrstore { 780 + struct nlm_args args; 781 + struct nlm_res res; 782 + struct nlm_reboot reboot; 783 + }; 784 + 785 + static DEFINE_PER_CPU_ALIGNED(unsigned long, 786 + nlm4svc_call_counters[ARRAY_SIZE(nlm4svc_procedures)]); 787 + 788 + const struct svc_version nlmsvc_version4 = { 789 + .vs_vers = 4, 790 + .vs_nproc = ARRAY_SIZE(nlm4svc_procedures), 791 + .vs_proc = nlm4svc_procedures, 792 + .vs_count = nlm4svc_call_counters, 793 + .vs_dispatch = nlmsvc_dispatch, 794 + .vs_xdrsize = sizeof(union nlm4svc_xdrstore), 774 795 };
+37 -1
fs/lockd/svcproc.c
··· 555 555 #define No (1+1024/4) /* Net Obj */ 556 556 #define Rg 2 /* range - offset + size */ 557 557 558 - const struct svc_procedure nlmsvc_procedures[24] = { 558 + static const struct svc_procedure nlmsvc_procedures[24] = { 559 559 [NLMPROC_NULL] = { 560 560 .pc_func = nlmsvc_proc_null, 561 561 .pc_decode = nlmsvc_decode_void, ··· 796 796 .pc_xdrressize = 0, 797 797 .pc_name = "FREE_ALL", 798 798 }, 799 + }; 800 + 801 + /* 802 + * Storage requirements for XDR arguments and results 803 + */ 804 + union nlmsvc_xdrstore { 805 + struct nlm_args args; 806 + struct nlm_res res; 807 + struct nlm_reboot reboot; 808 + }; 809 + 810 + /* 811 + * NLMv1 defines only procedures 1 - 15. Linux lockd also implements 812 + * procedures 0 (NULL) and 16 (SM_NOTIFY). 813 + */ 814 + static DEFINE_PER_CPU_ALIGNED(unsigned long, nlm1svc_call_counters[17]); 815 + 816 + const struct svc_version nlmsvc_version1 = { 817 + .vs_vers = 1, 818 + .vs_nproc = 17, 819 + .vs_proc = nlmsvc_procedures, 820 + .vs_count = nlm1svc_call_counters, 821 + .vs_dispatch = nlmsvc_dispatch, 822 + .vs_xdrsize = sizeof(union nlmsvc_xdrstore), 823 + }; 824 + 825 + static DEFINE_PER_CPU_ALIGNED(unsigned long, 826 + nlm3svc_call_counters[ARRAY_SIZE(nlmsvc_procedures)]); 827 + 828 + const struct svc_version nlmsvc_version3 = { 829 + .vs_vers = 3, 830 + .vs_nproc = ARRAY_SIZE(nlmsvc_procedures), 831 + .vs_proc = nlmsvc_procedures, 832 + .vs_count = nlm3svc_call_counters, 833 + .vs_dispatch = nlmsvc_dispatch, 834 + .vs_xdrsize = sizeof(union nlmsvc_xdrstore), 799 835 };
-5
fs/lockd/xdr.h
··· 88 88 struct nsm_private priv; 89 89 }; 90 90 91 - /* 92 - * Contents of statd callback when monitored host rebooted 93 - */ 94 - #define NLMSVC_XDRSIZE sizeof(struct nlm_args) 95 - 96 91 bool nlmsvc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr); 97 92 bool nlmsvc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr); 98 93 bool nlmsvc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);