* [PATCH] nfsd: permit to use multiple time the -H option
@ 2014-03-02 9:38 Michael Scherer
2014-03-03 20:19 ` J. Bruce Fields
2014-03-11 18:09 ` Steve Dickson
0 siblings, 2 replies; 4+ messages in thread
From: Michael Scherer @ 2014-03-02 9:38 UTC (permalink / raw)
To: linux-nfs; +Cc: Michael Scherer
This permit to have 1 nfsd listening on more than 1
interface for multihomed systems, without having to
listen on all interfaces and filtering later.
---
utils/nfsd/nfsd.c | 51 +++++++++++++++++++++++++++++++++++----------------
utils/nfsd/nfsd.man | 3 ++-
2 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
index edeb621..7ab6fcf 100644
--- a/utils/nfsd/nfsd.c
+++ b/utils/nfsd/nfsd.c
@@ -95,9 +95,10 @@ nfsd_enable_protos(unsigned int *proto4, unsigned int *proto6)
int
main(int argc, char **argv)
{
- int count = NFSD_NPROC, c, error = 0, portnum = 0, fd, found_one;
+ int count = NFSD_NPROC, c, i, error = 0, portnum = 0, fd, found_one;
char *p, *progname, *port;
- char *haddr = NULL;
+ char **haddr = NULL;
+ unsigned int hcounter = 0;
int socket_up = 0;
unsigned int minorvers = 0;
unsigned int minorversset = 0;
@@ -118,6 +119,13 @@ main(int argc, char **argv)
exit(1);
}
+ haddr = malloc(sizeof(char*));
+ if (!haddr) {
+ fprintf(stderr, "%s: unable to allocate memory.\n", progname);
+ exit(1);
+ }
+ haddr[0] = NULL;
+
xlog_syslog(0);
xlog_stderr(1);
@@ -127,17 +135,24 @@ main(int argc, char **argv)
xlog_config(D_ALL, 1);
break;
case 'H':
- /*
- * for now, this only handles one -H option. Use the
- * last one specified.
- */
- free(haddr);
- haddr = strdup(optarg);
- if (!haddr) {
+ if (hcounter) {
+ haddr = realloc(haddr, sizeof(char*) * hcounter+1);
+
+ if(!haddr) {
+ fprintf(stderr, "%s: unable to allocate "
+ "memory.\n", progname);
+ exit(1);
+ }
+ }
+
+ haddr[hcounter] = strdup(optarg);
+ if (!haddr[hcounter]) {
fprintf(stderr, "%s: unable to allocate "
"memory.\n", progname);
exit(1);
}
+
+ hcounter++;
break;
case 'P': /* XXX for nfs-server compatibility */
case 'p':
@@ -286,16 +301,18 @@ main(int argc, char **argv)
* interfaces, these are a no-op.
*/
nfssvc_setvers(versbits, minorvers, minorversset);
-
- error = nfssvc_set_sockets(AF_INET, proto4, haddr, port);
- if (!error)
- socket_up = 1;
+
+ for(i=0; i <= hcounter; i++) {
+ error = nfssvc_set_sockets(AF_INET, proto4, haddr[i], port);
+ if (!error)
+ socket_up = 1;
#ifdef IPV6_SUPPORTED
- error = nfssvc_set_sockets(AF_INET6, proto6, haddr, port);
- if (!error)
- socket_up = 1;
+ error = nfssvc_set_sockets(AF_INET6, proto6, haddr[i], port);
+ if (!error)
+ socket_up = 1;
#endif /* IPV6_SUPPORTED */
+ }
set_threads:
/* don't start any threads if unable to hand off any sockets */
@@ -328,6 +345,8 @@ set_threads:
xlog(L_ERROR, "error starting threads: errno %d (%m)", errno);
out:
free(port);
+ for(i=0; i <= hcounter; i++)
+ free(haddr[i]);
free(haddr);
free(progname);
return (error != 0);
diff --git a/utils/nfsd/nfsd.man b/utils/nfsd/nfsd.man
index 7de0867..cdc14ba 100644
--- a/utils/nfsd/nfsd.man
+++ b/utils/nfsd/nfsd.man
@@ -35,7 +35,8 @@ Note that
.B lockd
(which performs file locking services for NFS) may still accept
request on all known network addresses. This may change in future
-releases of the Linux Kernel.
+releases of the Linux Kernel. This option can be used multiple time
+to listen to more than one interface.
.TP
.B \-p " or " \-\-port port
specify a different port to listen on for NFS requests. By default,
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] nfsd: permit to use multiple time the -H option
2014-03-02 9:38 [PATCH] nfsd: permit to use multiple time the -H option Michael Scherer
@ 2014-03-03 20:19 ` J. Bruce Fields
2014-03-11 17:59 ` Steve Dickson
2014-03-11 18:09 ` Steve Dickson
1 sibling, 1 reply; 4+ messages in thread
From: J. Bruce Fields @ 2014-03-03 20:19 UTC (permalink / raw)
To: Michael Scherer; +Cc: linux-nfs
On Sun, Mar 02, 2014 at 10:38:32AM +0100, Michael Scherer wrote:
> This permit to have 1 nfsd listening on more than 1
> interface for multihomed systems, without having to
> listen on all interfaces and filtering later.
> ---
> utils/nfsd/nfsd.c | 51 +++++++++++++++++++++++++++++++++++----------------
> utils/nfsd/nfsd.man | 3 ++-
> 2 files changed, 37 insertions(+), 17 deletions(-)
>
> diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
> index edeb621..7ab6fcf 100644
> --- a/utils/nfsd/nfsd.c
> +++ b/utils/nfsd/nfsd.c
> @@ -95,9 +95,10 @@ nfsd_enable_protos(unsigned int *proto4, unsigned int *proto6)
> int
> main(int argc, char **argv)
> {
> - int count = NFSD_NPROC, c, error = 0, portnum = 0, fd, found_one;
> + int count = NFSD_NPROC, c, i, error = 0, portnum = 0, fd, found_one;
> char *p, *progname, *port;
> - char *haddr = NULL;
> + char **haddr = NULL;
> + unsigned int hcounter = 0;
> int socket_up = 0;
> unsigned int minorvers = 0;
> unsigned int minorversset = 0;
> @@ -118,6 +119,13 @@ main(int argc, char **argv)
> exit(1);
> }
>
> + haddr = malloc(sizeof(char*));
> + if (!haddr) {
> + fprintf(stderr, "%s: unable to allocate memory.\n", progname);
> + exit(1);
> + }
> + haddr[0] = NULL;
> +
Checking "man malloc..." realloc(NULL) is the same as malloc(), so you
can just skip this initial allocation (and the "if hcounter" below) and
count on the realloc below doing the right thing when it needs to.
Otherwise, allowing multiple -H options seems like a reasonable thing to
do.
--b.
> xlog_syslog(0);
> xlog_stderr(1);
>
> @@ -127,17 +135,24 @@ main(int argc, char **argv)
> xlog_config(D_ALL, 1);
> break;
> case 'H':
> - /*
> - * for now, this only handles one -H option. Use the
> - * last one specified.
> - */
> - free(haddr);
> - haddr = strdup(optarg);
> - if (!haddr) {
> + if (hcounter) {
> + haddr = realloc(haddr, sizeof(char*) * hcounter+1);
> +
> + if(!haddr) {
> + fprintf(stderr, "%s: unable to allocate "
> + "memory.\n", progname);
> + exit(1);
> + }
> + }
> +
> + haddr[hcounter] = strdup(optarg);
> + if (!haddr[hcounter]) {
> fprintf(stderr, "%s: unable to allocate "
> "memory.\n", progname);
> exit(1);
> }
> +
> + hcounter++;
> break;
> case 'P': /* XXX for nfs-server compatibility */
> case 'p':
> @@ -286,16 +301,18 @@ main(int argc, char **argv)
> * interfaces, these are a no-op.
> */
> nfssvc_setvers(versbits, minorvers, minorversset);
> -
> - error = nfssvc_set_sockets(AF_INET, proto4, haddr, port);
> - if (!error)
> - socket_up = 1;
> +
> + for(i=0; i <= hcounter; i++) {
> + error = nfssvc_set_sockets(AF_INET, proto4, haddr[i], port);
> + if (!error)
> + socket_up = 1;
>
> #ifdef IPV6_SUPPORTED
> - error = nfssvc_set_sockets(AF_INET6, proto6, haddr, port);
> - if (!error)
> - socket_up = 1;
> + error = nfssvc_set_sockets(AF_INET6, proto6, haddr[i], port);
> + if (!error)
> + socket_up = 1;
> #endif /* IPV6_SUPPORTED */
> + }
>
> set_threads:
> /* don't start any threads if unable to hand off any sockets */
> @@ -328,6 +345,8 @@ set_threads:
> xlog(L_ERROR, "error starting threads: errno %d (%m)", errno);
> out:
> free(port);
> + for(i=0; i <= hcounter; i++)
> + free(haddr[i]);
> free(haddr);
> free(progname);
> return (error != 0);
> diff --git a/utils/nfsd/nfsd.man b/utils/nfsd/nfsd.man
> index 7de0867..cdc14ba 100644
> --- a/utils/nfsd/nfsd.man
> +++ b/utils/nfsd/nfsd.man
> @@ -35,7 +35,8 @@ Note that
> .B lockd
> (which performs file locking services for NFS) may still accept
> request on all known network addresses. This may change in future
> -releases of the Linux Kernel.
> +releases of the Linux Kernel. This option can be used multiple time
> +to listen to more than one interface.
> .TP
> .B \-p " or " \-\-port port
> specify a different port to listen on for NFS requests. By default,
> --
> 1.8.5.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nfsd: permit to use multiple time the -H option
2014-03-03 20:19 ` J. Bruce Fields
@ 2014-03-11 17:59 ` Steve Dickson
0 siblings, 0 replies; 4+ messages in thread
From: Steve Dickson @ 2014-03-11 17:59 UTC (permalink / raw)
To: J. Bruce Fields, Michael Scherer; +Cc: linux-nfs
On 03/03/2014 03:19 PM, J. Bruce Fields wrote:
> On Sun, Mar 02, 2014 at 10:38:32AM +0100, Michael Scherer wrote:
>> This permit to have 1 nfsd listening on more than 1
>> interface for multihomed systems, without having to
>> listen on all interfaces and filtering later.
>> ---
>> utils/nfsd/nfsd.c | 51 +++++++++++++++++++++++++++++++++++----------------
>> utils/nfsd/nfsd.man | 3 ++-
>> 2 files changed, 37 insertions(+), 17 deletions(-)
>>
>> diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
>> index edeb621..7ab6fcf 100644
>> --- a/utils/nfsd/nfsd.c
>> +++ b/utils/nfsd/nfsd.c
>> @@ -95,9 +95,10 @@ nfsd_enable_protos(unsigned int *proto4, unsigned int *proto6)
>> int
>> main(int argc, char **argv)
>> {
>> - int count = NFSD_NPROC, c, error = 0, portnum = 0, fd, found_one;
>> + int count = NFSD_NPROC, c, i, error = 0, portnum = 0, fd, found_one;
>> char *p, *progname, *port;
>> - char *haddr = NULL;
>> + char **haddr = NULL;
>> + unsigned int hcounter = 0;
>> int socket_up = 0;
>> unsigned int minorvers = 0;
>> unsigned int minorversset = 0;
>> @@ -118,6 +119,13 @@ main(int argc, char **argv)
>> exit(1);
>> }
>>
>> + haddr = malloc(sizeof(char*));
>> + if (!haddr) {
>> + fprintf(stderr, "%s: unable to allocate memory.\n", progname);
>> + exit(1);
>> + }
>> + haddr[0] = NULL;
>> +
>
> Checking "man malloc..." realloc(NULL) is the same as malloc(), so you
> can just skip this initial allocation (and the "if hcounter" below) and
> count on the realloc below doing the right thing when it needs to.
>
> Otherwise, allowing multiple -H options seems like a reasonable thing to
> do.
It turns out you do need allocate a NULL entry for when there are
no -H specified...
steved.
>
> --b.
>
>> xlog_syslog(0);
>> xlog_stderr(1);
>>
>> @@ -127,17 +135,24 @@ main(int argc, char **argv)
>> xlog_config(D_ALL, 1);
>> break;
>> case 'H':
>> - /*
>> - * for now, this only handles one -H option. Use the
>> - * last one specified.
>> - */
>> - free(haddr);
>> - haddr = strdup(optarg);
>> - if (!haddr) {
>> + if (hcounter) {
>> + haddr = realloc(haddr, sizeof(char*) * hcounter+1);
>> +
>> + if(!haddr) {
>> + fprintf(stderr, "%s: unable to allocate "
>> + "memory.\n", progname);
>> + exit(1);
>> + }
>> + }
>> +
>> + haddr[hcounter] = strdup(optarg);
>> + if (!haddr[hcounter]) {
>> fprintf(stderr, "%s: unable to allocate "
>> "memory.\n", progname);
>> exit(1);
>> }
>> +
>> + hcounter++;
>> break;
>> case 'P': /* XXX for nfs-server compatibility */
>> case 'p':
>> @@ -286,16 +301,18 @@ main(int argc, char **argv)
>> * interfaces, these are a no-op.
>> */
>> nfssvc_setvers(versbits, minorvers, minorversset);
>> -
>> - error = nfssvc_set_sockets(AF_INET, proto4, haddr, port);
>> - if (!error)
>> - socket_up = 1;
>> +
>> + for(i=0; i <= hcounter; i++) {
>> + error = nfssvc_set_sockets(AF_INET, proto4, haddr[i], port);
>> + if (!error)
>> + socket_up = 1;
>>
>> #ifdef IPV6_SUPPORTED
>> - error = nfssvc_set_sockets(AF_INET6, proto6, haddr, port);
>> - if (!error)
>> - socket_up = 1;
>> + error = nfssvc_set_sockets(AF_INET6, proto6, haddr[i], port);
>> + if (!error)
>> + socket_up = 1;
>> #endif /* IPV6_SUPPORTED */
>> + }
>>
>> set_threads:
>> /* don't start any threads if unable to hand off any sockets */
>> @@ -328,6 +345,8 @@ set_threads:
>> xlog(L_ERROR, "error starting threads: errno %d (%m)", errno);
>> out:
>> free(port);
>> + for(i=0; i <= hcounter; i++)
>> + free(haddr[i]);
>> free(haddr);
>> free(progname);
>> return (error != 0);
>> diff --git a/utils/nfsd/nfsd.man b/utils/nfsd/nfsd.man
>> index 7de0867..cdc14ba 100644
>> --- a/utils/nfsd/nfsd.man
>> +++ b/utils/nfsd/nfsd.man
>> @@ -35,7 +35,8 @@ Note that
>> .B lockd
>> (which performs file locking services for NFS) may still accept
>> request on all known network addresses. This may change in future
>> -releases of the Linux Kernel.
>> +releases of the Linux Kernel. This option can be used multiple time
>> +to listen to more than one interface.
>> .TP
>> .B \-p " or " \-\-port port
>> specify a different port to listen on for NFS requests. By default,
>> --
>> 1.8.5.3
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] nfsd: permit to use multiple time the -H option
2014-03-02 9:38 [PATCH] nfsd: permit to use multiple time the -H option Michael Scherer
2014-03-03 20:19 ` J. Bruce Fields
@ 2014-03-11 18:09 ` Steve Dickson
1 sibling, 0 replies; 4+ messages in thread
From: Steve Dickson @ 2014-03-11 18:09 UTC (permalink / raw)
To: Michael Scherer, linux-nfs
On 03/02/2014 04:38 AM, Michael Scherer wrote:
> This permit to have 1 nfsd listening on more than 1
> interface for multihomed systems, without having to
> listen on all interfaces and filtering later.
> ---
> utils/nfsd/nfsd.c | 51 +++++++++++++++++++++++++++++++++++----------------
> utils/nfsd/nfsd.man | 3 ++-
> 2 files changed, 37 insertions(+), 17 deletions(-)
Committed...
steved.
>
> diff --git a/utils/nfsd/nfsd.c b/utils/nfsd/nfsd.c
> index edeb621..7ab6fcf 100644
> --- a/utils/nfsd/nfsd.c
> +++ b/utils/nfsd/nfsd.c
> @@ -95,9 +95,10 @@ nfsd_enable_protos(unsigned int *proto4, unsigned int *proto6)
> int
> main(int argc, char **argv)
> {
> - int count = NFSD_NPROC, c, error = 0, portnum = 0, fd, found_one;
> + int count = NFSD_NPROC, c, i, error = 0, portnum = 0, fd, found_one;
> char *p, *progname, *port;
> - char *haddr = NULL;
> + char **haddr = NULL;
> + unsigned int hcounter = 0;
> int socket_up = 0;
> unsigned int minorvers = 0;
> unsigned int minorversset = 0;
> @@ -118,6 +119,13 @@ main(int argc, char **argv)
> exit(1);
> }
>
> + haddr = malloc(sizeof(char*));
> + if (!haddr) {
> + fprintf(stderr, "%s: unable to allocate memory.\n", progname);
> + exit(1);
> + }
> + haddr[0] = NULL;
> +
> xlog_syslog(0);
> xlog_stderr(1);
>
> @@ -127,17 +135,24 @@ main(int argc, char **argv)
> xlog_config(D_ALL, 1);
> break;
> case 'H':
> - /*
> - * for now, this only handles one -H option. Use the
> - * last one specified.
> - */
> - free(haddr);
> - haddr = strdup(optarg);
> - if (!haddr) {
> + if (hcounter) {
> + haddr = realloc(haddr, sizeof(char*) * hcounter+1);
> +
> + if(!haddr) {
> + fprintf(stderr, "%s: unable to allocate "
> + "memory.\n", progname);
> + exit(1);
> + }
> + }
> +
> + haddr[hcounter] = strdup(optarg);
> + if (!haddr[hcounter]) {
> fprintf(stderr, "%s: unable to allocate "
> "memory.\n", progname);
> exit(1);
> }
> +
> + hcounter++;
> break;
> case 'P': /* XXX for nfs-server compatibility */
> case 'p':
> @@ -286,16 +301,18 @@ main(int argc, char **argv)
> * interfaces, these are a no-op.
> */
> nfssvc_setvers(versbits, minorvers, minorversset);
> -
> - error = nfssvc_set_sockets(AF_INET, proto4, haddr, port);
> - if (!error)
> - socket_up = 1;
> +
> + for(i=0; i <= hcounter; i++) {
> + error = nfssvc_set_sockets(AF_INET, proto4, haddr[i], port);
> + if (!error)
> + socket_up = 1;
>
> #ifdef IPV6_SUPPORTED
> - error = nfssvc_set_sockets(AF_INET6, proto6, haddr, port);
> - if (!error)
> - socket_up = 1;
> + error = nfssvc_set_sockets(AF_INET6, proto6, haddr[i], port);
> + if (!error)
> + socket_up = 1;
> #endif /* IPV6_SUPPORTED */
> + }
>
> set_threads:
> /* don't start any threads if unable to hand off any sockets */
> @@ -328,6 +345,8 @@ set_threads:
> xlog(L_ERROR, "error starting threads: errno %d (%m)", errno);
> out:
> free(port);
> + for(i=0; i <= hcounter; i++)
> + free(haddr[i]);
> free(haddr);
> free(progname);
> return (error != 0);
> diff --git a/utils/nfsd/nfsd.man b/utils/nfsd/nfsd.man
> index 7de0867..cdc14ba 100644
> --- a/utils/nfsd/nfsd.man
> +++ b/utils/nfsd/nfsd.man
> @@ -35,7 +35,8 @@ Note that
> .B lockd
> (which performs file locking services for NFS) may still accept
> request on all known network addresses. This may change in future
> -releases of the Linux Kernel.
> +releases of the Linux Kernel. This option can be used multiple time
> +to listen to more than one interface.
> .TP
> .B \-p " or " \-\-port port
> specify a different port to listen on for NFS requests. By default,
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-11 19:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-02 9:38 [PATCH] nfsd: permit to use multiple time the -H option Michael Scherer
2014-03-03 20:19 ` J. Bruce Fields
2014-03-11 17:59 ` Steve Dickson
2014-03-11 18:09 ` Steve Dickson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).