g_eli_ctl.c (162345) | g_eli_ctl.c (162353) |
---|---|
1/*- 2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_ctl.c 162345 2006-09-16 07:47:57Z pjd $"); | 28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_ctl.c 162353 2006-09-16 10:43:17Z pjd $"); |
29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/module.h> 34#include <sys/lock.h> 35#include <sys/mutex.h> 36#include <sys/bio.h> --- 322 unchanged lines hidden (view full) --- 359 } 360 361 g_eli_create(req, mp, pp, &md, mkey, -1); 362 bzero(mkey, sizeof(mkey)); 363 bzero(&md, sizeof(md)); 364} 365 366static void | 29 30#include <sys/param.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/module.h> 34#include <sys/lock.h> 35#include <sys/mutex.h> 36#include <sys/bio.h> --- 322 unchanged lines hidden (view full) --- 359 } 360 361 g_eli_create(req, mp, pp, &md, mkey, -1); 362 bzero(mkey, sizeof(mkey)); 363 bzero(&md, sizeof(md)); 364} 365 366static void |
367g_eli_ctl_configure(struct gctl_req *req, struct g_class *mp) 368{ 369 struct g_eli_softc *sc; 370 struct g_eli_metadata md; 371 struct g_provider *pp; 372 struct g_consumer *cp; 373 char param[16]; 374 const char *prov; 375 u_char *sector; 376 int *nargs, *boot, *noboot; 377 int error; 378 u_int i; 379 380 g_topology_assert(); 381 382 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); 383 if (nargs == NULL) { 384 gctl_error(req, "No '%s' argument.", "nargs"); 385 return; 386 } 387 if (*nargs <= 0) { 388 gctl_error(req, "Missing device(s)."); 389 return; 390 } 391 392 boot = gctl_get_paraml(req, "boot", sizeof(*boot)); 393 if (boot == NULL) { 394 gctl_error(req, "No '%s' argument.", "boot"); 395 return; 396 } 397 noboot = gctl_get_paraml(req, "noboot", sizeof(*noboot)); 398 if (noboot == NULL) { 399 gctl_error(req, "No '%s' argument.", "noboot"); 400 return; 401 } 402 if (*boot && *noboot) { 403 gctl_error(req, "Options -b and -B are mutually exclusive."); 404 return; 405 } 406 if (!*boot && !*noboot) { 407 gctl_error(req, "No option given."); 408 return; 409 } 410 411 for (i = 0; i < *nargs; i++) { 412 snprintf(param, sizeof(param), "arg%d", i); 413 prov = gctl_get_asciiparam(req, param); 414 if (prov == NULL) { 415 gctl_error(req, "No 'arg%d' argument.", i); 416 return; 417 } 418 sc = g_eli_find_device(mp, prov); 419 if (sc == NULL) { 420 /* 421 * We ignore not attached providers, userland part will 422 * take care of them. 423 */ 424 G_ELI_DEBUG(1, "Skipping configuration of not attached " 425 "provider %s.", prov); 426 continue; 427 } 428 if (*boot && (sc->sc_flags & G_ELI_FLAG_BOOT)) { 429 G_ELI_DEBUG(1, "BOOT flag already configured for %s.", 430 prov); 431 continue; 432 } else if (!*boot && !(sc->sc_flags & G_ELI_FLAG_BOOT)) { 433 G_ELI_DEBUG(1, "BOOT flag not configured for %s.", 434 prov); 435 continue; 436 } 437 if (sc->sc_flags & G_ELI_FLAG_RO) { 438 gctl_error(req, "Cannot change configuration of " 439 "read-only provider %s.", prov); 440 continue; 441 } 442 cp = LIST_FIRST(&sc->sc_geom->consumer); 443 pp = cp->provider; 444 error = g_eli_read_metadata(mp, pp, &md); 445 if (error != 0) { 446 gctl_error(req, 447 "Cannot read metadata from %s (error=%d).", 448 prov, error); 449 continue; 450 } 451 452 if (*boot) { 453 md.md_flags |= G_ELI_FLAG_BOOT; 454 sc->sc_flags |= G_ELI_FLAG_BOOT; 455 } else { 456 md.md_flags &= ~G_ELI_FLAG_BOOT; 457 sc->sc_flags &= ~G_ELI_FLAG_BOOT; 458 } 459 460 sector = malloc(pp->sectorsize, M_ELI, M_WAITOK | M_ZERO); 461 eli_metadata_encode(&md, sector); 462 error = g_write_data(cp, pp->mediasize - pp->sectorsize, sector, 463 pp->sectorsize); 464 if (error != 0) { 465 gctl_error(req, 466 "Cannot store metadata on %s (error=%d).", 467 prov, error); 468 } 469 bzero(&md, sizeof(md)); 470 bzero(sector, sizeof(sector)); 471 free(sector, M_ELI); 472 } 473} 474 475static void |
|
367g_eli_ctl_setkey(struct gctl_req *req, struct g_class *mp) 368{ 369 struct g_eli_softc *sc; 370 struct g_eli_metadata md; 371 struct g_provider *pp; 372 struct g_consumer *cp; 373 const char *name; 374 u_char *key, *mkeydst, *sector; --- 330 unchanged lines hidden (view full) --- 705 } 706 707 if (strcmp(verb, "attach") == 0) 708 g_eli_ctl_attach(req, mp); 709 else if (strcmp(verb, "detach") == 0 || strcmp(verb, "stop") == 0) 710 g_eli_ctl_detach(req, mp); 711 else if (strcmp(verb, "onetime") == 0) 712 g_eli_ctl_onetime(req, mp); | 476g_eli_ctl_setkey(struct gctl_req *req, struct g_class *mp) 477{ 478 struct g_eli_softc *sc; 479 struct g_eli_metadata md; 480 struct g_provider *pp; 481 struct g_consumer *cp; 482 const char *name; 483 u_char *key, *mkeydst, *sector; --- 330 unchanged lines hidden (view full) --- 814 } 815 816 if (strcmp(verb, "attach") == 0) 817 g_eli_ctl_attach(req, mp); 818 else if (strcmp(verb, "detach") == 0 || strcmp(verb, "stop") == 0) 819 g_eli_ctl_detach(req, mp); 820 else if (strcmp(verb, "onetime") == 0) 821 g_eli_ctl_onetime(req, mp); |
822 else if (strcmp(verb, "configure") == 0) 823 g_eli_ctl_configure(req, mp); |
|
713 else if (strcmp(verb, "setkey") == 0) 714 g_eli_ctl_setkey(req, mp); 715 else if (strcmp(verb, "delkey") == 0) 716 g_eli_ctl_delkey(req, mp); 717 else if (strcmp(verb, "kill") == 0) 718 g_eli_ctl_kill(req, mp); 719 else 720 gctl_error(req, "Unknown verb."); 721} | 824 else if (strcmp(verb, "setkey") == 0) 825 g_eli_ctl_setkey(req, mp); 826 else if (strcmp(verb, "delkey") == 0) 827 g_eli_ctl_delkey(req, mp); 828 else if (strcmp(verb, "kill") == 0) 829 g_eli_ctl_kill(req, mp); 830 else 831 gctl_error(req, "Unknown verb."); 832} |