svn commit: r256451 - projects/zfsd/head/cddl/sbin/zfsd

Alan Somers asomers at FreeBSD.org
Mon Oct 14 20:51:52 UTC 2013


Author: asomers
Date: Mon Oct 14 20:51:51 2013
New Revision: 256451
URL: http://svnweb.freebsd.org/changeset/base/256451

Log:
  Move parsing policy for invalid GUIDs into the Guid class.
  
          cddl/sbin/zfsd/guid.cc:
          cddl/sbin/zfsd/guid.h:
                  o Allow a Guid to be constructed from a string.  The empty
                    string is treated as an invalid Guid.
                  o Rename NONE_FLAG to INVALID_GUID to clarify its meaning.
                    The concept of a Guid being "none" only applies in certain
                    contexts like reading a spare label.
  
          cddl/sbin/zfsd/dev_ctl_event.cc:
                  Modify ZfsEvent's constructor  to just use Guid's string
                  contructor instead of embedding logic to manually create
                  invalid guids when these nvpairs do not exist.
  
          stable/cddl/sbin/zfsd/vdev.cc:
                  Rely on Guid's default constructor creating an invalid
                  guid to simplify the handling of pool GUIDs parsed from
                  a label.  This also fixes a vdev/pool guid variable mixup
                  bug that, due to Guid's default construction, had no ill
                  effects.
  
  Submitted by:	gibbs
  Approved by:	ken (mentor)
  Sponsored By:	Spectra Logic Corporation

Modified:
  projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc
  projects/zfsd/head/cddl/sbin/zfsd/guid.cc
  projects/zfsd/head/cddl/sbin/zfsd/guid.h
  projects/zfsd/head/cddl/sbin/zfsd/vdev.cc

Modified: projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc	Mon Oct 14 18:31:15 2013	(r256450)
+++ projects/zfsd/head/cddl/sbin/zfsd/dev_ctl_event.cc	Mon Oct 14 20:51:51 2013	(r256451)
@@ -692,24 +692,10 @@ ZfsEvent::Process() const
 //- ZfsEvent Protected Methods -------------------------------------------------
 ZfsEvent::ZfsEvent(DevCtlEvent::Type type, NVPairMap &nvpairs,
 		   const string &eventString)
- : DevCtlEvent(type, nvpairs, eventString)
+ : DevCtlEvent(type, nvpairs, eventString),
+   m_poolGUID(Guid(Value("pool_guid"))),
+   m_vdevGUID(Guid(Value("vdev_guid")))
 {
-	/*
-	 * These are zero on conversion failure as will happen if
-	 * Value returns the empty string.
-	 */
-	if (Contains("pool_guid")) {
-		m_poolGUID = (uint64_t)strtoumax(Value("pool_guid").c_str(),
-		    NULL, 0);
-	}
-	else
-		m_poolGUID = Guid();
-	if (Contains("vdev_guid")) {
-		m_vdevGUID = (uint64_t)strtoumax(Value("vdev_guid").c_str(),
-		    NULL, 0);
-	}
-	else
-		m_vdevGUID = Guid();
 }
 
 ZfsEvent::ZfsEvent(const ZfsEvent &src)

Modified: projects/zfsd/head/cddl/sbin/zfsd/guid.cc
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/guid.cc	Mon Oct 14 18:31:15 2013	(r256450)
+++ projects/zfsd/head/cddl/sbin/zfsd/guid.cc	Mon Oct 14 20:51:51 2013	(r256451)
@@ -49,8 +49,24 @@
 #include "guid.h"
 
 __FBSDID("$FreeBSD$");
+/*============================ Namespace Control =============================*/
+using std::string;
+
 /*=========================== Class Implementations ==========================*/
 /*----------------------------------- Guid -----------------------------------*/
+Guid::Guid(const string &guidString)
+{
+	if (guidString.empty()) {
+		m_GUID = INVALID_GUID;
+	} else {
+		/*
+		 * strtoumax() returns zero on conversion failure
+		 * which nicely matches our choice for INVALID_GUID.
+		 */
+		m_GUID = (uint64_t)strtoumax(guidString.c_str(), NULL, 0);
+	}
+}
+
 std::ostream&
 operator<< (std::ostream& out, Guid g)
 {

Modified: projects/zfsd/head/cddl/sbin/zfsd/guid.h
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/guid.h	Mon Oct 14 18:31:15 2013	(r256450)
+++ projects/zfsd/head/cddl/sbin/zfsd/guid.h	Mon Oct 14 20:51:51 2013	(r256451)
@@ -46,11 +46,11 @@
  * \brief Object that represents guids.
  *
  * It can generally be manipulated as a uint64_t, but with a special
- * value "None" that does not equal any valid guid.
+ * value INVALID_GUID that does not equal any valid guid.
  * 
  * As of this writing, spa_generate_guid() in spa_misc.c explicitly
- * refuses to return a guid of 0.  So this class uses 0 as a flag
- * value for "None".  In the future, if 0 is allowed to be a valid
+ * refuses to return a guid of 0.  So this class uses 0 as the value
+ * for INVALID_GUID.  In the future, if 0 is allowed to be a valid
  * guid, the implementation of this class must change.
  */
 class Guid
@@ -59,6 +59,7 @@ public:
 	/* Constructors */
 	Guid();
 	Guid(uint64_t guid);
+	Guid(const std::string &guid);
 
 	/* Assignment */
 	Guid& operator=(const Guid& rhs);
@@ -74,16 +75,16 @@ public:
 	operator uint64_t()		 const;
 	operator bool()			 const;
 
-	static const uint64_t NONE_FLAG = 0;
+	static const uint64_t INVALID_GUID = 0;
 protected:
-	/* The stored value.  0 is a flag for "None" */
+	/* The integer value of the GUID. */
 	uint64_t  m_GUID;
 };
 
 //- Guid Inline Public Methods ------------------------------------------------
 inline
 Guid::Guid()
-  : m_GUID(NONE_FLAG)
+  : m_GUID(INVALID_GUID)
 {
 }
 
@@ -103,7 +104,7 @@ Guid::operator=(const Guid &rhs)
 inline bool
 Guid::IsValid() const
 {
-	return (m_GUID != NONE_FLAG);
+	return (m_GUID != INVALID_GUID);
 }
 
 inline bool
@@ -127,7 +128,7 @@ Guid::operator uint64_t() const
 inline
 Guid::operator bool() const
 {
-	return (m_GUID != NONE_FLAG);
+	return (m_GUID != INVALID_GUID);
 }
 
 /** Convert the GUID into its string representation */

Modified: projects/zfsd/head/cddl/sbin/zfsd/vdev.cc
==============================================================================
--- projects/zfsd/head/cddl/sbin/zfsd/vdev.cc	Mon Oct 14 18:31:15 2013	(r256450)
+++ projects/zfsd/head/cddl/sbin/zfsd/vdev.cc	Mon Oct 14 20:51:51 2013	(r256451)
@@ -89,10 +89,15 @@ Vdev::Vdev(nvlist_t *labelConfig)
  : m_poolConfig(labelConfig)
 {
 	uint64_t raw_guid;
+
+	/*
+	 * Spares do not have a Pool GUID.  Tolerate its absence.
+	 * Code accessing this Vdev in a context where the Pool GUID is
+	 * required will find it invalid (as it is upon Vdev construction)
+	 * and act accordingly.
+	 */
 	if (nvlist_lookup_uint64(labelConfig, ZPOOL_CONFIG_POOL_GUID,
-				 &raw_guid) != 0)
-		m_vdevGUID = Guid();
-	else
+				 &raw_guid) == 0)
 		m_poolGUID = raw_guid;
 
 	if (nvlist_lookup_uint64(labelConfig, ZPOOL_CONFIG_GUID,


More information about the svn-src-projects mailing list