Linux NFS development
 help / color / mirror / Atom feed
From: Steve Dickson <SteveD@redhat.com>
To: Weston Andros Adamson <dros@netapp.com>
Cc: chuck.lever@oracle.com, linux-nfs@vger.kernel.org
Subject: Re: [PATCH] statd: exit if a statd is already running
Date: Tue, 07 May 2013 12:00:12 -0400	[thread overview]
Message-ID: <5189250C.3010903@RedHat.com> (raw)
In-Reply-To: <1367017819-11006-1-git-send-email-dros@netapp.com>



On 26/04/13 19:10, Weston Andros Adamson wrote:
> Moves nfs_probe_statd from mount to nfs support lib to share with statd.
> 
> Signed-off-by: Weston Andros Adamson <dros@netapp.com>
> ---
> 
> This patch stops users from running multiple instances of statd, which can
> obviously cause a lot of problems.
> 
>  support/include/nfsrpc.h |  5 +++++
>  support/nfs/getport.c    | 22 ++++++++++++++++++++++
>  utils/mount/network.c    | 17 -----------------
>  utils/statd/statd.c      |  6 ++++++
>  4 files changed, 33 insertions(+), 17 deletions(-)
Committed... 

steved.
> 
> diff --git a/support/include/nfsrpc.h b/support/include/nfsrpc.h
> index a0b80e1..1bfae7a 100644
> --- a/support/include/nfsrpc.h
> +++ b/support/include/nfsrpc.h
> @@ -156,6 +156,11 @@ extern unsigned long	nfs_pmap_getport(const struct sockaddr_in *,
>  				const struct timeval *);
>  
>  /*
> + * Use nfs_pmap_getport to see if statd is running locally
> + */
> +extern int nfs_probe_statd(void);
> +
> +/*
>   * Contact a remote RPC service to discover whether it is responding
>   * to requests.
>   */
> diff --git a/support/nfs/getport.c b/support/nfs/getport.c
> index 3331ad4..081594c 100644
> --- a/support/nfs/getport.c
> +++ b/support/nfs/getport.c
> @@ -1102,3 +1102,25 @@ unsigned long nfs_pmap_getport(const struct sockaddr_in *sin,
>  
>  	return port;
>  }
> +
> +static const char *nfs_ns_pgmtbl[] = {
> +        "status",
> +        NULL,
> +};
> +
> +/*
> + * nfs_probe_statd - use nfs_pmap_getport to see if statd is running locally
> + *
> + * Returns non-zero if statd is running locally.
> + */
> +int nfs_probe_statd(void)
> +{
> +        struct sockaddr_in addr = {
> +                .sin_family             = AF_INET,
> +                .sin_addr.s_addr        = htonl(INADDR_LOOPBACK),
> +        };
> +        rpcprog_t program = nfs_getrpcbyname(NSMPROG, nfs_ns_pgmtbl);
> +
> +        return nfs_getport_ping((struct sockaddr *)(char *)&addr, sizeof(addr),
> +                                program, (rpcvers_t)1, IPPROTO_UDP);
> +}
> diff --git a/utils/mount/network.c b/utils/mount/network.c
> index 4be48cd..e2cdcaf 100644
> --- a/utils/mount/network.c
> +++ b/utils/mount/network.c
> @@ -65,11 +65,6 @@ extern int nfs_mount_data_version;
>  extern char *progname;
>  extern int verbose;
>  
> -static const char *nfs_ns_pgmtbl[] = {
> -	"status",
> -	NULL,
> -};
> -
>  static const char *nfs_mnt_pgmtbl[] = {
>  	"mount",
>  	"mountd",
> @@ -761,18 +756,6 @@ int probe_bothports(clnt_addr_t *mnt_server, clnt_addr_t *nfs_server)
>  					&nfs_server->pmap);
>  }
>  
> -static int nfs_probe_statd(void)
> -{
> -	struct sockaddr_in addr = {
> -		.sin_family		= AF_INET,
> -		.sin_addr.s_addr	= htonl(INADDR_LOOPBACK),
> -	};
> -	rpcprog_t program = nfs_getrpcbyname(NSMPROG, nfs_ns_pgmtbl);
> -
> -	return nfs_getport_ping(SAFE_SOCKADDR(&addr), sizeof(addr),
> -				program, (rpcvers_t)1, IPPROTO_UDP);
> -}
> -
>  /**
>   * start_statd - attempt to start rpc.statd
>   *
> diff --git a/utils/statd/statd.c b/utils/statd/statd.c
> index 652546c..ed9c1db 100644
> --- a/utils/statd/statd.c
> +++ b/utils/statd/statd.c
> @@ -237,6 +237,12 @@ int main (int argc, char **argv)
>  	/* Set hostname */
>  	MY_NAME = NULL;
>  
> +	/* Refuse to start if another statd is running */
> +	if (nfs_probe_statd()) {
> +		fprintf(stderr, "Statd service already running!\n");
> +		exit(1);
> +	}
> +
>  	/* Process command line switches */
>  	while ((arg = getopt_long(argc, argv, "h?vVFNH:dn:p:o:P:L", longopts, NULL)) != EOF) {
>  		switch (arg) {
> 

      parent reply	other threads:[~2013-05-07 16:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-26 23:10 [PATCH] statd: exit if a statd is already running Weston Andros Adamson
2013-04-27  0:20 ` Chuck Lever
2013-05-07 16:00 ` Steve Dickson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5189250C.3010903@RedHat.com \
    --to=steved@redhat.com \
    --cc=chuck.lever@oracle.com \
    --cc=dros@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox