Get rid of disklabel faking/processing.
[dragonfly.git] / sys / dev / raid / vinum / vinumioctl.c
blob92b09dc8159c1322264899a18bdd7c3ca7059e4e
1 /*
2 * XXX replace all the checks on object validity with
3 * calls to valid<object>
4 */
5 /*-
6 * Copyright (c) 1997, 1998, 1999
7 * Nan Yang Computer Services Limited. All rights reserved.
9 * Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
11 * Written by Greg Lehey
13 * This software is distributed under the so-called ``Berkeley
14 * License'':
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by Nan Yang Computer
27 * Services Limited.
28 * 4. Neither the name of the Company nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * This software is provided ``as is'', and any express or implied
33 * warranties, including, but not limited to, the implied warranties of
34 * merchantability and fitness for a particular purpose are disclaimed.
35 * In no event shall the company or contributors be liable for any
36 * direct, indirect, incidental, special, exemplary, or consequential
37 * damages (including, but not limited to, procurement of substitute
38 * goods or services; loss of use, data, or profits; or business
39 * interruption) however caused and on any theory of liability, whether
40 * in contract, strict liability, or tort (including negligence or
41 * otherwise) arising in any way out of the use of this software, even if
42 * advised of the possibility of such damage.
44 * $Id: vinumioctl.c,v 1.14 2000/10/27 03:07:53 grog Exp grog $
45 * $FreeBSD: src/sys/dev/vinum/vinumioctl.c,v 1.25.2.4 2002/02/03 00:44:19 grog Exp $
46 * $DragonFly: src/sys/dev/raid/vinum/vinumioctl.c,v 1.9 2007/06/07 22:58:38 corecode Exp $
49 #include "vinumhdr.h"
50 #include "request.h"
52 #ifdef VINUMDEBUG
53 #include <sys/reboot.h>
54 #endif
56 void attachobject(struct vinum_ioctl_msg *);
57 void detachobject(struct vinum_ioctl_msg *);
58 void renameobject(struct vinum_rename_msg *);
59 void replaceobject(struct vinum_ioctl_msg *);
60 void moveobject(struct vinum_ioctl_msg *);
62 jmp_buf command_fail; /* return on a failed command */
64 /* ioctl routine */
65 int
66 vinumioctl(struct dev_ioctl_args *ap)
68 cdev_t dev = ap->a_head.a_dev;
69 u_long cmd = ap->a_cmd;
70 caddr_t data = ap->a_data;
71 int error = 0;
72 unsigned int index; /* for transferring config info */
73 unsigned int sdno; /* for transferring config info */
74 int fe; /* free list element number */
75 struct _ioctl_reply *ioctl_reply = (struct _ioctl_reply *) data; /* struct to return */
77 /* First, decide what we're looking at */
78 switch (DEVTYPE(dev)) {
79 case VINUM_SUPERDEV_TYPE: /* ordinary super device */
80 ioctl_reply = (struct _ioctl_reply *) data; /* save the address to reply to */
81 switch (cmd) {
82 #ifdef VINUMDEBUG
83 case VINUM_DEBUG:
84 if (((struct debuginfo *) data)->changeit) /* change debug settings */
85 debug = (((struct debuginfo *) data)->param);
86 else {
87 if (debug & DEBUG_REMOTEGDB)
88 boothowto |= RB_GDB; /* serial debug line */
89 else
90 boothowto &= ~RB_GDB; /* local ddb */
91 Debugger("vinum debug");
93 ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */
94 ioctl_reply->error = 0;
95 return 0;
96 #endif
98 case VINUM_CREATE: /* create a vinum object */
99 error = lock_config(); /* get the config for us alone */
100 if (error) /* can't do it, */
101 return error; /* give up */
102 error = setjmp(command_fail); /* come back here on error */
103 if (error == 0) /* first time, */
104 ioctl_reply->error = parse_user_config((char *) data, /* update the config */
105 &keyword_set);
106 else if (ioctl_reply->error == 0) { /* longjmp, but no error status */
107 ioctl_reply->error = EINVAL; /* note that something's up */
108 ioctl_reply->msg[0] = '\0'; /* no message? */
110 unlock_config();
111 return 0; /* must be 0 to return the real error info */
113 case VINUM_GETCONFIG: /* get the configuration information */
114 bcopy(&vinum_conf, data, sizeof(vinum_conf));
115 return 0;
117 /* start configuring the subsystem */
118 case VINUM_STARTCONFIG:
119 return start_config(*(int *) data); /* just lock it. Parameter is 'force' */
122 * Move the individual parts of the config to user space.
124 * Specify the index of the object in the first word of data,
125 * and return the object there
127 case VINUM_DRIVECONFIG:
128 index = *(int *) data; /* get the index */
129 if (index >= (unsigned) vinum_conf.drives_allocated) /* can't do it */
130 return ENXIO; /* bang */
131 bcopy(&DRIVE[index], data, sizeof(struct drive)); /* copy the config item out */
132 return 0;
134 case VINUM_SDCONFIG:
135 index = *(int *) data; /* get the index */
136 if (index >= (unsigned) vinum_conf.subdisks_allocated) /* can't do it */
137 return ENXIO; /* bang */
138 bcopy(&SD[index], data, sizeof(struct sd)); /* copy the config item out */
139 return 0;
141 case VINUM_PLEXCONFIG:
142 index = *(int *) data; /* get the index */
143 if (index >= (unsigned) vinum_conf.plexes_allocated) /* can't do it */
144 return ENXIO; /* bang */
145 bcopy(&PLEX[index], data, sizeof(struct plex)); /* copy the config item out */
146 return 0;
148 case VINUM_VOLCONFIG:
149 index = *(int *) data; /* get the index */
150 if (index >= (unsigned) vinum_conf.volumes_allocated) /* can't do it */
151 return ENXIO; /* bang */
152 bcopy(&VOL[index], data, sizeof(struct volume)); /* copy the config item out */
153 return 0;
155 case VINUM_PLEXSDCONFIG:
156 index = *(int *) data; /* get the plex index */
157 sdno = ((int *) data)[1]; /* and the sd index */
158 if ((index >= (unsigned) vinum_conf.plexes_allocated) /* plex doesn't exist */
159 ||(sdno >= PLEX[index].subdisks)) /* or it doesn't have this many subdisks */
160 return ENXIO; /* bang */
161 bcopy(&SD[PLEX[index].sdnos[sdno]], /* copy the config item out */
162 data,
163 sizeof(struct sd));
164 return 0;
167 * We get called in two places: one from the
168 * userland config routines, which call us
169 * to complete the config and save it. This
170 * call supplies the value 0 as a parameter.
172 * The other place is from the user "saveconfig"
173 * routine, which can only work if we're *not*
174 * configuring. In this case, supply parameter 1.
176 case VINUM_SAVECONFIG:
177 if (VFLAGS & VF_CONFIGURING) { /* must be us, the others are asleep */
178 if (*(int *) data == 0) /* finish config */
179 finish_config(1); /* finish the configuration and update it */
180 else
181 return EBUSY; /* can't do it now */
183 save_config(); /* save configuration to disk */
184 return 0;
186 case VINUM_RELEASECONFIG: /* release the config */
187 if (VFLAGS & VF_CONFIGURING) { /* must be us, the others are asleep */
188 finish_config(0); /* finish the configuration, don't change it */
189 save_config(); /* save configuration to disk */
190 } else
191 error = EINVAL; /* release what config? */
192 return error;
194 case VINUM_INIT:
195 ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */
196 ioctl_reply->error = 0;
197 return 0;
199 case VINUM_RESETCONFIG:
200 if (vinum_inactive(0)) { /* if the volumes are not active */
202 * Note the open count. We may be called from v, so we'll be open.
203 * Keep the count so we don't underflow
205 free_vinum(1); /* clean up everything */
206 log(LOG_NOTICE, "vinum: CONFIGURATION OBLITERATED\n");
207 ioctl_reply = (struct _ioctl_reply *) data; /* reinstate the address to reply to */
208 ioctl_reply->error = 0;
209 return 0;
211 return EBUSY;
213 case VINUM_SETSTATE:
214 setstate((struct vinum_ioctl_msg *) data); /* set an object state */
215 return 0;
218 * Set state by force, without changing
219 * anything else.
221 case VINUM_SETSTATE_FORCE:
222 setstate_by_force((struct vinum_ioctl_msg *) data); /* set an object state */
223 return 0;
225 #ifdef VINUMDEBUG
226 case VINUM_MEMINFO:
227 vinum_meminfo(data);
228 return 0;
230 case VINUM_MALLOCINFO:
231 return vinum_mallocinfo(data);
233 case VINUM_RQINFO:
234 return vinum_rqinfo(data);
235 #endif
237 case VINUM_LABEL: /* label a volume */
238 ioctl_reply->error = write_volume_label(*(int *) data); /* index of the volume to label */
239 ioctl_reply->msg[0] = '\0'; /* no message */
240 return 0;
242 case VINUM_REMOVE:
243 remove((struct vinum_ioctl_msg *) data); /* remove an object */
244 return 0;
246 case VINUM_GETFREELIST: /* get a drive free list element */
247 index = *(int *) data; /* get the drive index */
248 fe = ((int *) data)[1]; /* and the free list element */
249 if ((index >= (unsigned) vinum_conf.drives_allocated) /* plex doesn't exist */
250 ||(DRIVE[index].state == drive_unallocated))
251 return ENODEV;
252 if (fe >= DRIVE[index].freelist_entries) /* no such entry */
253 return ENOENT;
254 bcopy(&DRIVE[index].freelist[fe],
255 data,
256 sizeof(struct drive_freelist));
257 return 0;
259 case VINUM_RESETSTATS:
260 resetstats((struct vinum_ioctl_msg *) data); /* reset object stats */
261 return 0;
263 /* attach an object to a superordinate object */
264 case VINUM_ATTACH:
265 attachobject((struct vinum_ioctl_msg *) data);
266 return 0;
268 /* detach an object from a superordinate object */
269 case VINUM_DETACH:
270 detachobject((struct vinum_ioctl_msg *) data);
271 return 0;
273 /* rename an object */
274 case VINUM_RENAME:
275 renameobject((struct vinum_rename_msg *) data);
276 return 0;
278 /* replace an object */
279 case VINUM_REPLACE:
280 replaceobject((struct vinum_ioctl_msg *) data);
281 return 0;
283 case VINUM_DAEMON:
284 vinum_daemon(); /* perform the daemon */
285 return 0;
287 case VINUM_FINDDAEMON: /* check for presence of daemon */
288 return vinum_finddaemon();
289 return 0;
291 case VINUM_SETDAEMON: /* set daemon flags */
292 return vinum_setdaemonopts(*(int *) data);
294 case VINUM_GETDAEMON: /* get daemon flags */
295 *(int *) data = daemon_options;
296 return 0;
298 case VINUM_PARITYOP: /* check/rebuild RAID-4/5 parity */
299 parityops((struct vinum_ioctl_msg *) data);
300 return 0;
302 /* move an object */
303 case VINUM_MOVE:
304 moveobject((struct vinum_ioctl_msg *) data);
305 return 0;
306 default:
307 /* FALLTHROUGH */
308 break;
311 case VINUM_DRIVE_TYPE:
312 case VINUM_SD_TYPE:
313 case VINUM_RAWSD_TYPE:
314 case VINUM_RAWPLEX_TYPE:
315 case VINUM_PLEX_TYPE:
316 case VINUM_VOLUME_TYPE:
317 default:
318 log(LOG_WARNING,
319 "vinumioctl: invalid ioctl from process %d (%s): %lx\n",
320 curproc->p_pid,
321 curproc->p_comm,
322 cmd);
323 return EINVAL;
325 return 0; /* XXX */
329 * The following four functions check the supplied
330 * object index and return a pointer to the object
331 * if it exists. Otherwise they longjump out via
332 * throw_rude_remark.
334 struct drive *
335 validdrive(int driveno, struct _ioctl_reply *reply)
337 if ((driveno < vinum_conf.drives_allocated)
338 && (DRIVE[driveno].state > drive_referenced))
339 return &DRIVE[driveno];
340 strcpy(reply->msg, "No such drive");
341 reply->error = ENOENT;
342 return NULL;
345 struct sd *
346 validsd(int sdno, struct _ioctl_reply *reply)
348 if ((sdno < vinum_conf.subdisks_allocated)
349 && (SD[sdno].state > sd_referenced))
350 return &SD[sdno];
351 strcpy(reply->msg, "No such subdisk");
352 reply->error = ENOENT;
353 return NULL;
356 struct plex *
357 validplex(int plexno, struct _ioctl_reply *reply)
359 if ((plexno < vinum_conf.plexes_allocated)
360 && (PLEX[plexno].state > plex_referenced))
361 return &PLEX[plexno];
362 strcpy(reply->msg, "No such plex");
363 reply->error = ENOENT;
364 return NULL;
367 struct volume *
368 validvol(int volno, struct _ioctl_reply *reply)
370 if ((volno < vinum_conf.volumes_allocated)
371 && (VOL[volno].state > volume_uninit))
372 return &VOL[volno];
373 strcpy(reply->msg, "No such volume");
374 reply->error = ENOENT;
375 return NULL;
378 /* reset an object's stats */
379 void
380 resetstats(struct vinum_ioctl_msg *msg)
382 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
384 switch (msg->type) {
385 case drive_object:
386 if (msg->index < vinum_conf.drives_allocated) {
387 struct drive *drive = &DRIVE[msg->index];
388 if (drive->state > drive_referenced) {
389 drive->reads = 0; /* number of reads on this drive */
390 drive->writes = 0; /* number of writes on this drive */
391 drive->bytes_read = 0; /* number of bytes read */
392 drive->bytes_written = 0; /* number of bytes written */
393 reply->error = 0;
394 return;
396 reply->error = EINVAL;
397 return;
399 case sd_object:
400 if (msg->index < vinum_conf.subdisks_allocated) {
401 struct sd *sd = &SD[msg->index];
402 if (sd->state > sd_referenced) {
403 sd->reads = 0; /* number of reads on this subdisk */
404 sd->writes = 0; /* number of writes on this subdisk */
405 sd->bytes_read = 0; /* number of bytes read */
406 sd->bytes_written = 0; /* number of bytes written */
407 reply->error = 0;
408 return;
410 reply->error = EINVAL;
411 return;
413 break;
415 case plex_object:
416 if (msg->index < vinum_conf.plexes_allocated) {
417 struct plex *plex = &PLEX[msg->index];
418 if (plex->state > plex_referenced) {
419 plex->reads = 0;
420 plex->writes = 0; /* number of writes on this plex */
421 plex->bytes_read = 0; /* number of bytes read */
422 plex->bytes_written = 0; /* number of bytes written */
423 plex->recovered_reads = 0; /* number of recovered read operations */
424 plex->degraded_writes = 0; /* number of degraded writes */
425 plex->parityless_writes = 0; /* number of parityless writes */
426 plex->multiblock = 0; /* requests that needed more than one block */
427 plex->multistripe = 0; /* requests that needed more than one stripe */
428 reply->error = 0;
429 return;
431 reply->error = EINVAL;
432 return;
434 break;
436 case volume_object:
437 if (msg->index < vinum_conf.volumes_allocated) {
438 struct volume *vol = &VOL[msg->index];
439 if (vol->state > volume_uninit) {
440 vol->bytes_read = 0; /* number of bytes read */
441 vol->bytes_written = 0; /* number of bytes written */
442 vol->reads = 0; /* number of reads on this volume */
443 vol->writes = 0; /* number of writes on this volume */
444 vol->recovered_reads = 0; /* reads recovered from another plex */
445 reply->error = 0;
446 return;
448 reply->error = EINVAL;
449 return;
451 case invalid_object: /* can't get this */
452 reply->error = EINVAL;
453 return;
457 /* attach an object to a superior object */
458 void
459 attachobject(struct vinum_ioctl_msg *msg)
461 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
462 int sdno;
463 struct sd *sd;
464 struct plex *plex;
465 struct volume *vol;
467 switch (msg->type) {
468 case drive_object: /* you can't attach a drive to anything */
469 case volume_object: /* nor a volume */
470 case invalid_object: /* "this can't happen" */
471 reply->error = EINVAL;
472 reply->msg[0] = '\0'; /* vinum(8) doesn't do this */
473 return;
475 case sd_object:
476 sd = validsd(msg->index, reply);
477 if (sd == NULL) /* not a valid subdisk */
478 return;
479 plex = validplex(msg->otherobject, reply);
480 if (plex) {
482 * We should be more intelligent about this.
483 * We should be able to reattach a dead
484 * subdisk, but if we want to increase the total
485 * number of subdisks, we have a lot of reshuffling
486 * to do. XXX
488 if ((plex->organization != plex_concat) /* can't attach to striped and RAID-4/5 */
489 &&(!msg->force)) { /* without using force */
490 reply->error = EINVAL; /* no message, the user should check */
491 strcpy(reply->msg, "Can't attach to this plex organization");
492 return;
494 if (sd->plexno >= 0) { /* already belong to a plex */
495 reply->error = EBUSY; /* no message, the user should check */
496 reply->msg[0] = '\0';
497 return;
499 sd->plexoffset = msg->offset; /* this is where we want it */
500 set_sd_state(sd->sdno, sd_stale, setstate_force); /* make sure it's stale */
501 give_sd_to_plex(plex->plexno, sd->sdno); /* and give it to the plex */
502 update_sd_config(sd->sdno, 0);
503 save_config();
505 if (sd->state == sd_reviving)
506 reply->error = EAGAIN; /* need to revive it */
507 else
508 reply->error = 0;
509 break;
511 case plex_object:
512 plex = validplex(msg->index, reply); /* get plex */
513 if (plex == NULL)
514 return;
515 vol = validvol(msg->otherobject, reply); /* and volume information */
516 if (vol) {
517 if ((vol->plexes == MAXPLEX) /* we have too many already */
518 ||(plex->volno >= 0)) { /* or the plex has an owner */
519 reply->error = EINVAL; /* no message, the user should check */
520 reply->msg[0] = '\0';
521 return;
523 for (sdno = 0; sdno < plex->subdisks; sdno++) {
524 sd = &SD[plex->sdnos[sdno]];
526 if (sd->state > sd_down) /* real subdisk, vaguely accessible */
527 set_sd_state(plex->sdnos[sdno], sd_stale, setstate_force); /* make it stale */
529 set_plex_state(plex->plexno, plex_up, setstate_none); /* update plex state */
530 give_plex_to_volume(msg->otherobject, msg->index); /* and give it to the volume */
531 update_plex_config(plex->plexno, 0);
532 save_config();
537 /* detach an object from a superior object */
538 void
539 detachobject(struct vinum_ioctl_msg *msg)
541 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
542 struct sd *sd;
543 struct plex *plex;
544 struct volume *vol;
545 int sdno;
546 int plexno;
548 switch (msg->type) {
549 case drive_object: /* you can't detach a drive from anything */
550 case volume_object: /* nor a volume */
551 case invalid_object: /* "this can't happen" */
552 reply->error = EINVAL;
553 reply->msg[0] = '\0'; /* vinum(8) doesn't do this */
554 return;
556 case sd_object:
557 sd = validsd(msg->index, reply);
558 if (sd == NULL)
559 return;
560 if (sd->plexno < 0) { /* doesn't belong to a plex */
561 reply->error = ENOENT;
562 strcpy(reply->msg, "Subdisk is not attached");
563 return;
564 } else { /* valid plex number */
565 plex = &PLEX[sd->plexno];
566 if ((!msg->force) /* don't force things */
567 &&((plex->state == plex_up) /* and the plex is up */
568 ||((plex->state == plex_flaky) && sd->state == sd_up))) { /* or flaky with this sd up */
569 reply->error = EBUSY; /* we need this sd */
570 reply->msg[0] = '\0';
571 return;
573 sd->plexno = -1; /* anonymous sd */
574 if (plex->subdisks == 1) { /* this was the only subdisk */
575 Free(plex->sdnos); /* free the subdisk array */
576 plex->sdnos = NULL; /* and note the fact */
577 plex->subdisks_allocated = 0; /* no subdisk space */
578 } else {
579 for (sdno = 0; sdno < plex->subdisks; sdno++) {
580 if (plex->sdnos[sdno] == msg->index) /* found our subdisk */
581 break;
583 if (sdno < (plex->subdisks - 1)) /* not the last one, compact */
584 bcopy(&plex->sdnos[sdno + 1],
585 &plex->sdnos[sdno],
586 (plex->subdisks - 1 - sdno) * sizeof(int));
588 plex->subdisks--;
589 if (!bcmp(plex->name, sd->name, strlen(plex->name) + 1))
590 /* this subdisk is named after the plex */
592 bcopy(sd->name,
593 &sd->name[3],
594 min(strlen(sd->name) + 1, MAXSDNAME - 3));
595 bcopy("ex-", sd->name, 3);
596 sd->name[MAXSDNAME - 1] = '\0';
598 update_plex_config(plex->plexno, 0);
599 if (isstriped(plex)) /* we've just mutilated our plex, */
600 set_plex_state(plex->plexno,
601 plex_down,
602 setstate_force | setstate_configuring);
603 save_config();
604 reply->error = 0;
606 return;
608 case plex_object:
609 plex = validplex(msg->index, reply); /* get plex */
610 if (plex == NULL)
611 return;
612 if (plex->volno >= 0) {
613 int volno = plex->volno;
615 vol = &VOL[volno];
616 if ((!msg->force) /* don't force things */
617 &&((vol->state == volume_up) /* and the volume is up */
618 &&(vol->plexes == 1))) { /* and this is the last plex */
620 * XXX As elsewhere, check whether we will lose
621 * mapping by removing this plex
623 reply->error = EBUSY; /* we need this plex */
624 reply->msg[0] = '\0';
625 return;
627 plex->volno = -1; /* anonymous plex */
628 for (plexno = 0; plexno < vol->plexes; plexno++) {
629 if (vol->plex[plexno] == msg->index) /* found our plex */
630 break;
632 if (plexno < (vol->plexes - 1)) /* not the last one, compact */
633 bcopy(&vol->plex[plexno + 1],
634 &vol->plex[plexno],
635 (vol->plexes - 1 - plexno) * sizeof(int));
636 vol->plexes--;
637 vol->last_plex_read = 0; /* don't go beyond the end */
638 if (!bcmp(vol->name, plex->name, strlen(vol->name) + 1))
639 /* this plex is named after the volume */
641 /* First, check if the subdisks are the same */
642 if (msg->recurse) {
643 int sdno;
645 for (sdno = 0; sdno < plex->subdisks; sdno++) {
646 struct sd *sd = &SD[plex->sdnos[sdno]];
648 if (!bcmp(plex->name, sd->name, strlen(plex->name) + 1))
649 /* subdisk is named after the plex */
651 bcopy(sd->name,
652 &sd->name[3],
653 min(strlen(sd->name) + 1, MAXSDNAME - 3));
654 bcopy("ex-", sd->name, 3);
655 sd->name[MAXSDNAME - 1] = '\0';
659 bcopy(plex->name,
660 &plex->name[3],
661 min(strlen(plex->name) + 1, MAXPLEXNAME - 3));
662 bcopy("ex-", plex->name, 3);
663 plex->name[MAXPLEXNAME - 1] = '\0';
665 update_volume_config(volno, 0);
666 save_config();
667 reply->error = 0;
668 } else {
669 reply->error = ENOENT;
670 strcpy(reply->msg, "Plex is not attached");
675 void
676 renameobject(struct vinum_rename_msg *msg)
678 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
679 struct drive *drive;
680 struct sd *sd;
681 struct plex *plex;
682 struct volume *vol;
684 switch (msg->type) {
685 case drive_object: /* you can't attach a drive to anything */
686 if (find_drive(msg->newname, 0) >= 0) { /* we have that name already, */
687 reply->error = EEXIST;
688 reply->msg[0] = '\0';
689 return;
691 drive = validdrive(msg->index, reply);
692 if (drive) {
693 bcopy(msg->newname, drive->label.name, MAXDRIVENAME);
694 save_config();
695 reply->error = 0;
697 return;
699 case sd_object: /* you can't attach a subdisk to anything */
700 if (find_subdisk(msg->newname, 0) >= 0) { /* we have that name already, */
701 reply->error = EEXIST;
702 reply->msg[0] = '\0';
703 return;
705 sd = validsd(msg->index, reply);
706 if (sd) {
707 bcopy(msg->newname, sd->name, MAXSDNAME);
708 update_sd_config(sd->sdno, 0);
709 save_config();
710 reply->error = 0;
712 return;
714 case plex_object: /* you can't attach a plex to anything */
715 if (find_plex(msg->newname, 0) >= 0) { /* we have that name already, */
716 reply->error = EEXIST;
717 reply->msg[0] = '\0';
718 return;
720 plex = validplex(msg->index, reply);
721 if (plex) {
722 bcopy(msg->newname, plex->name, MAXPLEXNAME);
723 update_plex_config(plex->plexno, 0);
724 save_config();
725 reply->error = 0;
727 return;
729 case volume_object: /* you can't attach a volume to anything */
730 if (find_volume(msg->newname, 0) >= 0) { /* we have that name already, */
731 reply->error = EEXIST;
732 reply->msg[0] = '\0';
733 return;
735 vol = validvol(msg->index, reply);
736 if (vol) {
737 bcopy(msg->newname, vol->name, MAXVOLNAME);
738 update_volume_config(msg->index, 0);
739 save_config();
740 reply->error = 0;
742 return;
744 case invalid_object:
745 reply->error = EINVAL;
746 reply->msg[0] = '\0';
751 * Replace one object with another.
752 * Currently only for drives.
753 * message->index is the drive number of the old drive
754 * message->otherobject is the drive number of the new drive
756 void
757 replaceobject(struct vinum_ioctl_msg *msg)
759 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
761 reply->error = ENODEV; /* until I know how to do this */
762 strcpy(reply->msg, "replace not implemented yet");
763 /* save_config (); */
766 void
767 moveobject(struct vinum_ioctl_msg *msg)
769 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
770 struct drive *drive;
771 struct sd *sd;
773 /* Check that our objects are valid (i.e. they exist) */
774 drive = validdrive(msg->index, (struct _ioctl_reply *) msg);
775 if (drive == NULL)
776 return;
777 sd = validsd(msg->otherobject, (struct _ioctl_reply *) msg);
778 if (sd == NULL)
779 return;
780 if (sd->driveno == msg->index) /* sd already belongs to drive */
781 return;
783 if (sd->state > sd_stale)
784 set_sd_state(sd->sdno, sd_stale, setstate_force); /* make the subdisk stale */
785 else
786 sd->state = sd_empty;
787 if (sd->plexno >= 0) /* part of a plex, */
788 update_plex_state(sd->plexno); /* update its state */
790 /* Return the space on the old drive */
791 if ((sd->driveno >= 0) /* we have a drive, */
792 &&(sd->sectors > 0)) /* and some space on it */
793 return_drive_space(sd->driveno, /* return the space */
794 sd->driveoffset,
795 sd->sectors);
797 /* Reassign the old subdisk */
798 sd->driveno = msg->index;
799 sd->driveoffset = -1; /* let the drive decide where to put us */
800 give_sd_to_drive(sd->sdno);
801 reply->error = 0;
804 /* Local Variables: */
805 /* fill-column: 50 */
806 /* End: */