~xnox/ubuntu/quantal/mdadm/merge

« back to all changes in this revision

Viewing changes to Kill.c

  • Committer: Dmitrijs Ledkovs
  • Author(s): Surbhi Palande
  • Date: 2010-09-30 17:46:19 UTC
  • mfrom: (1.1.25 sid)
  • Revision ID: dmitrijs.ledkovs@canonical.com-20100930174619-cqsokylnluraiyr8
Tags: 3.1.4-1+8efb9d1ubuntu1
* Merge from debian unstable. (LP: #603582) 
* Remaining changes
  - Assemble.c, config.c: upgraded to the mdadm-3.1.4 version of these files
    from Debian.
  - debian/control: we need udev and util-linux in the right version. We
    also remove the build dependency from quilt and docbook-to-man as both
    are not used in Ubuntus mdadm.
  - debian/initramfs/hook: kept the Ubuntus version for handling the absence
    of active raid arrays in <initramfs>/etc/mdadm/mdadm.conf
  - debian/initramfs/script.local-top.DEBIAN, debian/mdadm-startall,
    debian/mdadm.raid.DEBIAN: removed. udev does its job now instead.
  - debian/mdadm-startall.sgml, debian/mdadm-startall.8: documentation of
    unused startall script
  - debian/mdadm.config, debian/mdadm.postinst - let udev do the handling
    instead. Resolved merge conflict by keeping Ubuntu's version.
  - debian/rules: kept debian's switch to using dh_lintian
  - debian/mdadm.links, debian/mdadm.manpages: dropped owing to the fact
    that these are not used in Ubuntu. Also dropped the build-dep on docbook
    to man)
  - debian/mdadm.postinst, debian/mdadm.config, initramfs/init-premount:
    boot-degraded enablement; maintain udev starting of RAID devices;
    init-premount hook script for the initramfs, to provide information at
    boot
  - debian/mkconf.in is the older mkconf. Kept the Ubuntus version.
  - debian/rules: Kept Ubuntus version for installing apport hooks, not
    installing un-used startall script and for adding a udev rule
    corresponding to mdadm.
  - debian/install-rc, check.d/_numbers, check.d/root_on_raid: Ubuntu partman
    installer changes
  - debian/presubj: Dropped this unused bug reporting file. Instead use
    source_mdadm.py act as an apport hook for bug handling.
  - rename debian/mdadm.vol_id.udev to debian/mdadm.mdadm-blkid.udev so that
    the rules file ends up with a more reasonable name

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * mdadm - manage Linux "md" devices aka RAID arrays.
3
3
 *
4
 
 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
 
4
 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
5
5
 *
6
6
 *
7
7
 *    This program is free software; you can redistribute it and/or modify
19
19
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
20
 *
21
21
 *    Author: Neil Brown
22
 
 *    Email: <neilb@cse.unsw.edu.au>
23
 
 *    Paper: Neil Brown
24
 
 *           School of Computer Science and Engineering
25
 
 *           The University of New South Wales
26
 
 *           Sydney, 2052
27
 
 *           Australia
 
22
 *    Email: <neilb@suse.de>
28
23
 *
29
24
 *    Added by Dale Stephenson
30
25
 *    steph@snapserver.com
34
29
#include        "md_u.h"
35
30
#include        "md_p.h"
36
31
 
37
 
int Kill(char *dev, int force, int quiet)
 
32
int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl)
38
33
{
39
34
        /*
40
35
         * Nothing fancy about Kill.  It just zeroes out a superblock
41
36
         * Definitely not safe.
 
37
         * Returns:
 
38
         *  0 - a zero superblock was successfully written out
 
39
         *  1 - failed to write the zero superblock
 
40
         *  2 - failed to open the device or find a superblock.
42
41
         */
43
42
 
44
43
        int fd, rv = 0;
45
 
        struct supertype *st;
46
44
 
47
 
        fd = open(dev, O_RDWR|O_EXCL);
 
45
        if (force)
 
46
                noexcl = 1;
 
47
        fd = open(dev, O_RDWR|(noexcl ? 0 : O_EXCL));
48
48
        if (fd < 0) {
49
49
                if (!quiet)
50
50
                        fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n",
51
51
                                dev);
52
 
                close(fd);
53
 
                return 1;
 
52
                return 2;
54
53
        }
55
 
        st = guess_super(fd);
 
54
        if (st == NULL)
 
55
                st = guess_super(fd);
56
56
        if (st == NULL) {
57
57
                if (!quiet)
58
58
                        fprintf(stderr, Name ": Unrecognised md component device - %s\n", dev);
59
59
                close(fd);
60
 
                return 1;
 
60
                return 2;
61
61
        }
62
62
        rv = st->ss->load_super(st, fd, dev);
63
63
        if (force && rv >= 2)
64
64
                rv = 0; /* ignore bad data in superblock */
65
65
        if (rv== 0 || (force && rv >= 2)) {
66
 
                mdu_array_info_t info;
67
 
                info.major_version = -1; /* zero superblock */
68
66
                st->ss->free_super(st);
69
 
                st->ss->init_super(st, &info, 0, "", NULL, NULL);
 
67
                st->ss->init_super(st, NULL, 0, "", NULL, NULL);
70
68
                if (st->ss->store_super(st, fd)) {
71
69
                        if (!quiet)
72
70
                                fprintf(stderr, Name ": Could not zero superblock on %s\n",
81
79
        close(fd);
82
80
        return rv;
83
81
}
 
82
 
 
83
int Kill_subarray(char *dev, char *subarray, int quiet)
 
84
{
 
85
        /* Delete a subarray out of a container, the subarry must be
 
86
         * inactive.  The subarray string must be a subarray index
 
87
         * number.
 
88
         *
 
89
         * 0 = successfully deleted subarray from all container members
 
90
         * 1 = failed to sync metadata to one or more devices
 
91
         * 2 = failed to find the container, subarray, or other resource
 
92
         *     issue
 
93
         */
 
94
        struct supertype supertype, *st = &supertype;
 
95
        int fd, rv = 2;
 
96
 
 
97
        memset(st, 0, sizeof(*st));
 
98
 
 
99
        if (snprintf(st->subarray, sizeof(st->subarray), "%s", subarray) >=
 
100
            (int)sizeof(st->subarray)) {
 
101
                if (!quiet)
 
102
                        fprintf(stderr,
 
103
                                Name ": Input overflow for subarray '%s' > %zu bytes\n",
 
104
                                subarray, sizeof(st->subarray) - 1);
 
105
                return 2;
 
106
        }
 
107
 
 
108
        fd = open_subarray(dev, st, quiet);
 
109
        if (fd < 0)
 
110
                return 2;
 
111
 
 
112
        if (!st->ss->kill_subarray) {
 
113
                if (!quiet)
 
114
                        fprintf(stderr,
 
115
                                Name ": Operation not supported for %s metadata\n",
 
116
                                st->ss->name);
 
117
                goto free_super;
 
118
        }
 
119
 
 
120
        if (is_subarray_active(subarray, st->devname)) {
 
121
                if (!quiet)
 
122
                        fprintf(stderr,
 
123
                                Name ": Subarray-%s still active, aborting\n",
 
124
                                subarray);
 
125
                goto free_super;
 
126
        }
 
127
 
 
128
        if (mdmon_running(st->devnum))
 
129
                st->update_tail = &st->updates;
 
130
 
 
131
        /* ok we've found our victim, drop the axe */
 
132
        rv = st->ss->kill_subarray(st);
 
133
        if (rv) {
 
134
                if (!quiet)
 
135
                        fprintf(stderr,
 
136
                                Name ": Failed to delete subarray-%s from %s\n",
 
137
                                subarray, dev);
 
138
                goto free_super;
 
139
        }
 
140
 
 
141
        /* FIXME these routines do not report success/failure */
 
142
        if (st->update_tail)
 
143
                flush_metadata_updates(st);
 
144
        else
 
145
                st->ss->sync_metadata(st);
 
146
 
 
147
        if (!quiet)
 
148
                fprintf(stderr,
 
149
                        Name ": Deleted subarray-%s from %s, UUIDs may have changed\n",
 
150
                        subarray, dev);
 
151
 
 
152
        rv = 0;
 
153
 
 
154
 free_super:
 
155
        st->ss->free_super(st);
 
156
        close(fd);
 
157
 
 
158
        return rv;
 
159
}