From: Neil Brown <neilb@suse.de>
To: Adam Kwolek <adam.kwolek@intel.com>
Cc: linux-raid@vger.kernel.org, dan.j.williams@intel.com,
ed.ciechanowski@intel.com
Subject: Re: [PATCH 33/53] Prepare and free fdlist in functions
Date: Tue, 30 Nov 2010 13:28:33 +1100 [thread overview]
Message-ID: <20101130132833.0c063c80@notabene.brown> (raw)
In-Reply-To: <20101126080808.5221.94530.stgit@gklab-170-024.igk.intel.com>
On Fri, 26 Nov 2010 09:08:08 +0100 Adam Kwolek <adam.kwolek@intel.com> wrote:
> fd handles table creation is put in to function for code reuse.
>
> In manage_reshape(), child_grow() function from Grow.c will be reused.
> To prepare parameters for this function, code from Grow.c can be reused also.
>
> Signed-off-by: Adam Kwolek <adam.kwolek@intel.com>
I've applied this, though I changed the "_in" parameters to simple
pass-by-value parameters, and removed all the NULL checks which are fairly
pointless - if those values are zero it would be wrong to continue, you
should just abort, which is what will now happen anyway.
NeilBrown
> ---
>
> Grow.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++---------------
> mdadm.h | 11 +++++
> 2 files changed, 115 insertions(+), 32 deletions(-)
>
> diff --git a/Grow.c b/Grow.c
> index 347f07b..8cba82b 100644
> --- a/Grow.c
> +++ b/Grow.c
> @@ -832,6 +832,103 @@ int remove_disks_on_raid10_to_raid0_takeover(struct supertype *st,
> return 0;
> }
>
> +void reshape_free_fdlist(int **fdlist_in,
> + unsigned long long **offsets_in,
> + int size)
> +{
> + int i;
> + int *fdlist;
> + unsigned long long *offsets;
> + if ((offsets_in == NULL) || (offsets_in == NULL)) {
> + dprintf(Name " Error: Parameters verification error #1.\n");
> + return;
> + }
> +
> + fdlist = *fdlist_in;
> + offsets = *offsets_in;
> + if ((fdlist == NULL) || (offsets == NULL)) {
> + dprintf(Name " Error: Parameters verification error #2.\n");
> + return;
> + }
> +
> + for (i = 0; i < size; i++) {
> + if (fdlist[i] > 0)
> + close(fdlist[i]);
> + }
> +
> + free(fdlist);
> + free(offsets);
> + *fdlist_in = NULL;
> + *offsets_in = NULL;
> +}
> +
> +int reshape_prepare_fdlist(char *devname,
> + struct mdinfo *sra,
> + int raid_disks,
> + int nrdisks,
> + unsigned long blocks,
> + char *backup_file,
> + int **fdlist_in,
> + unsigned long long **offsets_in)
> +{
> + int d = 0;
> + int *fdlist;
> + unsigned long long *offsets;
> + struct mdinfo *sd;
> +
> + if ((devname == NULL) || (sra == NULL) ||
> + (fdlist_in == NULL) || (offsets_in == NULL)) {
> + dprintf(Name " Error: Parameters verification error #1.\n");
> + d = -1;
> + goto release;
> + }
> +
> + fdlist = *fdlist_in;
> + offsets = *offsets_in;
> +
> + if ((fdlist == NULL) || (offsets == NULL)) {
> + dprintf(Name " Error: Parameters verification error #2.\n");
> + d = -1;
> + goto release;
> + }
> +
> + for (d = 0; d <= nrdisks; d++)
> + fdlist[d] = -1;
> + d = raid_disks;
> + for (sd = sra->devs; sd; sd = sd->next) {
> + if (sd->disk.state & (1<<MD_DISK_FAULTY))
> + continue;
> + if (sd->disk.state & (1<<MD_DISK_SYNC)) {
> + char *dn = map_dev(sd->disk.major,
> + sd->disk.minor, 1);
> + fdlist[sd->disk.raid_disk]
> + = dev_open(dn, O_RDONLY);
> + offsets[sd->disk.raid_disk] = sd->data_offset*512;
> + if (fdlist[sd->disk.raid_disk] < 0) {
> + fprintf(stderr, Name ": %s: cannot open component %s\n",
> + devname, dn ? dn : "-unknown-");
> + d = -1;
> + goto release;
> + }
> + } else if (backup_file == NULL) {
> + /* spare */
> + char *dn = map_dev(sd->disk.major,
> + sd->disk.minor, 1);
> + fdlist[d] = dev_open(dn, O_RDWR);
> + offsets[d] = (sd->data_offset + sra->component_size - blocks - 8)*512;
> + if (fdlist[d] < 0) {
> + fprintf(stderr, Name ": %s: cannot open component %s\n",
> + devname, dn ? dn : "-unknown-");
> + d = -1;
> + goto release;
> + }
> + d++;
> + }
> + }
> +release:
> + return d;
> +}
> +
> int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
> long long size,
> int level, char *layout_str, int chunksize, int raid_disks)
> @@ -1547,38 +1644,13 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
> rv = 1;
> break;
> }
> - for (d=0; d <= nrdisks; d++)
> - fdlist[d] = -1;
> - d = array.raid_disks;
> - for (sd = sra->devs; sd; sd=sd->next) {
> - if (sd->disk.state & (1<<MD_DISK_FAULTY))
> - continue;
> - if (sd->disk.state & (1<<MD_DISK_SYNC)) {
> - char *dn = map_dev(sd->disk.major,
> - sd->disk.minor, 1);
> - fdlist[sd->disk.raid_disk]
> - = dev_open(dn, O_RDONLY);
> - offsets[sd->disk.raid_disk] = sd->data_offset*512;
> - if (fdlist[sd->disk.raid_disk] < 0) {
> - fprintf(stderr, Name ": %s: cannot open component %s\n",
> - devname, dn?dn:"-unknown-");
> - rv = 1;
> - goto release;
> - }
> - } else if (backup_file == NULL) {
> - /* spare */
> - char *dn = map_dev(sd->disk.major,
> - sd->disk.minor, 1);
> - fdlist[d] = dev_open(dn, O_RDWR);
> - offsets[d] = (sd->data_offset + sra->component_size - blocks - 8)*512;
> - if (fdlist[d]<0) {
> - fprintf(stderr, Name ": %s: cannot open component %s\n",
> - devname, dn?dn:"-unknown");
> - rv = 1;
> - goto release;
> - }
> - d++;
> - }
> +
> + d = reshape_prepare_fdlist(devname, sra, array.raid_disks,
> + nrdisks, blocks, backup_file,
> + &fdlist, &offsets);
> + if (d < 0) {
> + rv = 1;
> + goto release;
> }
> if (backup_file == NULL) {
> if (st->ss->external && !st->ss->manage_reshape) {
> diff --git a/mdadm.h b/mdadm.h
> index 750afcc..698f1bf 100644
> --- a/mdadm.h
> +++ b/mdadm.h
> @@ -448,6 +448,17 @@ extern int sysfs_unique_holder(int devnum, long rdev);
> extern int sysfs_freeze_array(struct mdinfo *sra);
> extern int load_sys(char *path, char *buf);
> extern struct mdinfo *sysfs_get_unused_spares(int container_fd, int fd);
> +extern int reshape_prepare_fdlist(char *devname,
> + struct mdinfo *sra,
> + int raid_disks,
> + int nrdisks,
> + unsigned long blocks,
> + char *backup_file,
> + int **fdlist_in,
> + unsigned long long **offsets_in);
> +extern void reshape_free_fdlist(int **fdlist_in,
> + unsigned long long **offsets_in,
> + int size);
>
>
> extern int save_stripes(int *source, unsigned long long *offsets,
next prev parent reply other threads:[~2010-11-30 2:28 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-26 8:03 [PATCH 00/53] External Metadata Reshape Adam Kwolek
2010-11-26 8:03 ` [PATCH 01/53] Provide a mdstat_ent to subarray helper Adam Kwolek
2010-11-26 8:04 ` [PATCH 02/53] block monitor: freeze spare assignment for external arrays Adam Kwolek
2010-11-26 8:04 ` [PATCH 03/53] Manage: allow manual control of external raid0 readonly flag Adam Kwolek
2010-11-26 8:04 ` [PATCH 04/53] Grow: mark some functions static Adam Kwolek
2010-11-26 8:04 ` [PATCH 05/53] Assemble: fix assembly in the delta_disks > max_degraded case Adam Kwolek
2010-11-26 8:04 ` [PATCH 06/53] Grow: fix check for raid6 layout normalization Adam Kwolek
2010-11-26 8:04 ` [PATCH 07/53] Grow: add missing raid4 geometries to geo_map() Adam Kwolek
2010-11-26 8:04 ` [PATCH 08/53] fix a get_linux_version() comparison typo Adam Kwolek
2010-11-26 8:05 ` [PATCH 09/53] Create: cleanup/unify default geometry handling Adam Kwolek
2010-11-26 8:05 ` [PATCH 10/53] Initialize st->devnum and st->container_dev in super_by_fd Adam Kwolek
2010-11-26 8:05 ` [PATCH 11/53] Document the external reshape implementation Adam Kwolek
2010-11-26 8:05 ` [PATCH 12/53] External reshape (step 1): container reshape and ->reshape_super() Adam Kwolek
2010-11-26 8:05 ` [PATCH 13/53] External reshape (step 2): Freeze container Adam Kwolek
2010-11-26 8:05 ` [PATCH 14/53] FIX: Cannot exit monitor after takeover Adam Kwolek
2010-11-28 23:38 ` Neil Brown
2010-11-30 16:03 ` Kwolek, Adam
2010-11-30 22:06 ` Neil Brown
2010-11-26 8:05 ` [PATCH 15/53] FIX: Unfreeze not only container for external metadata Adam Kwolek
2010-11-28 23:48 ` Neil Brown
2010-11-30 16:03 ` Kwolek, Adam
2010-11-26 8:05 ` [PATCH 16/53] Add takeover support for external meta Adam Kwolek
2010-11-29 0:31 ` Neil Brown
2010-11-26 8:06 ` [PATCH 17/53] Disk removal support for Raid10->Raid0 takeover Adam Kwolek
2010-11-29 1:00 ` Neil Brown
2010-11-26 8:06 ` [PATCH 18/53] Treat feature as experimental Adam Kwolek
2010-11-29 1:13 ` Neil Brown
2010-11-26 8:06 ` [PATCH 19/53] imsm: Add support for general migration Adam Kwolek
2010-11-29 1:17 ` Neil Brown
2010-11-29 1:29 ` Neil Brown
2010-11-26 8:06 ` [PATCH 20/53] imsm: Add reshape_update for grow array case Adam Kwolek
2010-11-29 1:48 ` Neil Brown
2010-11-26 8:06 ` [PATCH 21/53] imsm: FIX: core dump during imsm metadata writing Adam Kwolek
2010-11-29 1:54 ` Neil Brown
2010-11-26 8:06 ` [PATCH 22/53] Send information to managemon about reshape request Adam Kwolek
2010-11-29 1:56 ` Neil Brown
2010-11-26 8:06 ` [PATCH 23/53] Process reshape initialization by managemon Adam Kwolek
2010-11-26 8:07 ` [PATCH 24/53] Add support to skip slot configuration Adam Kwolek
2010-11-26 8:07 ` [PATCH 25/53] imsm: Verify slots in meta against slot numbers set by md Adam Kwolek
2010-11-26 8:07 ` [PATCH 26/53] imsm: Cancel metadata changes on reshape start failure Adam Kwolek
2010-11-26 8:07 ` [PATCH 27/53] imsm: Do not accept messages sent by mdadm Adam Kwolek
2010-11-26 8:07 ` [PATCH 28/53] imsm: Do not indicate resync during reshape Adam Kwolek
2010-11-26 8:07 ` [PATCH 29/53] Add spares to raid0 array using takeover Adam Kwolek
2010-11-30 2:00 ` Neil Brown
2010-11-26 8:07 ` [PATCH 30/53] imsm: FIX: Fill sys_name field in getinfo_super() Adam Kwolek
2010-11-30 2:06 ` Neil Brown
2010-11-26 8:07 ` [PATCH 31/53] imsm: FIX: Fill delta_disks " Adam Kwolek
2010-11-30 2:07 ` Neil Brown
2010-11-26 8:08 ` [PATCH 32/53] imsm: FIX: spare list contains one device several times Adam Kwolek
2010-11-30 2:17 ` Neil Brown
2010-11-26 8:08 ` [PATCH 33/53] Prepare and free fdlist in functions Adam Kwolek
2010-11-30 2:28 ` Neil Brown [this message]
2010-11-26 8:08 ` [PATCH 34/53] Compute backup blocks in function Adam Kwolek
2010-11-30 2:32 ` Neil Brown
2010-11-26 8:08 ` [PATCH 35/53] Control reshape in mdadm Adam Kwolek
2010-11-30 2:37 ` Neil Brown
2010-11-26 8:08 ` [PATCH 36/53] Finalize reshape after adding disks to array Adam Kwolek
2010-11-26 8:08 ` [PATCH 37/53] mdadm: second_map enhancement for imsm_get_map() Adam Kwolek
2010-11-26 8:08 ` [PATCH 38/53] mdadm: read chunksize and layout from mdstat Adam Kwolek
2010-11-26 8:08 ` [PATCH 39/53] mdadm: Add IMSM migration record to intel_super Adam Kwolek
2010-11-26 8:09 ` [PATCH 40/53] mdadm: add backup methods to superswitch Adam Kwolek
2010-11-26 8:09 ` [PATCH 41/53] mdadm: support restore_stripes() from the given buffer Adam Kwolek
2010-11-26 8:09 ` [PATCH 42/53] mdadm: support backup operations for imsm Adam Kwolek
2010-11-26 8:09 ` [PATCH 43/53] mdadm: migration restart for external meta Adam Kwolek
2010-11-26 8:09 ` [PATCH 44/53] Add mdadm->mdmon sync_max command message Adam Kwolek
2010-11-26 8:09 ` [PATCH 45/53] mdadm: support grow operation for external meta Adam Kwolek
2010-11-26 8:09 ` [PATCH 46/53] FIX: Allow for reshape without backup file Adam Kwolek
2010-11-26 8:09 ` [PATCH 47/53] FIX: Honor !reshape state on wait_reshape() entry Adam Kwolek
2010-11-26 8:10 ` [PATCH 48/53] WORKAROUND: md reports idle state during reshape start Adam Kwolek
2010-11-26 8:10 ` [PATCH 49/53] imsm Fix: Core during rebuild on array details read Adam Kwolek
2010-11-26 8:10 ` [PATCH 50/53] Change manage_reshape() placement Adam Kwolek
2010-11-26 8:10 ` [PATCH 51/53] Migration: raid5->raid0 Adam Kwolek
2010-11-26 8:10 ` [PATCH 52/53] Migration raid0->raid5 Adam Kwolek
2010-11-26 8:10 ` [PATCH 53/53] Migration: Chunk size migration Adam Kwolek
2010-11-29 3:32 ` [PATCH 00/53] External Metadata Reshape Neil Brown
2010-11-29 4:07 ` Neil Brown
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=20101130132833.0c063c80@notabene.brown \
--to=neilb@suse.de \
--cc=adam.kwolek@intel.com \
--cc=dan.j.williams@intel.com \
--cc=ed.ciechanowski@intel.com \
--cc=linux-raid@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;
as well as URLs for NNTP newsgroup(s).