Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: [PATCH 19/31] Prepare and free fdlist in functions

Posted on 2010-11-09 18:01:18 by adam.kwolek

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>
---

mdadm/mdadm/Grow.c | 135 +++++++++++++++++++++++++++++++++++++++------------
mdadm/mdadm/mdadm.h | 11 ++++
2 files changed, 114 insertions(+), 32 deletions(-)

diff --git a/mdadm/mdadm/Grow.c b/mdadm/mdadm/Grow.c index d97480a..93f091a 100644
--- a/mdadm/mdadm/Grow.c
+++ b/mdadm/mdadm/Grow.c
@@ -699,6 +699,102 @@ static void revert_container_raid_disks(struct supertype *st, int fd, char *cont
free_mdstat(ent);
}

+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) @@ -1435,38 +1531,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/mdadm/mdadm.h b/mdadm/mdadm/mdadm.h index d967057..3b5553a 100644
--- a/mdadm/mdadm/mdadm.h
+++ b/mdadm/mdadm/mdadm.h
@@ -450,6 +450,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,

--
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

Report this message