Turn VINUM_LABEL into a noop (fixing LINT).
[dragonfly/vkernel-mp.git] / sys / dev / raid / vinum / vinumioctl.c
blob48e980ecaaee3bff8274980ea65bdfb1d76cbb7d
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.10 2007/06/16 20:48:34 swildner 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_REMOVE:
238 remove((struct vinum_ioctl_msg *) data); /* remove an object */
239 return 0;
241 case VINUM_GETFREELIST: /* get a drive free list element */
242 index = *(int *) data; /* get the drive index */
243 fe = ((int *) data)[1]; /* and the free list element */
244 if ((index >= (unsigned) vinum_conf.drives_allocated) /* plex doesn't exist */
245 ||(DRIVE[index].state == drive_unallocated))
246 return ENODEV;
247 if (fe >= DRIVE[index].freelist_entries) /* no such entry */
248 return ENOENT;
249 bcopy(&DRIVE[index].freelist[fe],
250 data,
251 sizeof(struct drive_freelist));
252 return 0;
254 case VINUM_RESETSTATS:
255 resetstats((struct vinum_ioctl_msg *) data); /* reset object stats */
256 return 0;
258 /* attach an object to a superordinate object */
259 case VINUM_ATTACH:
260 attachobject((struct vinum_ioctl_msg *) data);
261 return 0;
263 /* detach an object from a superordinate object */
264 case VINUM_DETACH:
265 detachobject((struct vinum_ioctl_msg *) data);
266 return 0;
268 /* rename an object */
269 case VINUM_RENAME:
270 renameobject((struct vinum_rename_msg *) data);
271 return 0;
273 /* replace an object */
274 case VINUM_REPLACE:
275 replaceobject((struct vinum_ioctl_msg *) data);
276 return 0;
278 case VINUM_DAEMON:
279 vinum_daemon(); /* perform the daemon */
280 return 0;
282 case VINUM_FINDDAEMON: /* check for presence of daemon */
283 return vinum_finddaemon();
284 return 0;
286 case VINUM_SETDAEMON: /* set daemon flags */
287 return vinum_setdaemonopts(*(int *) data);
289 case VINUM_GETDAEMON: /* get daemon flags */
290 *(int *) data = daemon_options;
291 return 0;
293 case VINUM_PARITYOP: /* check/rebuild RAID-4/5 parity */
294 parityops((struct vinum_ioctl_msg *) data);
295 return 0;
297 /* move an object */
298 case VINUM_MOVE:
299 moveobject((struct vinum_ioctl_msg *) data);
300 return 0;
301 default:
302 /* FALLTHROUGH */
303 break;
306 case VINUM_LABEL:
307 case VINUM_DRIVE_TYPE:
308 case VINUM_SD_TYPE:
309 case VINUM_RAWSD_TYPE:
310 case VINUM_RAWPLEX_TYPE:
311 case VINUM_PLEX_TYPE:
312 case VINUM_VOLUME_TYPE:
313 default:
314 log(LOG_WARNING,
315 "vinumioctl: invalid ioctl from process %d (%s): %lx\n",
316 curproc->p_pid,
317 curproc->p_comm,
318 cmd);
319 return EINVAL;
321 return 0; /* XXX */
325 * The following four functions check the supplied
326 * object index and return a pointer to the object
327 * if it exists. Otherwise they longjump out via
328 * throw_rude_remark.
330 struct drive *
331 validdrive(int driveno, struct _ioctl_reply *reply)
333 if ((driveno < vinum_conf.drives_allocated)
334 && (DRIVE[driveno].state > drive_referenced))
335 return &DRIVE[driveno];
336 strcpy(reply->msg, "No such drive");
337 reply->error = ENOENT;
338 return NULL;
341 struct sd *
342 validsd(int sdno, struct _ioctl_reply *reply)
344 if ((sdno < vinum_conf.subdisks_allocated)
345 && (SD[sdno].state > sd_referenced))
346 return &SD[sdno];
347 strcpy(reply->msg, "No such subdisk");
348 reply->error = ENOENT;
349 return NULL;
352 struct plex *
353 validplex(int plexno, struct _ioctl_reply *reply)
355 if ((plexno < vinum_conf.plexes_allocated)
356 && (PLEX[plexno].state > plex_referenced))
357 return &PLEX[plexno];
358 strcpy(reply->msg, "No such plex");
359 reply->error = ENOENT;
360 return NULL;
363 struct volume *
364 validvol(int volno, struct _ioctl_reply *reply)
366 if ((volno < vinum_conf.volumes_allocated)
367 && (VOL[volno].state > volume_uninit))
368 return &VOL[volno];
369 strcpy(reply->msg, "No such volume");
370 reply->error = ENOENT;
371 return NULL;
374 /* reset an object's stats */
375 void
376 resetstats(struct vinum_ioctl_msg *msg)
378 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
380 switch (msg->type) {
381 case drive_object:
382 if (msg->index < vinum_conf.drives_allocated) {
383 struct drive *drive = &DRIVE[msg->index];
384 if (drive->state > drive_referenced) {
385 drive->reads = 0; /* number of reads on this drive */
386 drive->writes = 0; /* number of writes on this drive */
387 drive->bytes_read = 0; /* number of bytes read */
388 drive->bytes_written = 0; /* number of bytes written */
389 reply->error = 0;
390 return;
392 reply->error = EINVAL;
393 return;
395 case sd_object:
396 if (msg->index < vinum_conf.subdisks_allocated) {
397 struct sd *sd = &SD[msg->index];
398 if (sd->state > sd_referenced) {
399 sd->reads = 0; /* number of reads on this subdisk */
400 sd->writes = 0; /* number of writes on this subdisk */
401 sd->bytes_read = 0; /* number of bytes read */
402 sd->bytes_written = 0; /* number of bytes written */
403 reply->error = 0;
404 return;
406 reply->error = EINVAL;
407 return;
409 break;
411 case plex_object:
412 if (msg->index < vinum_conf.plexes_allocated) {
413 struct plex *plex = &PLEX[msg->index];
414 if (plex->state > plex_referenced) {
415 plex->reads = 0;
416 plex->writes = 0; /* number of writes on this plex */
417 plex->bytes_read = 0; /* number of bytes read */
418 plex->bytes_written = 0; /* number of bytes written */
419 plex->recovered_reads = 0; /* number of recovered read operations */
420 plex->degraded_writes = 0; /* number of degraded writes */
421 plex->parityless_writes = 0; /* number of parityless writes */
422 plex->multiblock = 0; /* requests that needed more than one block */
423 plex->multistripe = 0; /* requests that needed more than one stripe */
424 reply->error = 0;
425 return;
427 reply->error = EINVAL;
428 return;
430 break;
432 case volume_object:
433 if (msg->index < vinum_conf.volumes_allocated) {
434 struct volume *vol = &VOL[msg->index];
435 if (vol->state > volume_uninit) {
436 vol->bytes_read = 0; /* number of bytes read */
437 vol->bytes_written = 0; /* number of bytes written */
438 vol->reads = 0; /* number of reads on this volume */
439 vol->writes = 0; /* number of writes on this volume */
440 vol->recovered_reads = 0; /* reads recovered from another plex */
441 reply->error = 0;
442 return;
444 reply->error = EINVAL;
445 return;
447 case invalid_object: /* can't get this */
448 reply->error = EINVAL;
449 return;
453 /* attach an object to a superior object */
454 void
455 attachobject(struct vinum_ioctl_msg *msg)
457 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
458 int sdno;
459 struct sd *sd;
460 struct plex *plex;
461 struct volume *vol;
463 switch (msg->type) {
464 case drive_object: /* you can't attach a drive to anything */
465 case volume_object: /* nor a volume */
466 case invalid_object: /* "this can't happen" */
467 reply->error = EINVAL;
468 reply->msg[0] = '\0'; /* vinum(8) doesn't do this */
469 return;
471 case sd_object:
472 sd = validsd(msg->index, reply);
473 if (sd == NULL) /* not a valid subdisk */
474 return;
475 plex = validplex(msg->otherobject, reply);
476 if (plex) {
478 * We should be more intelligent about this.
479 * We should be able to reattach a dead
480 * subdisk, but if we want to increase the total
481 * number of subdisks, we have a lot of reshuffling
482 * to do. XXX
484 if ((plex->organization != plex_concat) /* can't attach to striped and RAID-4/5 */
485 &&(!msg->force)) { /* without using force */
486 reply->error = EINVAL; /* no message, the user should check */
487 strcpy(reply->msg, "Can't attach to this plex organization");
488 return;
490 if (sd->plexno >= 0) { /* already belong to a plex */
491 reply->error = EBUSY; /* no message, the user should check */
492 reply->msg[0] = '\0';
493 return;
495 sd->plexoffset = msg->offset; /* this is where we want it */
496 set_sd_state(sd->sdno, sd_stale, setstate_force); /* make sure it's stale */
497 give_sd_to_plex(plex->plexno, sd->sdno); /* and give it to the plex */
498 update_sd_config(sd->sdno, 0);
499 save_config();
501 if (sd->state == sd_reviving)
502 reply->error = EAGAIN; /* need to revive it */
503 else
504 reply->error = 0;
505 break;
507 case plex_object:
508 plex = validplex(msg->index, reply); /* get plex */
509 if (plex == NULL)
510 return;
511 vol = validvol(msg->otherobject, reply); /* and volume information */
512 if (vol) {
513 if ((vol->plexes == MAXPLEX) /* we have too many already */
514 ||(plex->volno >= 0)) { /* or the plex has an owner */
515 reply->error = EINVAL; /* no message, the user should check */
516 reply->msg[0] = '\0';
517 return;
519 for (sdno = 0; sdno < plex->subdisks; sdno++) {
520 sd = &SD[plex->sdnos[sdno]];
522 if (sd->state > sd_down) /* real subdisk, vaguely accessible */
523 set_sd_state(plex->sdnos[sdno], sd_stale, setstate_force); /* make it stale */
525 set_plex_state(plex->plexno, plex_up, setstate_none); /* update plex state */
526 give_plex_to_volume(msg->otherobject, msg->index); /* and give it to the volume */
527 update_plex_config(plex->plexno, 0);
528 save_config();
533 /* detach an object from a superior object */
534 void
535 detachobject(struct vinum_ioctl_msg *msg)
537 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
538 struct sd *sd;
539 struct plex *plex;
540 struct volume *vol;
541 int sdno;
542 int plexno;
544 switch (msg->type) {
545 case drive_object: /* you can't detach a drive from anything */
546 case volume_object: /* nor a volume */
547 case invalid_object: /* "this can't happen" */
548 reply->error = EINVAL;
549 reply->msg[0] = '\0'; /* vinum(8) doesn't do this */
550 return;
552 case sd_object:
553 sd = validsd(msg->index, reply);
554 if (sd == NULL)
555 return;
556 if (sd->plexno < 0) { /* doesn't belong to a plex */
557 reply->error = ENOENT;
558 strcpy(reply->msg, "Subdisk is not attached");
559 return;
560 } else { /* valid plex number */
561 plex = &PLEX[sd->plexno];
562 if ((!msg->force) /* don't force things */
563 &&((plex->state == plex_up) /* and the plex is up */
564 ||((plex->state == plex_flaky) && sd->state == sd_up))) { /* or flaky with this sd up */
565 reply->error = EBUSY; /* we need this sd */
566 reply->msg[0] = '\0';
567 return;
569 sd->plexno = -1; /* anonymous sd */
570 if (plex->subdisks == 1) { /* this was the only subdisk */
571 Free(plex->sdnos); /* free the subdisk array */
572 plex->sdnos = NULL; /* and note the fact */
573 plex->subdisks_allocated = 0; /* no subdisk space */
574 } else {
575 for (sdno = 0; sdno < plex->subdisks; sdno++) {
576 if (plex->sdnos[sdno] == msg->index) /* found our subdisk */
577 break;
579 if (sdno < (plex->subdisks - 1)) /* not the last one, compact */
580 bcopy(&plex->sdnos[sdno + 1],
581 &plex->sdnos[sdno],
582 (plex->subdisks - 1 - sdno) * sizeof(int));
584 plex->subdisks--;
585 if (!bcmp(plex->name, sd->name, strlen(plex->name) + 1))
586 /* this subdisk is named after the plex */
588 bcopy(sd->name,
589 &sd->name[3],
590 min(strlen(sd->name) + 1, MAXSDNAME - 3));
591 bcopy("ex-", sd->name, 3);
592 sd->name[MAXSDNAME - 1] = '\0';
594 update_plex_config(plex->plexno, 0);
595 if (isstriped(plex)) /* we've just mutilated our plex, */
596 set_plex_state(plex->plexno,
597 plex_down,
598 setstate_force | setstate_configuring);
599 save_config();
600 reply->error = 0;
602 return;
604 case plex_object:
605 plex = validplex(msg->index, reply); /* get plex */
606 if (plex == NULL)
607 return;
608 if (plex->volno >= 0) {
609 int volno = plex->volno;
611 vol = &VOL[volno];
612 if ((!msg->force) /* don't force things */
613 &&((vol->state == volume_up) /* and the volume is up */
614 &&(vol->plexes == 1))) { /* and this is the last plex */
616 * XXX As elsewhere, check whether we will lose
617 * mapping by removing this plex
619 reply->error = EBUSY; /* we need this plex */
620 reply->msg[0] = '\0';
621 return;
623 plex->volno = -1; /* anonymous plex */
624 for (plexno = 0; plexno < vol->plexes; plexno++) {
625 if (vol->plex[plexno] == msg->index) /* found our plex */
626 break;
628 if (plexno < (vol->plexes - 1)) /* not the last one, compact */
629 bcopy(&vol->plex[plexno + 1],
630 &vol->plex[plexno],
631 (vol->plexes - 1 - plexno) * sizeof(int));
632 vol->plexes--;
633 vol->last_plex_read = 0; /* don't go beyond the end */
634 if (!bcmp(vol->name, plex->name, strlen(vol->name) + 1))
635 /* this plex is named after the volume */
637 /* First, check if the subdisks are the same */
638 if (msg->recurse) {
639 int sdno;
641 for (sdno = 0; sdno < plex->subdisks; sdno++) {
642 struct sd *sd = &SD[plex->sdnos[sdno]];
644 if (!bcmp(plex->name, sd->name, strlen(plex->name) + 1))
645 /* subdisk is named after the plex */
647 bcopy(sd->name,
648 &sd->name[3],
649 min(strlen(sd->name) + 1, MAXSDNAME - 3));
650 bcopy("ex-", sd->name, 3);
651 sd->name[MAXSDNAME - 1] = '\0';
655 bcopy(plex->name,
656 &plex->name[3],
657 min(strlen(plex->name) + 1, MAXPLEXNAME - 3));
658 bcopy("ex-", plex->name, 3);
659 plex->name[MAXPLEXNAME - 1] = '\0';
661 update_volume_config(volno, 0);
662 save_config();
663 reply->error = 0;
664 } else {
665 reply->error = ENOENT;
666 strcpy(reply->msg, "Plex is not attached");
671 void
672 renameobject(struct vinum_rename_msg *msg)
674 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
675 struct drive *drive;
676 struct sd *sd;
677 struct plex *plex;
678 struct volume *vol;
680 switch (msg->type) {
681 case drive_object: /* you can't attach a drive to anything */
682 if (find_drive(msg->newname, 0) >= 0) { /* we have that name already, */
683 reply->error = EEXIST;
684 reply->msg[0] = '\0';
685 return;
687 drive = validdrive(msg->index, reply);
688 if (drive) {
689 bcopy(msg->newname, drive->label.name, MAXDRIVENAME);
690 save_config();
691 reply->error = 0;
693 return;
695 case sd_object: /* you can't attach a subdisk to anything */
696 if (find_subdisk(msg->newname, 0) >= 0) { /* we have that name already, */
697 reply->error = EEXIST;
698 reply->msg[0] = '\0';
699 return;
701 sd = validsd(msg->index, reply);
702 if (sd) {
703 bcopy(msg->newname, sd->name, MAXSDNAME);
704 update_sd_config(sd->sdno, 0);
705 save_config();
706 reply->error = 0;
708 return;
710 case plex_object: /* you can't attach a plex to anything */
711 if (find_plex(msg->newname, 0) >= 0) { /* we have that name already, */
712 reply->error = EEXIST;
713 reply->msg[0] = '\0';
714 return;
716 plex = validplex(msg->index, reply);
717 if (plex) {
718 bcopy(msg->newname, plex->name, MAXPLEXNAME);
719 update_plex_config(plex->plexno, 0);
720 save_config();
721 reply->error = 0;
723 return;
725 case volume_object: /* you can't attach a volume to anything */
726 if (find_volume(msg->newname, 0) >= 0) { /* we have that name already, */
727 reply->error = EEXIST;
728 reply->msg[0] = '\0';
729 return;
731 vol = validvol(msg->index, reply);
732 if (vol) {
733 bcopy(msg->newname, vol->name, MAXVOLNAME);
734 update_volume_config(msg->index, 0);
735 save_config();
736 reply->error = 0;
738 return;
740 case invalid_object:
741 reply->error = EINVAL;
742 reply->msg[0] = '\0';
747 * Replace one object with another.
748 * Currently only for drives.
749 * message->index is the drive number of the old drive
750 * message->otherobject is the drive number of the new drive
752 void
753 replaceobject(struct vinum_ioctl_msg *msg)
755 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
757 reply->error = ENODEV; /* until I know how to do this */
758 strcpy(reply->msg, "replace not implemented yet");
759 /* save_config (); */
762 void
763 moveobject(struct vinum_ioctl_msg *msg)
765 struct _ioctl_reply *reply = (struct _ioctl_reply *) msg;
766 struct drive *drive;
767 struct sd *sd;
769 /* Check that our objects are valid (i.e. they exist) */
770 drive = validdrive(msg->index, (struct _ioctl_reply *) msg);
771 if (drive == NULL)
772 return;
773 sd = validsd(msg->otherobject, (struct _ioctl_reply *) msg);
774 if (sd == NULL)
775 return;
776 if (sd->driveno == msg->index) /* sd already belongs to drive */
777 return;
779 if (sd->state > sd_stale)
780 set_sd_state(sd->sdno, sd_stale, setstate_force); /* make the subdisk stale */
781 else
782 sd->state = sd_empty;
783 if (sd->plexno >= 0) /* part of a plex, */
784 update_plex_state(sd->plexno); /* update its state */
786 /* Return the space on the old drive */
787 if ((sd->driveno >= 0) /* we have a drive, */
788 &&(sd->sectors > 0)) /* and some space on it */
789 return_drive_space(sd->driveno, /* return the space */
790 sd->driveoffset,
791 sd->sectors);
793 /* Reassign the old subdisk */
794 sd->driveno = msg->index;
795 sd->driveoffset = -1; /* let the drive decide where to put us */
796 give_sd_to_drive(sd->sdno);
797 reply->error = 0;
800 /* Local Variables: */
801 /* fill-column: 50 */
802 /* End: */