ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * CDDL HEADER START
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * See the License for the specific language governing permissions
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * and limitations under the License.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * When distributing Covered Code, include this CDDL HEADER in each
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If applicable, add the following below this CDDL HEADER, with the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * fields enclosed by brackets "[]" replaced with your own identifying
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * information: Portions Copyright [yyyy] [name of copyright owner]
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * CDDL HEADER END
f80ce222af313ec87dc070b2219b29c81c5e5d8cChris Kirby * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * Copyright (c) 2012 by Delphix. All rights reserved.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockextern void kernel_init(int);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockextern void kernel_fini(void);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Given a full path to a file, translate into a dataset name and a relative
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * path within the dataset. 'dataset' must be at least MAXNAMELEN characters,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * and 'relpath' must be at least MAXPATHLEN characters. We also pass a stat64
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * buffer, which we need later to get the object ID.
f80ce222af313ec87dc070b2219b29c81c5e5d8cChris Kirbyparse_pathname(const char *inpath, char *dataset, char *relpath,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "invalid object '%s': must be full "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "invalid object; pathname too long\n");
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "cannot open /etc/mnttab\n");
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (makedev(mp.mnt_major, mp.mnt_minor) == statbuf->st_dev) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "cannot find mountpoint for '%s'\n",
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "invalid path '%s': not a ZFS "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (strncmp(fullpath, mp.mnt_mountp, strlen(mp.mnt_mountp)) != 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "invalid path '%s': mountpoint "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Convert from a (dataset, path) pair into a (objset, object) pair. Note that
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * we grab the object number from the inode number, since looking this up via
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * libzpool is a real pain.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock/* ARGSUSED */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockobject_from_path(const char *dataset, const char *path, struct stat64 *statbuf,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Before doing any libzpool operations, call sync() to ensure that the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * on-disk state is consistent with the in-core state.
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens err = dmu_objset_own(dataset, DMU_OST_ZFS, B_TRUE, FTAG, &os);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "cannot open dataset '%s': %s\n",
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Calculate the real range based on the type, level, and range given.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockcalculate_range(const char *dataset, err_type_t type, int level, char *range,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Determine the numeric range from the string.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If range is unspecified, set the range to [0,-1], which
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * indicates that the whole object should be treated as an
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock /* XXX add support for suffixes */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "invalid range '%s': must be "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "a numeric range of the form 'start[,end]'\n",
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If this is a request to inject faults into the dnode, then we
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * must translate the current (objset,object) pair into an
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * offset within the metadnode for the objset. Specifying any
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * kind of range with type 'dnode' is illegal.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "range cannot be specified when "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "type is 'dnode'\n");
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock record->zi_start = record->zi_object * sizeof (dnode_phys_t);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock record->zi_end = record->zi_start + sizeof (dnode_phys_t);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Get the dnode associated with object, so we can calculate the block
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens if ((err = dmu_objset_own(dataset, DMU_OST_ANY,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "cannot open dataset '%s': %s\n",
503ad85c168c7992ccc310af845a581cff3c72b5Matthew Ahrens err = dnode_hold(os, record->zi_object, FTAG, &dn);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err != 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock "for object %llu\n",
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ziprintf("data shift: %d\n", (int)dn->dn_datablkshift);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ziprintf(" ind shift: %d\n", (int)dn->dn_indblkshift);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Translate range into block IDs.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (record->zi_start != 0 || record->zi_end != -1ULL) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Check level, and then translate level 0 blkids into ranges
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * appropriate for level of indirection.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "level %d exceeds max level "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (record->zi_start != 0 || record->zi_end != 0) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrocktranslate_record(err_type_t type, const char *object, const char *range,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock int level, zinject_record_t *record, char *poolname, char *dataset)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * MOS objects are treated specially.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Convert a full path into a (dataset, file) pair.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (parse_pathname(object, dataset, path, &statbuf) != 0)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Convert (dataset, file) into (objset, object)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (object_from_path(dataset, path, &statbuf, record) != 0)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * For the given object, calculate the real (type, level, range)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (calculate_range(dataset, type, level, (char *)range, record) != 0)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ziprintf(" range: [%llu, %llu]\n", record->zi_start,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Copy the pool name
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrocktranslate_raw(const char *str, zinject_record_t *record)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * A raw bookmark of the form objset:object:level:blkid, where each
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * number is a hexidecimal value.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (sscanf(str, "%llx:%llx:%x:%llx", (u_longlong_t *)&record->zi_objset,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (u_longlong_t *)&record->zi_object, &record->zi_level,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (void) fprintf(stderr, "bad raw spec '%s': must be of the form "
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);
21bf64a78855d076f09716ea1c06175d954e934cgwtranslate_device(const char *pool, const char *device, err_type_t label_type,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Given a device name or GUID, create an appropriate injection record
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * with zi_guid set.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (-1);
ee0eb9f2d12b8a03b5a193cd667735c1962e0c7bEric Schrock tgt = zpool_find_vdev(zhp, device, &isspare, &iscache, NULL);
99653d4ee642c6528e88224f12409a5f23060994eschrock (void) fprintf(stderr, "cannot find device '%s' in "
99653d4ee642c6528e88224f12409a5f23060994eschrock return (-1);
99653d4ee642c6528e88224f12409a5f23060994eschrock verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID,
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * Device faults can take on three different forms:
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * 1). delayed or hanging I/O
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * 2). zfs label faults
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * 3). generic disk faults
21bf64a78855d076f09716ea1c06175d954e934cgw record->zi_start = offsetof(vdev_label_t, vl_uberblock[0]);
21bf64a78855d076f09716ea1c06175d954e934cgw record->zi_end = record->zi_start + VDEV_UBERBLOCK_RING - 1;
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson record->zi_start = offsetof(vdev_label_t, vl_pad1);
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson record->zi_end = record->zi_start + VDEV_PAD_SIZE - 1;
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson record->zi_start = offsetof(vdev_label_t, vl_pad2);
98d1cbfec254295273b6a761bc1861c0374bdf02George Wilson record->zi_end = record->zi_start + VDEV_PAD_SIZE - 1;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (0);