changeset 3660:1532d6e91300

6520627 TSlvm sometimes gets NORESULT in snv_58
author cth
date Thu, 15 Feb 2007 11:12:06 -0800
parents 7e9e2f60e9c9
children 42a018c1e567
files usr/src/cmd/devfsadm/devfsadm.c usr/src/lib/libdevinfo/devinfo_devlink.c
diffstat 2 files changed, 19 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/devfsadm/devfsadm.c	Thu Feb 15 10:33:09 2007 -0800
+++ b/usr/src/cmd/devfsadm/devfsadm.c	Thu Feb 15 11:12:06 2007 -0800
@@ -2323,8 +2323,6 @@
 		vprint(INITFINI_MID, "minor_fini sync done\n");
 
 		(void) mutex_lock(&minor_fini_mutex);
-		minor_fini_canceled = TRUE;
-		minor_fini_delayed = FALSE;
 	}
 }
 
--- a/usr/src/lib/libdevinfo/devinfo_devlink.c	Thu Feb 15 10:33:09 2007 -0800
+++ b/usr/src/lib/libdevinfo/devinfo_devlink.c	Thu Feb 15 11:12:06 2007 -0800
@@ -119,7 +119,6 @@
  * walks through every link in the link segment.
  *
  */
-
 di_devlink_handle_t
 di_devlink_open(const char *root_dir, uint_t flags)
 {
@@ -140,15 +139,14 @@
 	err = open_db(hdp, OPEN_RDONLY);
 
 	/*
-	 * Unlink the database, so that consumers don't get
-	 * out of date information as the database is being updated.
-	 *
-	 * NOTE: A typical snapshot consumer will wait until write lock
-	 * obtained by handle_alloc above is dropped by handle_free,
-	 * at which point the file will have been recreated.
+	 * We don't want to unlink the db at this point - if we did we
+	 * would be creating a window where consumers would take a slow
+	 * code path (and those consumers might also trigger requests for
+	 * db creation, which we are already in the process of doing).
+	 * When we are done with our update, we use rename to install the
+	 * latest version of the db file.
 	 */
 	get_db_path(hdp, DB_FILE, path, sizeof (path));
-	(void) unlink(path);
 
 	/*
 	 * The flags argument is reserved for future use.
@@ -357,7 +355,7 @@
 	/*
 	 * Lock database if a read-write handle is being allocated.
 	 * Locks are needed to protect against multiple writers.
-	 * Readers lock/unlock in di_devlink_snapshot.
+	 * Readers don't need locks.
 	 */
 	if (HDL_RDWR(&proto)) {
 		if (enter_db_lock(&proto, root_dir) != 1) {
@@ -1936,44 +1934,34 @@
 devlink_snapshot(const char *root_dir)
 {
 	struct di_devlink_handle *hdp;
-	int	locked;
-	int	err;
-	int	retried = 0;
+	int		err;
+	static int	retried = 0;
 
 	if ((hdp = handle_alloc(root_dir, OPEN_RDONLY)) == NULL) {
 		return (NULL);
 	}
 
 	/*
-	 * Enter the DB lock.  This will wait for update in progress and
-	 * provide exclusion from new updates while we establish our mmap
-	 * to the database contents.
+	 * We don't need to lock.  If a consumer wants the very latest db
+	 * then he must perform a di_devlink_init with the DI_MAKE_LINK
+	 * flag to force a sync with devfsadm first.  Otherwise, the
+	 * current database file is opened and mmaped on demand: the rename
+	 * associated with a db update does not change the contents
+	 * of files already opened.
 	 */
-again:	locked = enter_db_lock(hdp, root_dir);
-	if (locked == -1) {
-		handle_free(&hdp);
-		return (NULL);
-	} else if (locked == 1) {
-		/* Open the DB and exit the lock. */
-		err = open_db(hdp, OPEN_RDONLY);
-		exit_db_lock(hdp);
-	} else
-		return (hdp);		/* walk /dev in di_devlink_walk */
+again:	err = open_db(hdp, OPEN_RDONLY);
 
 	/*
 	 * If we failed to open DB the most likely cause is that DB file did
 	 * not exist. If we have not done a retry, signal devfsadmd to
-	 * recreate the DB file and retry.
-	 *
-	 * If we fail to open the DB with retry, we will walk /dev
-	 * in di_devlink_walk.
+	 * recreate the DB file and retry. If we fail to open the DB after
+	 * retry, we will walk /dev in di_devlink_walk.
 	 */
 	if (err && (retried == 0)) {
 		retried++;
 		(void) devlink_create(root_dir, NULL, DCA_DEVLINK_SYNC);
 		goto again;
 	}
-
 	return (hdp);
 }
 
@@ -3033,7 +3021,7 @@
 	char		lockfile[PATH_MAX];
 	int		rv;
 	int		writer = HDL_RDWR(hdp);
-	int		did_sync = 0;
+	static int	did_sync = 0;
 	int		eintrs;
 
 	assert(hdp->lock_fd < 0);