2
2
* mdadm - manage Linux "md" devices aka RAID arrays.
4
* Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
4
* Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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
21
21
* Author: Neil Brown
22
* Email: <neilb@cse.unsw.edu.au>
24
* School of Computer Science and Engineering
25
* The University of New South Wales
22
* Email: <neilb@suse.de>
29
24
* Added by Dale Stephenson
30
25
* steph@snapserver.com
37
int Kill(char *dev, int force, int quiet)
32
int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl)
40
35
* Nothing fancy about Kill. It just zeroes out a superblock
41
36
* Definitely not safe.
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.
47
fd = open(dev, O_RDWR|O_EXCL);
47
fd = open(dev, O_RDWR|(noexcl ? 0 : O_EXCL));
50
50
fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n",
58
58
fprintf(stderr, Name ": Unrecognised md component device - %s\n", dev);
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)) {
72
70
fprintf(stderr, Name ": Could not zero superblock on %s\n",
83
int Kill_subarray(char *dev, char *subarray, int quiet)
85
/* Delete a subarray out of a container, the subarry must be
86
* inactive. The subarray string must be a subarray index
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
94
struct supertype supertype, *st = &supertype;
97
memset(st, 0, sizeof(*st));
99
if (snprintf(st->subarray, sizeof(st->subarray), "%s", subarray) >=
100
(int)sizeof(st->subarray)) {
103
Name ": Input overflow for subarray '%s' > %zu bytes\n",
104
subarray, sizeof(st->subarray) - 1);
108
fd = open_subarray(dev, st, quiet);
112
if (!st->ss->kill_subarray) {
115
Name ": Operation not supported for %s metadata\n",
120
if (is_subarray_active(subarray, st->devname)) {
123
Name ": Subarray-%s still active, aborting\n",
128
if (mdmon_running(st->devnum))
129
st->update_tail = &st->updates;
131
/* ok we've found our victim, drop the axe */
132
rv = st->ss->kill_subarray(st);
136
Name ": Failed to delete subarray-%s from %s\n",
141
/* FIXME these routines do not report success/failure */
143
flush_metadata_updates(st);
145
st->ss->sync_metadata(st);
149
Name ": Deleted subarray-%s from %s, UUIDs may have changed\n",
155
st->ss->free_super(st);