summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorasomers <asomers@FreeBSD.org>2018-03-10 03:34:27 +0000
committerasomers <asomers@FreeBSD.org>2018-03-10 03:34:27 +0000
commita804ad249fd8400062f1e51eecc7b4675258b0f3 (patch)
tree85d44ee8338e0c19a9015afb3937632efc15f77f
parentba9783a1436a2178e824662c2ecff3544e63b1c9 (diff)
downloadFreeBSD-src-a804ad249fd8400062f1e51eecc7b4675258b0f3.zip
FreeBSD-src-a804ad249fd8400062f1e51eecc7b4675258b0f3.tar.gz
MFC r329273, r329275, r329277, r329284, r329344
r329273: geli: append "/eli" to the underlying provider's physical path If the underlying provider's physical path is null, then the geli device's physical path will be, too. Otherwise, it will append "/eli". This will make geli work better with zfsd(8). PR: 224962 Differential Revision: https://reviews.freebsd.org/D13979 r329275: gpart: append partition name to the underlying provider's physical path If the underlying provider's physical path is null, then the gpart device's physical path will be, too. Otherwise, it will append the partition name, such as "/p1" or "/s1/a". This will make gpart work better with zfsd(8). PR: 224965 Differential Revision: https://reviews.freebsd.org/D14010 r329277: Add mtree entry for 329275 X-MFC-With: 329275 Sponsored by: Spectra Logic Corp r329284: zfsd: Allow zfsd to work on any type of GEOM provider cddl/usr.sbin/zfsd/zfsd_event.cc Remove the check for da and ada devices. This way zfsd can work on md, geli, glabel, gstripe, etc devices. geli in particular is useful combined with ZFS. gnop is also useful for simulating drive pulls in the ZFSD test suite. Also, eliminate the DevfsEvent class entirely. Move its responsibilities into GeomEvent. We can get everything we need to know just from listening to GEOM events. lib/libdevdctl/event.cc Fix GeomEvent::DevName for CREATE events. Oddly, the relevant field is named "cdev" for CREATE events but "devname" for disk events. Relnotes: Yes (probably worth mentioning the geli part) Sponsored by: Spectra Logic Corp r329344: Optimize zfsd for the happy case If there are no damaged pools, then ignore all GEOM events. We only use them to fix damaged pools. However, still pay attention to ZFS events. X-MFC-With: 329284 Sponsored by: Spectra Logic Corp
-rw-r--r--cddl/usr.sbin/zfsd/case_file.cc6
-rw-r--r--cddl/usr.sbin/zfsd/case_file.h5
-rw-r--r--cddl/usr.sbin/zfsd/zfsd.cc1
-rw-r--r--cddl/usr.sbin/zfsd/zfsd_event.cc255
-rw-r--r--cddl/usr.sbin/zfsd/zfsd_event.h90
-rw-r--r--etc/mtree/BSD.tests.dist2
-rw-r--r--lib/libdevdctl/event.cc5
-rw-r--r--sys/geom/eli/g_eli.c15
-rw-r--r--sys/geom/part/g_part.c36
-rw-r--r--tests/sys/geom/class/Makefile3
-rw-r--r--tests/sys/geom/class/eli/Makefile1
-rw-r--r--tests/sys/geom/class/eli/misc_test.sh177
-rw-r--r--tests/sys/geom/class/part/Makefile10
-rw-r--r--tests/sys/geom/class/part/misc.sh187
14 files changed, 569 insertions, 224 deletions
diff --git a/cddl/usr.sbin/zfsd/case_file.cc b/cddl/usr.sbin/zfsd/case_file.cc
index 1ddffae..c14009b 100644
--- a/cddl/usr.sbin/zfsd/case_file.cc
+++ b/cddl/usr.sbin/zfsd/case_file.cc
@@ -186,6 +186,12 @@ CaseFile::DeSerialize()
free(caseFiles);
}
+bool
+CaseFile::Empty()
+{
+ return (s_activeCases.empty());
+}
+
void
CaseFile::LogAll()
{
diff --git a/cddl/usr.sbin/zfsd/case_file.h b/cddl/usr.sbin/zfsd/case_file.h
index fcb1261..b4dc2de 100644
--- a/cddl/usr.sbin/zfsd/case_file.h
+++ b/cddl/usr.sbin/zfsd/case_file.h
@@ -135,6 +135,11 @@ public:
static void DeSerialize();
/**
+ * \brief returns true if there are no CaseFiles
+ */
+ static bool Empty();
+
+ /**
* \brief Emit syslog data on all active CaseFile%%s in the system.
*/
static void LogAll();
diff --git a/cddl/usr.sbin/zfsd/zfsd.cc b/cddl/usr.sbin/zfsd/zfsd.cc
index 648455f..2f17b47 100644
--- a/cddl/usr.sbin/zfsd/zfsd.cc
+++ b/cddl/usr.sbin/zfsd/zfsd.cc
@@ -98,7 +98,6 @@ int ZfsDaemon::s_signalPipeFD[2];
bool ZfsDaemon::s_systemRescanRequested(false);
EventFactory::Record ZfsDaemon::s_registryEntries[] =
{
- { Event::NOTIFY, "DEVFS", &DevfsEvent::Builder },
{ Event::NOTIFY, "GEOM", &GeomEvent::Builder },
{ Event::NOTIFY, "ZFS", &ZfsEvent::Builder }
};
diff --git a/cddl/usr.sbin/zfsd/zfsd_event.cc b/cddl/usr.sbin/zfsd/zfsd_event.cc
index 5594b35..707a868 100644
--- a/cddl/usr.sbin/zfsd/zfsd_event.cc
+++ b/cddl/usr.sbin/zfsd/zfsd_event.cc
@@ -76,111 +76,40 @@ using std::stringstream;
/*=========================== Class Implementations ==========================*/
-/*-------------------------------- DevfsEvent --------------------------------*/
+/*-------------------------------- GeomEvent --------------------------------*/
-//- DevfsEvent Static Public Methods -------------------------------------------
+//- GeomEvent Static Public Methods -------------------------------------------
Event *
-DevfsEvent::Builder(Event::Type type,
- NVPairMap &nvPairs,
- const string &eventString)
-{
- return (new DevfsEvent(type, nvPairs, eventString));
-}
-
-//- DevfsEvent Static Protected Methods ----------------------------------------
-nvlist_t *
-DevfsEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
-{
- pool_state_t poolState;
- char *poolName;
- boolean_t b_inuse;
- int nlabels;
-
- inUse = false;
- degraded = false;
- poolName = NULL;
- if (zpool_in_use(g_zfsHandle, devFd, &poolState,
- &poolName, &b_inuse) == 0) {
- nvlist_t *devLabel = NULL;
-
- inUse = b_inuse == B_TRUE;
- if (poolName != NULL)
- free(poolName);
-
- nlabels = zpool_read_all_labels(devFd, &devLabel);
- /*
- * If we find a disk with fewer than the maximum number of
- * labels, it might be the whole disk of a partitioned disk
- * where ZFS resides on a partition. In that case, we should do
- * nothing and wait for the partition to appear. Or, the disk
- * might be damaged. In that case, zfsd should do nothing and
- * wait for the sysadmin to decide.
- */
- if (nlabels != VDEV_LABELS || devLabel == NULL) {
- nvlist_free(devLabel);
- return (NULL);
- }
-
- try {
- Vdev vdev(devLabel);
- degraded = vdev.State() != VDEV_STATE_HEALTHY;
- return (devLabel);
- } catch (ZfsdException &exp) {
- string devName = fdevname(devFd);
- string devPath = _PATH_DEV + devName;
- string context("DevfsEvent::ReadLabel: "
- + devPath + ": ");
-
- exp.GetString().insert(0, context);
- exp.Log();
- nvlist_free(devLabel);
- }
- }
- return (NULL);
-}
-
-bool
-DevfsEvent::OnlineByLabel(const string &devPath, const string& physPath,
- nvlist_t *devConfig)
+GeomEvent::Builder(Event::Type type,
+ NVPairMap &nvPairs,
+ const string &eventString)
{
- try {
- /*
- * A device with ZFS label information has been
- * inserted. If it matches a device for which we
- * have a case, see if we can solve that case.
- */
- syslog(LOG_INFO, "Interrogating VDEV label for %s\n",
- devPath.c_str());
- Vdev vdev(devConfig);
- CaseFile *caseFile(CaseFile::Find(vdev.PoolGUID(),
- vdev.GUID()));
- if (caseFile != NULL)
- return (caseFile->ReEvaluate(devPath, physPath, &vdev));
-
- } catch (ZfsdException &exp) {
- string context("DevfsEvent::OnlineByLabel: " + devPath + ": ");
-
- exp.GetString().insert(0, context);
- exp.Log();
- }
- return (false);
+ return (new GeomEvent(type, nvPairs, eventString));
}
-//- DevfsEvent Virtual Public Methods ------------------------------------------
+//- GeomEvent Virtual Public Methods ------------------------------------------
Event *
-DevfsEvent::DeepCopy() const
+GeomEvent::DeepCopy() const
{
- return (new DevfsEvent(*this));
+ return (new GeomEvent(*this));
}
-
+
bool
-DevfsEvent::Process() const
+GeomEvent::Process() const
{
/*
- * We are only concerned with newly discovered
- * devices that can be ZFS vdevs.
+ * We only use GEOM events to repair damaged pools. So return early if
+ * there are no damaged pools
*/
- if (Value("type") != "CREATE" || !IsDiskDev())
+ if (CaseFile::Empty())
+ return (false);
+
+ /*
+ * We are only concerned with arrivals and physical path changes,
+ * because those can be used to satisfy online and autoreplace
+ * operations
+ */
+ if (Value("type") != "GEOM::physpath" && Value("type") != "CREATE")
return (false);
/* Log the event since it is of interest. */
@@ -199,7 +128,7 @@ DevfsEvent::Process() const
nvlist_t *devLabel(ReadLabel(devFd, inUse, degraded));
string physPath;
- bool havePhysPath(PhysicalPath(physPath));
+ bool havePhysPath(PhysicalPath(physPath));
string devName;
DevName(devName);
@@ -211,8 +140,8 @@ DevfsEvent::Process() const
syslog(LOG_INFO, "%s is marked degraded. Ignoring "
"as a replace by physical path candidate.\n",
devName.c_str());
- } else if (havePhysPath && IsWholeDev()) {
- /*
+ } else if (havePhysPath) {
+ /*
* TODO: attempt to resolve events using every casefile
* that matches this physpath
*/
@@ -227,93 +156,97 @@ DevfsEvent::Process() const
caseFile->ReEvaluate(devPath, physPath, /*vdev*/NULL);
}
}
- if (devLabel != NULL)
- nvlist_free(devLabel);
return (false);
}
-//- DevfsEvent Protected Methods -----------------------------------------------
-DevfsEvent::DevfsEvent(Event::Type type, NVPairMap &nvpairs,
+//- GeomEvent Protected Methods -----------------------------------------------
+GeomEvent::GeomEvent(Event::Type type, NVPairMap &nvpairs,
const string &eventString)
- : DevdCtl::DevfsEvent(type, nvpairs, eventString)
-{
-}
-
-DevfsEvent::DevfsEvent(const DevfsEvent &src)
- : DevdCtl::DevfsEvent::DevfsEvent(src)
+ : DevdCtl::GeomEvent(type, nvpairs, eventString)
{
}
-/*-------------------------------- GeomEvent --------------------------------*/
-
-//- GeomEvent Static Public Methods -------------------------------------------
-Event *
-GeomEvent::Builder(Event::Type type,
- NVPairMap &nvPairs,
- const string &eventString)
+GeomEvent::GeomEvent(const GeomEvent &src)
+ : DevdCtl::GeomEvent::GeomEvent(src)
{
- return (new GeomEvent(type, nvPairs, eventString));
}
-//- GeomEvent Virtual Public Methods ------------------------------------------
-Event *
-GeomEvent::DeepCopy() const
-{
- return (new GeomEvent(*this));
-}
-
-bool
-GeomEvent::Process() const
+nvlist_t *
+GeomEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
{
- /*
- * We are only concerned with physical path changes, because those can
- * be used to satisfy autoreplace operations
- */
- if (Value("type") != "GEOM::physpath" || !IsDiskDev())
- return (false);
+ pool_state_t poolState;
+ char *poolName;
+ boolean_t b_inuse;
+ int nlabels;
- /* Log the event since it is of interest. */
- Log(LOG_INFO);
+ inUse = false;
+ degraded = false;
+ poolName = NULL;
+ if (zpool_in_use(g_zfsHandle, devFd, &poolState,
+ &poolName, &b_inuse) == 0) {
+ nvlist_t *devLabel = NULL;
- string devPath;
- if (!DevPath(devPath))
- return (false);
+ inUse = b_inuse == B_TRUE;
+ if (poolName != NULL)
+ free(poolName);
- string physPath;
- bool havePhysPath(PhysicalPath(physPath));
+ nlabels = zpool_read_all_labels(devFd, &devLabel);
+ /*
+ * If we find a disk with fewer than the maximum number of
+ * labels, it might be the whole disk of a partitioned disk
+ * where ZFS resides on a partition. In that case, we should do
+ * nothing and wait for the partition to appear. Or, the disk
+ * might be damaged. In that case, zfsd should do nothing and
+ * wait for the sysadmin to decide.
+ */
+ if (nlabels != VDEV_LABELS || devLabel == NULL) {
+ nvlist_free(devLabel);
+ return (NULL);
+ }
- string devName;
- DevName(devName);
+ try {
+ Vdev vdev(devLabel);
+ degraded = vdev.State() != VDEV_STATE_HEALTHY;
+ return (devLabel);
+ } catch (ZfsdException &exp) {
+ string devName = fdevname(devFd);
+ string devPath = _PATH_DEV + devName;
+ string context("GeomEvent::ReadLabel: "
+ + devPath + ": ");
- if (havePhysPath) {
- /*
- * TODO: attempt to resolve events using every casefile
- * that matches this physpath
- */
- CaseFile *caseFile(CaseFile::Find(physPath));
- if (caseFile != NULL) {
- syslog(LOG_INFO,
- "Found CaseFile(%s:%s:%s) - ReEvaluating\n",
- caseFile->PoolGUIDString().c_str(),
- caseFile->VdevGUIDString().c_str(),
- zpool_state_to_name(caseFile->VdevState(),
- VDEV_AUX_NONE));
- caseFile->ReEvaluate(devPath, physPath, /*vdev*/NULL);
+ exp.GetString().insert(0, context);
+ exp.Log();
+ nvlist_free(devLabel);
}
}
- return (false);
+ return (NULL);
}
-//- GeomEvent Protected Methods -----------------------------------------------
-GeomEvent::GeomEvent(Event::Type type, NVPairMap &nvpairs,
- const string &eventString)
- : DevdCtl::GeomEvent(type, nvpairs, eventString)
+bool
+GeomEvent::OnlineByLabel(const string &devPath, const string& physPath,
+ nvlist_t *devConfig)
{
-}
+ try {
+ /*
+ * A device with ZFS label information has been
+ * inserted. If it matches a device for which we
+ * have a case, see if we can solve that case.
+ */
+ syslog(LOG_INFO, "Interrogating VDEV label for %s\n",
+ devPath.c_str());
+ Vdev vdev(devConfig);
+ CaseFile *caseFile(CaseFile::Find(vdev.PoolGUID(),
+ vdev.GUID()));
+ if (caseFile != NULL)
+ return (caseFile->ReEvaluate(devPath, physPath, &vdev));
-GeomEvent::GeomEvent(const GeomEvent &src)
- : DevdCtl::GeomEvent::GeomEvent(src)
-{
+ } catch (ZfsdException &exp) {
+ string context("GeomEvent::OnlineByLabel: " + devPath + ": ");
+
+ exp.GetString().insert(0, context);
+ exp.Log();
+ }
+ return (false);
}
diff --git a/cddl/usr.sbin/zfsd/zfsd_event.h b/cddl/usr.sbin/zfsd/zfsd_event.h
index c4ba422..fd3f9f7 100644
--- a/cddl/usr.sbin/zfsd/zfsd_event.h
+++ b/cddl/usr.sbin/zfsd/zfsd_event.h
@@ -60,63 +60,6 @@ typedef struct zpool_handle zpool_handle_t;
struct nvlist;
typedef struct nvlist nvlist_t;
-/*============================= Class Definitions ============================*/
-/*-------------------------------- DevfsEvent --------------------------------*/
-class DevfsEvent : public DevdCtl::DevfsEvent
-{
-public:
- /** Specialized DevdCtlEvent object factory for Devfs events. */
- static BuildMethod Builder;
-
- virtual DevdCtl::Event *DeepCopy() const;
-
- /**
- * Interpret and perform any actions necessary to
- * consume the event.
- * \return True if this event should be queued for later reevaluation
- */
- virtual bool Process() const;
-
-protected:
- /**
- * \brief Read and return label information for a device.
- *
- * \param devFd The device from which to read ZFS label information.
- * \param inUse The device is part of an active or potentially
- * active configuration.
- * \param degraded The device label indicates the vdev is not healthy.
- *
- * \return If label information is available, an nvlist describing
- * the vdev configuraiton found on the device specified by
- * devFd. Otherwise NULL.
- */
- static nvlist_t *ReadLabel(int devFd, bool &inUse, bool &degraded);
-
- /**
- * Attempt to match the ZFS labeled device at devPath with an active
- * CaseFile for a missing vdev. If a CaseFile is found, attempt
- * to re-integrate the device with its pool.
- *
- * \param devPath The devfs path to the potential leaf vdev.
- * \param physPath The physical path string reported by the device
- * at devPath.
- * \param devConfig The ZFS label information found on the device
- * at devPath.
- *
- * \return true if the event that caused the online action can
- * be considered consumed.
- */
- static bool OnlineByLabel(const string &devPath,
- const string& physPath,
- nvlist_t *devConfig);
-
- /** DeepCopy Constructor. */
- DevfsEvent(const DevfsEvent &src);
-
- /** Constructor */
- DevfsEvent(Type, DevdCtl::NVPairMap &, const string &);
-};
-
/*--------------------------------- ZfsEvent ---------------------------------*/
class ZfsEvent : public DevdCtl::ZfsEvent
{
@@ -164,5 +107,38 @@ protected:
/** Constructor */
GeomEvent(Type, DevdCtl::NVPairMap &, const string &);
+
+ /**
+ * Attempt to match the ZFS labeled device at devPath with an active
+ * CaseFile for a missing vdev. If a CaseFile is found, attempt
+ * to re-integrate the device with its pool.
+ *
+ * \param devPath The devfs path to the potential leaf vdev.
+ * \param physPath The physical path string reported by the device
+ * at devPath.
+ * \param devConfig The ZFS label information found on the device
+ * at devPath.
+ *
+ * \return true if the event that caused the online action can
+ * be considered consumed.
+ */
+ static bool OnlineByLabel(const string &devPath,
+ const string& physPath,
+ nvlist_t *devConfig);
+
+ /**
+ * \brief Read and return label information for a device.
+ *
+ * \param devFd The device from which to read ZFS label information.
+ * \param inUse The device is part of an active or potentially
+ * active configuration.
+ * \param degraded The device label indicates the vdev is not healthy.
+ *
+ * \return If label information is available, an nvlist describing
+ * the vdev configuraiton found on the device specified by
+ * devFd. Otherwise NULL.
+ */
+ static nvlist_t *ReadLabel(int devFd, bool &inUse, bool &degraded);
+
};
#endif /*_ZFSD_EVENT_H_ */
diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist
index 147a53f..0dbc44d 100644
--- a/etc/mtree/BSD.tests.dist
+++ b/etc/mtree/BSD.tests.dist
@@ -440,6 +440,8 @@
..
nop
..
+ part
+ ..
raid3
..
shsec
diff --git a/lib/libdevdctl/event.cc b/lib/libdevdctl/event.cc
index d63e8e2..c73c40c 100644
--- a/lib/libdevdctl/event.cc
+++ b/lib/libdevdctl/event.cc
@@ -542,7 +542,10 @@ GeomEvent::DeepCopy() const
bool
GeomEvent::DevName(std::string &name) const
{
- name = Value("devname");
+ if (Value("subsystem") == "disk")
+ name = Value("devname");
+ else
+ name = Value("cdev");
return (!name.empty());
}
diff --git a/sys/geom/eli/g_eli.c b/sys/geom/eli/g_eli.c
index fd64556..ee7f12f 100644
--- a/sys/geom/eli/g_eli.c
+++ b/sys/geom/eli/g_eli.c
@@ -210,6 +210,16 @@ g_eli_crypto_rerun(struct cryptop *crp)
return (error);
}
+static void
+g_eli_getattr_done(struct bio *bp)
+{
+ if (bp->bio_error == 0 &&
+ !strcmp(bp->bio_attribute, "GEOM::physpath")) {
+ strlcat(bp->bio_data, "/eli", bp->bio_length);
+ }
+ g_std_done(bp);
+}
+
/*
* The function is called afer reading encrypted data from the provider.
*
@@ -378,7 +388,10 @@ g_eli_start(struct bio *bp)
case BIO_FLUSH:
case BIO_DELETE:
case BIO_ZONE:
- cbp->bio_done = g_std_done;
+ if (bp->bio_cmd == BIO_GETATTR)
+ cbp->bio_done = g_eli_getattr_done;
+ else
+ cbp->bio_done = g_std_done;
cp = LIST_FIRST(&sc->sc_geom->consumer);
cbp->bio_to = cp->provider;
G_ELI_LOGREQ(2, cbp, "Sending request.");
diff --git a/sys/geom/part/g_part.c b/sys/geom/part/g_part.c
index 51202d8..dd75b37 100644
--- a/sys/geom/part/g_part.c
+++ b/sys/geom/part/g_part.c
@@ -268,6 +268,35 @@ g_part_geometry(struct g_part_table *table, struct g_consumer *cp,
}
}
+static void
+g_part_get_physpath_done(struct bio *bp)
+{
+ struct g_geom *gp;
+ struct g_part_entry *entry;
+ struct g_part_table *table;
+ struct g_provider *pp;
+ struct bio *pbp;
+
+ pbp = bp->bio_parent;
+ pp = pbp->bio_to;
+ gp = pp->geom;
+ table = gp->softc;
+ entry = pp->private;
+
+ if (bp->bio_error == 0) {
+ char *end;
+ size_t len, remainder;
+ len = strlcat(bp->bio_data, "/", bp->bio_length);
+ if (len < bp->bio_length) {
+ end = bp->bio_data + len;
+ remainder = bp->bio_length - len;
+ G_PART_NAME(table, entry, end, remainder);
+ }
+ }
+ g_std_done(bp);
+}
+
+
#define DPRINTF(...) if (bootverbose) { \
printf("GEOM_PART: " __VA_ARGS__); \
}
@@ -2157,6 +2186,7 @@ g_part_start(struct bio *bp)
struct g_part_table *table;
struct g_kerneldump *gkd;
struct g_provider *pp;
+ void (*done_func)(struct bio *) = g_std_done;
char buf[64];
pp = bp->bio_to;
@@ -2209,6 +2239,10 @@ g_part_start(struct bio *bp)
if (g_handleattr_str(bp, "PART::type",
G_PART_TYPE(table, entry, buf, sizeof(buf))))
return;
+ if (!strcmp("GEOM::physpath", bp->bio_attribute)) {
+ done_func = g_part_get_physpath_done;
+ break;
+ }
if (!strcmp("GEOM::kerneldump", bp->bio_attribute)) {
/*
* Check that the partition is suitable for kernel
@@ -2245,7 +2279,7 @@ g_part_start(struct bio *bp)
g_io_deliver(bp, ENOMEM);
return;
}
- bp2->bio_done = g_std_done;
+ bp2->bio_done = done_func;
g_io_request(bp2, cp);
}
diff --git a/tests/sys/geom/class/Makefile b/tests/sys/geom/class/Makefile
index b633fd0..950a03e 100644
--- a/tests/sys/geom/class/Makefile
+++ b/tests/sys/geom/class/Makefile
@@ -7,10 +7,9 @@ TESTSDIR= ${TESTSBASE}/sys/geom/class
TESTS_SUBDIRS+= concat
TESTS_SUBDIRS+= eli
TESTS_SUBDIRS+= gate
-# XXX: might not work due to geom(4) changes; more investigation's needed
-#TESTS_SUBDIRS+= gpt
TESTS_SUBDIRS+= mirror
TESTS_SUBDIRS+= nop
+TESTS_SUBDIRS+= part
TESTS_SUBDIRS+= raid3
TESTS_SUBDIRS+= shsec
TESTS_SUBDIRS+= stripe
diff --git a/tests/sys/geom/class/eli/Makefile b/tests/sys/geom/class/eli/Makefile
index 2acf3c4..6e34b3e 100644
--- a/tests/sys/geom/class/eli/Makefile
+++ b/tests/sys/geom/class/eli/Makefile
@@ -14,6 +14,7 @@ ATF_TESTS_SH+= detach_test
ATF_TESTS_SH+= init_test
ATF_TESTS_SH+= integrity_test
ATF_TESTS_SH+= kill_test
+ATF_TESTS_SH+= misc_test
ATF_TESTS_SH+= onetime_test
ATF_TESTS_SH+= resize_test
ATF_TESTS_SH+= setkey_test
diff --git a/tests/sys/geom/class/eli/misc_test.sh b/tests/sys/geom/class/eli/misc_test.sh
new file mode 100644
index 0000000..2dd60a4
--- /dev/null
+++ b/tests/sys/geom/class/eli/misc_test.sh
@@ -0,0 +1,177 @@
+# Copyright (c) 2018 Alan Somers
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+atf_test_case preserve_props cleanup
+preserve_props_head()
+{
+ atf_set "descr" "geli should preserve basic GEOM properties"
+ atf_set "require.user" "root"
+ atf_set "timeout" 15
+}
+preserve_props_body()
+{
+ . $(atf_get_srcdir)/conf.sh
+ md=$(attach_md -s1m)
+ atf_check geli onetime /dev/${md}
+ md_secsize=$(diskinfo ${md} | cut -wf 2)
+ md_stripesize=$(diskinfo ${md} | cut -wf 5)
+ eli_secsize=$(diskinfo ${md}.eli | cut -wf 2)
+ eli_stripesize=$(diskinfo ${md}.eli | cut -wf 5)
+ atf_check_equal "$md_secsize" "$eli_secsize"
+ atf_check_equal "$md_stripesize" "$eli_stripesize"
+}
+preserve_props_cleanup()
+{
+ . $(atf_get_srcdir)/conf.sh
+ geli_test_cleanup
+}
+
+atf_test_case preserve_disk_props cleanup
+preserve_disk_props_head()
+{
+ atf_set "descr" "geli should preserve properties for disks"
+ atf_set "require.user" "root"
+ atf_set "require.config" "disks"
+ atf_set "timeout" 15
+}
+preserve_disk_props_body()
+{
+ . $(atf_get_srcdir)/conf.sh
+ disks=`atf_config_get disks`
+ disk=${disks%% *}
+ if [ -z "$disk" ]; then
+ atf_skip "Must define disks (see tests(7))"
+ fi
+ atf_check geli onetime ${disk}
+
+ disk_ident=$(diskinfo -s ${disk})
+ disk_descr=$(diskinfo -v ${disk} | awk '/Disk descr/ {print $1}')
+ disk_rotrate=$(diskinfo -v ${disk} | awk '/Rotation rate/ {print $1}')
+ disk_zonemode=$(diskinfo -v ${disk} | awk '/Zone Mode/ {print $1}')
+ eli_ident=$(diskinfo -s ${disk}.eli)
+ eli_descr=$(diskinfo -v ${disk}.eli | awk '/Disk descr/ {print $1}')
+ eli_rotrate=$(diskinfo -v ${disk}.eli | awk '/Rotation/ {print $1}')
+ eli_zonemode=$(diskinfo -v ${disk}.eli | awk '/Zone Mode/ {print $1}')
+ atf_check_equal "$disk_ident" "$eli_ident"
+ atf_check_equal "$disk_descr" "$eli_descr"
+ atf_check_equal "$disk_rotrate" "$eli_rotrate"
+ atf_check_equal "$disk_zonemode" "$eli_zonemode"
+}
+preserve_disk_props_cleanup()
+{
+ . $(atf_get_srcdir)/conf.sh
+ disk_cleanup
+ geli_test_cleanup
+}
+
+atf_test_case physpath cleanup
+physpath_head()
+{
+ atf_set "descr" "geli should append /eli to the underlying device's physical path"
+ atf_set "require.user" "root"
+ atf_set "timeout" 15
+}
+physpath_body()
+{
+ . $(atf_get_srcdir)/conf.sh
+ load_gnop
+
+ md=$(attach_md -s1m)
+ # If the underlying device has no physical path, then geli should not
+ # create one.
+ atf_check -o empty -e ignore diskinfo -p $md
+ atf_check -s exit:0 geli onetime $md
+ atf_check -o empty -e ignore diskinfo -p $md.eli
+ atf_check -s exit:0 geli kill $md
+
+ # If the underlying device does have a physical path, then geli should
+ # append "/eli"
+ physpath="some/physical/path"
+ atf_check gnop create -z $physpath ${md}
+ atf_check -s exit:0 geli onetime $md.nop
+ atf_check -o match:"^${physpath}/eli$" diskinfo -p $md.nop.eli
+}
+physpath_cleanup()
+{
+ . $(atf_get_srcdir)/conf.sh
+
+ if [ -f "$TEST_MDS_FILE" ]; then
+ while read md; do
+ [ -c /dev/${md}.nop.eli ] && \
+ geli detach $md.nop.eli 2>/dev/null
+ [ -c /dev/${md}.nop ] && \
+ gnop destroy -f $md.nop 2>/dev/null
+ [ -c /dev/${md}.eli ] && \
+ geli detach $md.eli 2>/dev/null
+ mdconfig -d -u $md 2>/dev/null
+ done < $TEST_MDS_FILE
+ fi
+ true
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case physpath
+ atf_add_test_case preserve_props
+ atf_add_test_case preserve_disk_props
+}
+
+
+common_cleanup()
+{
+
+ if [ -f "$MD_DEVS" ]; then
+ while read test_md; do
+ gnop destroy -f ${test_md}.nop 2>/dev/null
+ mdconfig -d -u $test_md 2>/dev/null
+ done < $MD_DEVS
+ rm $MD_DEVS
+ fi
+
+ if [ -f "$PLAINFILES" ]; then
+ while read f; do
+ rm -f ${f}
+ done < ${PLAINFILES}
+ rm ${PLAINFILES}
+ fi
+ true
+}
+
+disk_cleanup()
+{
+ disks=`atf_config_get disks`
+ disk=${disks%% *}
+ if [ -n "$disk" ]; then
+ geli kill ${disk} 2>/dev/null
+ fi
+}
+
+load_gnop()
+{
+ if ! kldstat -q -m g_nop; then
+ geom nop load || atf_skip "could not load module for geom nop"
+ fi
+}
diff --git a/tests/sys/geom/class/part/Makefile b/tests/sys/geom/class/part/Makefile
new file mode 100644
index 0000000..21ecbec
--- /dev/null
+++ b/tests/sys/geom/class/part/Makefile
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+PACKAGE= tests
+
+TESTSDIR= ${TESTSBASE}/sys/geom/class/${.CURDIR:T}
+
+# TODO: port the perl tests in tools/regression/geom_gpt
+ATF_TESTS_SH+= misc
+
+.include <bsd.test.mk>
diff --git a/tests/sys/geom/class/part/misc.sh b/tests/sys/geom/class/part/misc.sh
new file mode 100644
index 0000000..3574579
--- /dev/null
+++ b/tests/sys/geom/class/part/misc.sh
@@ -0,0 +1,187 @@
+# Copyright (c) 2018 Alan Somers
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+MD_DEVS="md.devs"
+
+atf_test_case blank_physpath cleanup
+blank_physpath_head()
+{
+ atf_set "descr" "gpart shouldn't add physical paths to underlying providers that have none"
+ atf_set "require.user" "root"
+}
+blank_physpath_body()
+{
+ load_gnop
+ load_gpart
+ md=$(alloc_md)
+ atf_check -o empty -e ignore diskinfo -p ${md}
+ atf_check -s exit:0 -o ignore gpart create -s bsd ${md}
+ atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}
+ atf_check -o empty -e ignore diskinfo -p ${md}a
+}
+blank_physpath_cleanup()
+{
+ common_cleanup
+}
+
+
+atf_test_case bsd_physpath cleanup
+bsd_physpath_head()
+{
+ atf_set "descr" "BSD partitions should append /X to the underlying device's physical path"
+ atf_set "require.user" "root"
+}
+bsd_physpath_body()
+{
+ load_gnop
+ load_gpart
+ md=$(alloc_md)
+ physpath="some/physical/path"
+ atf_check gnop create -z $physpath /dev/${md}
+ atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nop
+ atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nop
+ gpart_physpath=$(diskinfo -p ${md}.nopa)
+ atf_check_equal "${physpath}/a" "$gpart_physpath"
+}
+bsd_physpath_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case gpt_physpath cleanup
+gpt_physpath_head()
+{
+ atf_set "descr" "GPT partitions should append /pX to the underlying device's physical path"
+ atf_set "require.user" "root"
+}
+gpt_physpath_body()
+{
+ load_gnop
+ load_gpart
+ md=$(alloc_md)
+ physpath="some/physical/path"
+ atf_check gnop create -z $physpath /dev/${md}
+ atf_check -s exit:0 -o ignore gpart create -s gpt ${md}.nop
+ atf_check -s exit:0 -o ignore gpart add -t efi ${md}.nop
+ gpart_physpath=$(diskinfo -p ${md}.nopp1)
+ atf_check_equal "${physpath}/p1" "$gpart_physpath"
+}
+gpt_physpath_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case mbr_physpath cleanup
+mbr_physpath_head()
+{
+ atf_set "descr" "MBR partitions should append /sX to the underlying device's physical path"
+ atf_set "require.user" "root"
+}
+mbr_physpath_body()
+{
+ load_gnop
+ load_gpart
+ md=$(alloc_md)
+ physpath="some/physical/path"
+ atf_check gnop create -z $physpath /dev/${md}
+ atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop
+ atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop
+ gpart_physpath=$(diskinfo -p ${md}.nops1)
+ atf_check_equal "${physpath}/s1" "$gpart_physpath"
+}
+mbr_physpath_cleanup()
+{
+ common_cleanup
+}
+
+atf_test_case mbr_bsd_physpath cleanup
+mbr_bsd_physpath_head()
+{
+ atf_set "descr" "BSD partitions nested within MBR partitions should append /sX/Y to the underlying device's physical path"
+ atf_set "require.user" "root"
+}
+mbr_bsd_physpath_body()
+{
+ load_gnop
+ load_gpart
+ md=$(alloc_md)
+ physpath="some/physical/path"
+ atf_check gnop create -z $physpath /dev/${md}
+ atf_check -s exit:0 -o ignore gpart create -s mbr ${md}.nop
+ atf_check -s exit:0 -o ignore gpart add -t freebsd ${md}.nop
+ atf_check -s exit:0 -o ignore gpart create -s bsd ${md}.nops1
+ atf_check -s exit:0 -o ignore gpart add -t freebsd-ufs ${md}.nops1
+ gpart_physpath=$(diskinfo -p ${md}.nops1a)
+ atf_check_equal "${physpath}/s1/a" "$gpart_physpath"
+}
+mbr_bsd_physpath_cleanup()
+{
+ common_cleanup
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case blank_physpath
+ atf_add_test_case bsd_physpath
+ atf_add_test_case gpt_physpath
+ atf_add_test_case mbr_physpath
+ atf_add_test_case mbr_bsd_physpath
+}
+
+alloc_md()
+{
+ local md
+
+ md=$(mdconfig -a -t swap -s 1M) || atf_fail "mdconfig -a failed"
+ echo ${md} >> $MD_DEVS
+ echo ${md}
+}
+
+common_cleanup()
+{
+ if [ -f "$MD_DEVS" ]; then
+ while read test_md; do
+ gnop destroy -f ${test_md}.nop 2>/dev/null
+ mdconfig -d -u $test_md 2>/dev/null
+ done < $MD_DEVS
+ rm $MD_DEVS
+ fi
+ true
+}
+
+load_gpart()
+{
+ if ! kldstat -q -m g_part; then
+ geom part load || atf_skip "could not load module for geom part"
+ fi
+}
+
+load_gnop()
+{
+ if ! kldstat -q -m g_nop; then
+ geom nop load || atf_skip "could not load module for geom nop"
+ fi
+}
OpenPOWER on IntegriCloud