Print this page
NEX-4934 Add capability to remove special vdev
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.

  24  */
  25 
  26 #include <libzfs.h>
  27 
  28 #include <sys/zfs_context.h>
  29 
  30 #include <errno.h>
  31 #include <fcntl.h>
  32 #include <stdarg.h>
  33 #include <stddef.h>
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <strings.h>
  37 #include <sys/file.h>
  38 #include <sys/mntent.h>
  39 #include <sys/mnttab.h>
  40 #include <sys/param.h>
  41 #include <sys/stat.h>
  42 
  43 #include <sys/dmu.h>


 444 }
 445 
 446 int
 447 translate_device(const char *pool, const char *device, err_type_t label_type,
 448     zinject_record_t *record)
 449 {
 450         char *end;
 451         zpool_handle_t *zhp;
 452         nvlist_t *tgt;
 453         boolean_t isspare, iscache;
 454 
 455         /*
 456          * Given a device name or GUID, create an appropriate injection record
 457          * with zi_guid set.
 458          */
 459         if ((zhp = zpool_open(g_zfs, pool)) == NULL)
 460                 return (-1);
 461 
 462         record->zi_guid = strtoull(device, &end, 16);
 463         if (record->zi_guid == 0 || *end != '\0') {
 464                 tgt = zpool_find_vdev(zhp, device, &isspare, &iscache, NULL);

 465 
 466                 if (tgt == NULL) {
 467                         (void) fprintf(stderr, "cannot find device '%s' in "
 468                             "pool '%s'\n", device, pool);
 469                         return (-1);
 470                 }
 471 
 472                 verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID,
 473                     &record->zi_guid) == 0);
 474         }
 475 
 476         /*
 477          * Device faults can take on three different forms:
 478          * 1). delayed or hanging I/O
 479          * 2). zfs label faults
 480          * 3). generic disk faults
 481          */
 482         if (record->zi_timer != 0) {
 483                 record->zi_cmd = ZINJECT_DELAY_IO;
 484         } else if (label_type != TYPE_INVAL) {




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  25  */
  26 
  27 #include <libzfs.h>
  28 
  29 #include <sys/zfs_context.h>
  30 
  31 #include <errno.h>
  32 #include <fcntl.h>
  33 #include <stdarg.h>
  34 #include <stddef.h>
  35 #include <stdio.h>
  36 #include <stdlib.h>
  37 #include <strings.h>
  38 #include <sys/file.h>
  39 #include <sys/mntent.h>
  40 #include <sys/mnttab.h>
  41 #include <sys/param.h>
  42 #include <sys/stat.h>
  43 
  44 #include <sys/dmu.h>


 445 }
 446 
 447 int
 448 translate_device(const char *pool, const char *device, err_type_t label_type,
 449     zinject_record_t *record)
 450 {
 451         char *end;
 452         zpool_handle_t *zhp;
 453         nvlist_t *tgt;
 454         boolean_t isspare, iscache;
 455 
 456         /*
 457          * Given a device name or GUID, create an appropriate injection record
 458          * with zi_guid set.
 459          */
 460         if ((zhp = zpool_open(g_zfs, pool)) == NULL)
 461                 return (-1);
 462 
 463         record->zi_guid = strtoull(device, &end, 16);
 464         if (record->zi_guid == 0 || *end != '\0') {
 465                 tgt = zpool_find_vdev(zhp, device, &isspare, &iscache, NULL,
 466                     NULL);
 467 
 468                 if (tgt == NULL) {
 469                         (void) fprintf(stderr, "cannot find device '%s' in "
 470                             "pool '%s'\n", device, pool);
 471                         return (-1);
 472                 }
 473 
 474                 verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID,
 475                     &record->zi_guid) == 0);
 476         }
 477 
 478         /*
 479          * Device faults can take on three different forms:
 480          * 1). delayed or hanging I/O
 481          * 2). zfs label faults
 482          * 3). generic disk faults
 483          */
 484         if (record->zi_timer != 0) {
 485                 record->zi_cmd = ZINJECT_DELAY_IO;
 486         } else if (label_type != TYPE_INVAL) {