diff options
author | Jeff Layton <jlayton@redhat.com> | 2012-11-12 15:00:48 -0500 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2012-11-12 18:55:10 -0500 |
commit | 2873d2147e1e14b82367bde14354a011ffda0496 (patch) | |
tree | 16d9511c07bb1287d3763f5539634cc9bd9fd549 | |
parent | a0af710a6510213672d28f83681c391d36a7555e (diff) |
nfsd: add a usermodehelper upcall for NFSv4 client ID tracking
Add a new client tracker upcall type that uses call_usermodehelper to
call out to a program. This seems to be the preferred method of
calling out to usermode these days for seldom-called upcalls. It's
simple and doesn't require a running daemon, so it should "just work"
as long as the binary is installed.
The client tracking exit operation is also changed to check for a
NULL pointer before running. The UMH upcall doesn't need to do anything
at module teardown time.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r-- | fs/nfsd/nfs4recover.c | 134 |
1 files changed, 133 insertions, 1 deletions
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index 151921bd164e..2fc2f6cb8d95 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c | |||
@@ -927,6 +927,137 @@ static struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = { | |||
927 | .grace_done = nfsd4_cld_grace_done, | 927 | .grace_done = nfsd4_cld_grace_done, |
928 | }; | 928 | }; |
929 | 929 | ||
930 | /* upcall via usermodehelper */ | ||
931 | static char cltrack_prog[PATH_MAX] = "/sbin/nfsdcltrack"; | ||
932 | module_param_string(cltrack_prog, cltrack_prog, sizeof(cltrack_prog), | ||
933 | S_IRUGO|S_IWUSR); | ||
934 | MODULE_PARM_DESC(cltrack_prog, "Path to the nfsdcltrack upcall program"); | ||
935 | |||
936 | static int | ||
937 | nfsd4_umh_cltrack_upcall(char *cmd, char *arg) | ||
938 | { | ||
939 | char *envp[] = { NULL }; | ||
940 | char *argv[4]; | ||
941 | int ret; | ||
942 | |||
943 | if (unlikely(!cltrack_prog[0])) { | ||
944 | dprintk("%s: cltrack_prog is disabled\n", __func__); | ||
945 | return -EACCES; | ||
946 | } | ||
947 | |||
948 | dprintk("%s: cmd: %s\n", __func__, cmd); | ||
949 | dprintk("%s: arg: %s\n", __func__, arg ? arg : "(null)"); | ||
950 | |||
951 | argv[0] = (char *)cltrack_prog; | ||
952 | argv[1] = cmd; | ||
953 | argv[2] = arg; | ||
954 | argv[3] = NULL; | ||
955 | |||
956 | ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC); | ||
957 | /* | ||
958 | * Disable the upcall mechanism if we're getting an ENOENT or EACCES | ||
959 | * error. The admin can re-enable it on the fly by using sysfs | ||
960 | * once the problem has been fixed. | ||
961 | */ | ||
962 | if (ret == -ENOENT || ret == -EACCES) { | ||
963 | dprintk("NFSD: %s was not found or isn't executable (%d). " | ||
964 | "Setting cltrack_prog to blank string!", | ||
965 | cltrack_prog, ret); | ||
966 | cltrack_prog[0] = '\0'; | ||
967 | } | ||
968 | dprintk("%s: %s return value: %d\n", __func__, cltrack_prog, ret); | ||
969 | |||
970 | return ret; | ||
971 | } | ||
972 | |||
973 | static char * | ||
974 | bin_to_hex_dup(const unsigned char *src, int srclen) | ||
975 | { | ||
976 | int i; | ||
977 | char *buf, *hex; | ||
978 | |||
979 | /* +1 for terminating NULL */ | ||
980 | buf = kmalloc((srclen * 2) + 1, GFP_KERNEL); | ||
981 | if (!buf) | ||
982 | return buf; | ||
983 | |||
984 | hex = buf; | ||
985 | for (i = 0; i < srclen; i++) { | ||
986 | sprintf(hex, "%2.2x", *src++); | ||
987 | hex += 2; | ||
988 | } | ||
989 | return buf; | ||
990 | } | ||
991 | |||
992 | static int | ||
993 | nfsd4_umh_cltrack_init(struct net __attribute__((unused)) *net) | ||
994 | { | ||
995 | return nfsd4_umh_cltrack_upcall("init", NULL); | ||
996 | } | ||
997 | |||
998 | static void | ||
999 | nfsd4_umh_cltrack_create(struct nfs4_client *clp) | ||
1000 | { | ||
1001 | char *hexid; | ||
1002 | |||
1003 | hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len); | ||
1004 | if (!hexid) { | ||
1005 | dprintk("%s: can't allocate memory for upcall!\n", __func__); | ||
1006 | return; | ||
1007 | } | ||
1008 | nfsd4_umh_cltrack_upcall("create", hexid); | ||
1009 | kfree(hexid); | ||
1010 | } | ||
1011 | |||
1012 | static void | ||
1013 | nfsd4_umh_cltrack_remove(struct nfs4_client *clp) | ||
1014 | { | ||
1015 | char *hexid; | ||
1016 | |||
1017 | hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len); | ||
1018 | if (!hexid) { | ||
1019 | dprintk("%s: can't allocate memory for upcall!\n", __func__); | ||
1020 | return; | ||
1021 | } | ||
1022 | nfsd4_umh_cltrack_upcall("remove", hexid); | ||
1023 | kfree(hexid); | ||
1024 | } | ||
1025 | |||
1026 | static int | ||
1027 | nfsd4_umh_cltrack_check(struct nfs4_client *clp) | ||
1028 | { | ||
1029 | int ret; | ||
1030 | char *hexid; | ||
1031 | |||
1032 | hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len); | ||
1033 | if (!hexid) { | ||
1034 | dprintk("%s: can't allocate memory for upcall!\n", __func__); | ||
1035 | return -ENOMEM; | ||
1036 | } | ||
1037 | ret = nfsd4_umh_cltrack_upcall("check", hexid); | ||
1038 | kfree(hexid); | ||
1039 | return ret; | ||
1040 | } | ||
1041 | |||
1042 | static void | ||
1043 | nfsd4_umh_cltrack_grace_done(struct net __attribute__((unused)) *net, | ||
1044 | time_t boot_time) | ||
1045 | { | ||
1046 | char timestr[22]; /* FIXME: better way to determine max size? */ | ||
1047 | |||
1048 | sprintf(timestr, "%ld", boot_time); | ||
1049 | nfsd4_umh_cltrack_upcall("gracedone", timestr); | ||
1050 | } | ||
1051 | |||
1052 | static struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = { | ||
1053 | .init = nfsd4_umh_cltrack_init, | ||
1054 | .exit = NULL, | ||
1055 | .create = nfsd4_umh_cltrack_create, | ||
1056 | .remove = nfsd4_umh_cltrack_remove, | ||
1057 | .check = nfsd4_umh_cltrack_check, | ||
1058 | .grace_done = nfsd4_umh_cltrack_grace_done, | ||
1059 | }; | ||
1060 | |||
930 | int | 1061 | int |
931 | nfsd4_client_tracking_init(struct net *net) | 1062 | nfsd4_client_tracking_init(struct net *net) |
932 | { | 1063 | { |
@@ -957,7 +1088,8 @@ void | |||
957 | nfsd4_client_tracking_exit(struct net *net) | 1088 | nfsd4_client_tracking_exit(struct net *net) |
958 | { | 1089 | { |
959 | if (client_tracking_ops) { | 1090 | if (client_tracking_ops) { |
960 | client_tracking_ops->exit(net); | 1091 | if (client_tracking_ops->exit) |
1092 | client_tracking_ops->exit(net); | ||
961 | client_tracking_ops = NULL; | 1093 | client_tracking_ops = NULL; |
962 | } | 1094 | } |
963 | } | 1095 | } |