linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: Adam Kwolek <adam.kwolek@intel.com>
Cc: linux-raid@vger.kernel.org, ed.ciechanowski@intel.com,
	marcin.labun@intel.com
Subject: Re: [PATCH 04/14] Add continue option to grow command
Date: Wed, 21 Sep 2011 12:22:07 +1000	[thread overview]
Message-ID: <20110921122207.0f3e65b3@notabene.brown> (raw)
In-Reply-To: <20110916115417.5201.51789.stgit@gklab-128-013.igk.intel.com>

[-- Attachment #1: Type: text/plain, Size: 4372 bytes --]

On Fri, 16 Sep 2011 13:54:17 +0200 Adam Kwolek <adam.kwolek@intel.com> wrote:

> To allow for reshape continuation, 'continue' option is added
> to grow command. It is not possible to check, if any existing mdadm
> instance is going to take ownership on blocked md array or it is
> orphaned/interrupted reshape.
> To resolve this problem grow command with continue option,
> is allowed when current mdadm instance is only one in the system.
> 
> Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>

Checking how many instances of mdadm are running is definitely wrong.
What are you trying to guard against here?

If we do need locking to prevent two processes trying to manage an array at
the same time, I would suggest creating a 'pid' file
- /var/run/mdadm-reshape-mdXXX.pid
or something like that.

NeilBrown


> ---
> 
>  ReadMe.c |    1 +
>  mdadm.c  |   17 ++++++++++++++++-
>  mdadm.h  |    2 ++
>  util.c   |   37 +++++++++++++++++++++++++++++++++++++
>  4 files changed, 56 insertions(+), 1 deletions(-)
> 
> diff --git a/ReadMe.c b/ReadMe.c
> index b658841..f0dc0d9 100644
> --- a/ReadMe.c
> +++ b/ReadMe.c
> @@ -190,6 +190,7 @@ struct option long_options[] = {
>      {"backup-file", 1,0, BackupFile},
>      {"invalid-backup",0,0,InvalidBackup},
>      {"array-size", 1, 0, 'Z'},
> +    {"continue", 0, 0, Continue},
>  
>      /* For Incremental */
>      {"rebuild-map", 0, 0, RebuildMapOpt},
> diff --git a/mdadm.c b/mdadm.c
> index 4b817ab..f30534a 100644
> --- a/mdadm.c
> +++ b/mdadm.c
> @@ -74,6 +74,7 @@ int main(int argc, char *argv[])
>  	int export = 0;
>  	int assume_clean = 0;
>  	char *symlinks = NULL;
> +	int grow_continue = 0;
>  	/* autof indicates whether and how to create device node.
>  	 * bottom 3 bits are style.  Rest (when shifted) are number of parts
>  	 * 0  - unset
> @@ -988,7 +989,21 @@ int main(int argc, char *argv[])
>  			}
>  			backup_file = optarg;
>  			continue;
> -
> +		case O(GROW, Continue):
> +			/* Continuer broken grow
> +			 * To be sure that continuation is allowed check
> +			 * if there is only one (current) mdadm instance
> +			 */
> +			grow_continue = count_mdadms();
> +			fprintf(stderr, Name ": %i mdadm instance(s) found\n",
> +				grow_continue);
> +			if (grow_continue != 1) {
> +				fprintf(stderr, Name ": Grow continuation "
> +					"requires single mdadm instance "
> +					"running.\n");
> +				exit(2);
> +			}
> +			continue;
>  		case O(ASSEMBLE, InvalidBackup):
>  			/* Acknowledge that the backupfile is invalid, but ask
>  			 * to continue anyway
> diff --git a/mdadm.h b/mdadm.h
> index 9035e67..7e3a618 100644
> --- a/mdadm.h
> +++ b/mdadm.h
> @@ -313,6 +313,7 @@ enum special_options {
>  	RebuildMapOpt,
>  	InvalidBackup,
>  	UdevRules,
> +	Continue,
>  };
>  
>  /* structures read from config file */
> @@ -1162,6 +1163,7 @@ extern char *human_size_brief(long long bytes);
>  extern void print_r10_layout(int layout);
>  
>  extern int initramfs_is_in_use(void);
> +extern int count_mdadms(void);
>  #define INITRAMFS_IS_IN_USE		1
>  #define INITRAMFS_NOT_USED		0
>  
> diff --git a/util.c b/util.c
> index 7186f3f..5077c2f 100644
> --- a/util.c
> +++ b/util.c
> @@ -1790,3 +1790,40 @@ int initramfs_is_in_use(void)
>  
>  	return ret_val;
>  }
> +
> +int count_mdadms(void)
> +{
> +	int ret_val = 0;
> +	DIR *dirp;
> +	struct dirent *d_entry;
> +	int fd;
> +
> +	dirp = opendir("/proc");
> +	if (!dirp)
> +		return -1;
> +
> +	while ((d_entry = readdir(dirp)) != NULL) {
> +		char p[PATH_MAX];
> +
> +		if (!strcmp(d_entry->d_name, ".") ||
> +			!strcmp(d_entry->d_name, "..") ||
> +			!strcmp(d_entry->d_name, "self"))
> +			continue;
> +		errno = 0;
> +		fd = (int)strtol(d_entry->d_name, NULL, 10);
> +		if (errno)
> +			continue;
> +		sprintf(p, "/proc/%s/cmdline", d_entry->d_name);
> +		fd = open(p, O_RDONLY);
> +		if (fd < 0)
> +			continue;
> +		if (read(fd, p, PATH_MAX) > 0) {
> +			if (strcmp(p, "mdadm") == 0)
> +				ret_val++;
> +		}
> +		close(fd);
> +	}
> +	closedir(dirp);
> +
> +	return ret_val;
> +}
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

  reply	other threads:[~2011-09-21  2:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-16 11:53 [PATCH 00/14] Series short description Adam Kwolek
2011-09-16 11:53 ` [PATCH 01/14] Stop array reshape when mounted initramfs is detected Adam Kwolek
2011-09-19 10:42   ` NeilBrown
2011-09-19 11:14     ` Kwolek, Adam
2011-09-16 11:54 ` [PATCH 02/14] Stop container reshape while using initramfs Adam Kwolek
2011-09-16 11:54 ` [PATCH 03/14] FIX: Do not unblock array accidentally Adam Kwolek
2011-09-21  2:19   ` NeilBrown
2011-09-16 11:54 ` [PATCH 04/14] Add continue option to grow command Adam Kwolek
2011-09-21  2:22   ` NeilBrown [this message]
2011-09-21  7:47     ` Kwolek, Adam
2011-09-16 11:54 ` [PATCH 05/14] Add Grow_continue_command Adam Kwolek
2011-09-16 11:54 ` [PATCH 06/14] Check and run mdmon Adam Kwolek
2011-09-16 11:54 ` [PATCH 07/14] FIX: Memory leak during Assembly Adam Kwolek
2011-09-21  2:23   ` NeilBrown
2011-09-16 11:54 ` [PATCH 08/14] Check if reshape can be restarted Adam Kwolek
2011-09-21  2:27   ` NeilBrown
2011-09-21  7:45     ` Kwolek, Adam
2011-09-16 11:54 ` [PATCH 09/14] Move restore backup code to function Adam Kwolek
2011-09-21  2:28   ` NeilBrown
2011-09-16 11:55 ` [PATCH 10/14] Perform restore backup for reshape continuation Adam Kwolek
2011-09-21  2:29   ` NeilBrown
2011-09-21  7:35     ` Kwolek, Adam
2011-09-16 11:55 ` [PATCH 11/14] Add possibility to restart reshape for native metadata Adam Kwolek
2011-09-16 11:55 ` [PATCH 12/14] Early reshape backup verification Adam Kwolek
2011-09-21  2:31   ` NeilBrown
2011-09-21  7:33     ` Kwolek, Adam
2011-09-16 11:55 ` [PATCH 13/14] Check if md allows to control reshape Adam Kwolek
2011-09-21  2:33   ` NeilBrown
2011-09-21  7:31     ` Kwolek, Adam
2011-09-21  7:51       ` NeilBrown
2011-09-16 11:55 ` [PATCH 14/14] Manual update for --continue option Adam Kwolek

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=20110921122207.0f3e65b3@notabene.brown \
    --to=neilb@suse.de \
    --cc=adam.kwolek@intel.com \
    --cc=ed.ciechanowski@intel.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=marcin.labun@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).