Print this page
6581 cmd/format should be able label virtio BLKDEV drives
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>

*** 22,31 **** --- 22,32 ---- * Copyright (c) 2011 Gary Mills * * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * Copyright 2015 Nexenta Systems, Inc. All rights reserved. + * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com> */ /* * This file contains functions to implement automatic configuration * of scsi disks.
*** 208,226 **** struct dk_cinfo *dkinfo); static struct disk_type *new_direct_disk_type(int fd, char *disk_name, struct dk_label *label); - static struct disk_info *find_direct_disk_info(struct dk_cinfo *dkinfo); static int efi_ioctl(int fd, int cmd, dk_efi_t *dk_ioc); static int auto_label_init(struct dk_label *label); ! static struct ctlr_type *find_direct_ctlr_type(void); ! static struct ctlr_info *find_direct_ctlr_info(struct dk_cinfo *dkinfo); ! static struct disk_info *find_direct_disk_info(struct dk_cinfo *dkinfo); ! static struct ctlr_type *find_vbd_ctlr_type(void); ! static struct ctlr_info *find_vbd_ctlr_info(struct dk_cinfo *dkinfo); ! static struct disk_info *find_vbd_disk_info(struct dk_cinfo *dkinfo); static char *get_sun_disk_name( char *disk_name, struct scsi_inquiry *inquiry); static char *strcopy( --- 209,223 ---- struct dk_cinfo *dkinfo); static struct disk_type *new_direct_disk_type(int fd, char *disk_name, struct dk_label *label); static int efi_ioctl(int fd, int cmd, dk_efi_t *dk_ioc); static int auto_label_init(struct dk_label *label); ! static struct ctlr_type *find_ctlr_type(ushort_t); ! static struct ctlr_info *find_ctlr_info(struct dk_cinfo *, ushort_t); ! static struct disk_info *find_disk_info(struct dk_cinfo *, ushort_t); static char *get_sun_disk_name( char *disk_name, struct scsi_inquiry *inquiry); static char *strcopy(
*** 262,277 **** if (option_msg && diag_msg) { err_print("DKIOCINFO failed\n"); } return (NULL); } ! if ((cur_ctype != NULL) && (cur_ctype->ctype_ctype == DKC_DIRECT)) { ! ctlr = find_direct_ctlr_info(&dkinfo); ! disk_info = find_direct_disk_info(&dkinfo); ! } else if ((cur_ctype != NULL) && (cur_ctype->ctype_ctype == DKC_VBD)) { ! ctlr = find_vbd_ctlr_info(&dkinfo); ! disk_info = find_vbd_disk_info(&dkinfo); } else { ctlr = find_scsi_ctlr_info(&dkinfo); disk_info = find_scsi_disk_info(&dkinfo); } --- 259,273 ---- if (option_msg && diag_msg) { err_print("DKIOCINFO failed\n"); } return (NULL); } ! if ((cur_ctype != NULL) && (cur_ctype->ctype_ctype == DKC_DIRECT || ! cur_ctype->ctype_ctype == DKC_VBD || ! cur_ctype->ctype_ctype == DKC_BLKDEV)) { ! ctlr = find_ctlr_info(&dkinfo, cur_ctype->ctype_ctype); ! disk_info = find_disk_info(&dkinfo, cur_ctype->ctype_ctype); } else { ctlr = find_scsi_ctlr_info(&dkinfo); disk_info = find_scsi_disk_info(&dkinfo); }
*** 376,506 **** return (error); } static struct ctlr_type * ! find_direct_ctlr_type() { struct mctlr_list *mlp; ! mlp = controlp; - while (mlp != NULL) { - if (mlp->ctlr_type->ctype_ctype == DKC_DIRECT) { - return (mlp->ctlr_type); - } - mlp = mlp->next; - } - - impossible("no DIRECT controller type"); - - return ((struct ctlr_type *)NULL); - } - - static struct ctlr_type * - find_vbd_ctlr_type() - { - struct mctlr_list *mlp; - mlp = controlp; while (mlp != NULL) { ! if (mlp->ctlr_type->ctype_ctype == DKC_VBD) { return (mlp->ctlr_type); } mlp = mlp->next; } ! impossible("no VBD controller type"); return ((struct ctlr_type *)NULL); } static struct ctlr_info * ! find_direct_ctlr_info( ! struct dk_cinfo *dkinfo) { struct ctlr_info *ctlr; ! if (dkinfo->dki_ctype != DKC_DIRECT) ! return (NULL); for (ctlr = ctlr_list; ctlr != NULL; ctlr = ctlr->ctlr_next) { if (ctlr->ctlr_addr == dkinfo->dki_addr && ctlr->ctlr_space == dkinfo->dki_space && ! ctlr->ctlr_ctype->ctype_ctype == DKC_DIRECT) { return (ctlr); } } ! impossible("no DIRECT controller info"); /*NOTREACHED*/ } - static struct ctlr_info * - find_vbd_ctlr_info( - struct dk_cinfo *dkinfo) - { - struct ctlr_info *ctlr; - - if (dkinfo->dki_ctype != DKC_VBD) - return (NULL); - - for (ctlr = ctlr_list; ctlr != NULL; ctlr = ctlr->ctlr_next) { - if (ctlr->ctlr_addr == dkinfo->dki_addr && - ctlr->ctlr_space == dkinfo->dki_space && - ctlr->ctlr_ctype->ctype_ctype == DKC_VBD) { - return (ctlr); - } - } - - impossible("no VBD controller info"); - /*NOTREACHED*/ - } - static struct disk_info * ! find_direct_disk_info( ! struct dk_cinfo *dkinfo) { struct disk_info *disk; struct dk_cinfo *dp; ! for (disk = disk_list; disk != NULL; disk = disk->disk_next) { ! assert(dkinfo->dki_ctype == DKC_DIRECT); ! dp = &disk->disk_dkinfo; ! if (dp->dki_ctype == dkinfo->dki_ctype && ! dp->dki_cnum == dkinfo->dki_cnum && ! dp->dki_unit == dkinfo->dki_unit && ! strcmp(dp->dki_dname, dkinfo->dki_dname) == 0) { ! return (disk); ! } ! } - impossible("No DIRECT disk info instance\n"); - /*NOTREACHED*/ - } - - static struct disk_info * - find_vbd_disk_info( - struct dk_cinfo *dkinfo) - { - struct disk_info *disk; - struct dk_cinfo *dp; - for (disk = disk_list; disk != NULL; disk = disk->disk_next) { - assert(dkinfo->dki_ctype == DKC_VBD); dp = &disk->disk_dkinfo; if (dp->dki_ctype == dkinfo->dki_ctype && dp->dki_cnum == dkinfo->dki_cnum && dp->dki_unit == dkinfo->dki_unit && strcmp(dp->dki_dname, dkinfo->dki_dname) == 0) { return (disk); } } ! impossible("No VBD disk info instance\n"); /*NOTREACHED*/ } /* * To convert EFI to SMI labels, we need to get label geometry. * Unfortunately at this time there is no good way to do so. --- 372,448 ---- return (error); } static struct ctlr_type * ! find_ctlr_type(ushort_t type) { struct mctlr_list *mlp; ! assert(type == DKC_DIRECT || ! type == DKC_VBD || ! type == DKC_BLKDEV); mlp = controlp; while (mlp != NULL) { ! if (mlp->ctlr_type->ctype_ctype == type) { return (mlp->ctlr_type); } mlp = mlp->next; } ! impossible("no DIRECT/VBD/BLKDEV controller type"); return ((struct ctlr_type *)NULL); } static struct ctlr_info * ! find_ctlr_info(struct dk_cinfo *dkinfo, ushort_t type) { struct ctlr_info *ctlr; ! assert(type == DKC_DIRECT || ! type == DKC_VBD || ! type == DKC_BLKDEV); for (ctlr = ctlr_list; ctlr != NULL; ctlr = ctlr->ctlr_next) { if (ctlr->ctlr_addr == dkinfo->dki_addr && ctlr->ctlr_space == dkinfo->dki_space && ! ctlr->ctlr_ctype->ctype_ctype == dkinfo->dki_ctype) { return (ctlr); } } ! impossible("no DIRECT/VBD/BLKDEV controller info"); /*NOTREACHED*/ + return ((struct ctlr_info *)NULL); } static struct disk_info * ! find_disk_info(struct dk_cinfo *dkinfo, ushort_t type) { struct disk_info *disk; struct dk_cinfo *dp; ! assert(type == DKC_DIRECT || ! type == DKC_VBD || ! type == DKC_BLKDEV); for (disk = disk_list; disk != NULL; disk = disk->disk_next) { dp = &disk->disk_dkinfo; if (dp->dki_ctype == dkinfo->dki_ctype && dp->dki_cnum == dkinfo->dki_cnum && dp->dki_unit == dkinfo->dki_unit && strcmp(dp->dki_dname, dkinfo->dki_dname) == 0) { return (disk); } } ! impossible("No DIRECT/VBD/BLKDEV disk info instance\n"); /*NOTREACHED*/ + return ((struct disk_info *)NULL); } /* * To convert EFI to SMI labels, we need to get label geometry. * Unfortunately at this time there is no good way to do so.
*** 689,709 **** } /* * Find the ctlr_info for this disk. */ ! ctlr = find_direct_ctlr_info(&dkinfo); /* * Allocate a new disk type for the direct controller. */ disk = (struct disk_type *)zalloc(sizeof (struct disk_type)); /* * Find the disk_info instance for this disk. */ ! disk_info = find_direct_disk_info(&dkinfo); /* * The controller and the disk should match. */ assert(disk_info->disk_ctlr == ctlr); --- 631,651 ---- } /* * Find the ctlr_info for this disk. */ ! ctlr = find_ctlr_info(&dkinfo, dkinfo.dki_ctype); /* * Allocate a new disk type for the direct controller. */ disk = (struct disk_type *)zalloc(sizeof (struct disk_type)); /* * Find the disk_info instance for this disk. */ ! disk_info = find_disk_info(&dkinfo, dkinfo.dki_ctype); /* * The controller and the disk should match. */ assert(disk_info->disk_ctlr == ctlr);
*** 2008,2027 **** /* * Delete a disk type from disk type list. */ int ! delete_disk_type( ! struct disk_type *disk_type) { struct ctlr_type *ctlr; struct disk_type *dp, *disk; ! if (cur_ctype->ctype_ctype == DKC_DIRECT) ! ctlr = find_direct_ctlr_type(); ! else if (cur_ctype->ctype_ctype == DKC_VBD) ! ctlr = find_vbd_ctlr_type(); else ctlr = find_scsi_ctlr_type(); if (ctlr == NULL || ctlr->ctype_dlist == NULL) { return (-1); } --- 1950,1968 ---- /* * Delete a disk type from disk type list. */ int ! delete_disk_type(struct disk_type *disk_type) { struct ctlr_type *ctlr; struct disk_type *dp, *disk; ! if (cur_ctype->ctype_ctype == DKC_DIRECT || ! cur_ctype->ctype_ctype == DKC_VBD || ! cur_ctype->ctype_ctype == DKC_BLKDEV) ! ctlr = find_ctlr_type(cur_ctype->ctype_ctype); else ctlr = find_scsi_ctlr_type(); if (ctlr == NULL || ctlr->ctype_dlist == NULL) { return (-1); }