[Ocfs2-tools-commits] mfasheh commits r598 - trunk/libo2dlm

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Jan 26 15:53:41 CST 2005


Author: mfasheh
Date: 2005-01-26 15:53:39 -0600 (Wed, 26 Jan 2005)
New Revision: 598

Modified:
   trunk/libo2dlm/o2dlm.c
   trunk/libo2dlm/o2dlm_err.et.in
Log:
* check that the dlmfs path is a directory

* use an internal function for locking so that we may bypass the check for  
  reserved lock names when creating them.



Modified: trunk/libo2dlm/o2dlm.c
===================================================================
--- trunk/libo2dlm/o2dlm.c	2005-01-26 21:51:35 UTC (rev 597)
+++ trunk/libo2dlm/o2dlm.c	2005-01-26 21:53:39 UTC (rev 598)
@@ -41,6 +41,11 @@
 
 #define USER_DLMFS_MAGIC	0x76a9f425
 
+static errcode_t o2dlm_lock_nochecks(struct o2dlm_ctxt *ctxt,
+				     const char *lockid,
+				     int lockflags,
+				     enum o2dlm_lock_level level);
+
 static errcode_t o2dlm_generate_random_value(int64_t *value)
 {
 	int randfd = 0;
@@ -111,14 +116,34 @@
 
 static errcode_t o2dlm_check_user_dlmfs(const char *dlmfs_path)
 {
-	struct statfs stat;
-	int ret;
+	struct statfs statfs_buf;
+	struct stat stat_buf;
+	int ret, fd;
 
-	ret = statfs(dlmfs_path, &stat);
-	if (ret)
+	fd = open(dlmfs_path, O_RDONLY);
+	if (fd < 0)
+		return O2DLM_ET_OPEN_DLM_DIR;
+
+	ret = fstat(fd, &stat_buf);
+	if (ret) {
+		close(fd);
 		return O2DLM_ET_STATFS;
+	}
 
-	if (stat.f_type != USER_DLMFS_MAGIC)
+	if (!S_ISDIR(stat_buf.st_mode)) {
+		close(fd);
+		return O2DLM_ET_NO_FS_DIR;
+	}
+
+	ret = fstatfs(fd, &statfs_buf);
+	if (ret) {
+		close(fd);
+		return O2DLM_ET_STATFS;
+	}
+
+	close(fd);
+
+	if (statfs_buf.f_type != USER_DLMFS_MAGIC)
 		return O2DLM_ET_NO_FS;
 
 	return 0;
@@ -214,7 +239,8 @@
 	 * open for the duration of this context. This way if another
 	 * process won't be able to shut down this domain underneath
 	 * us. */
-	ret = o2dlm_lock(ctxt, ctxt->ct_ctxt_lock_name, 0, O2DLM_LEVEL_PRMODE);
+	ret = o2dlm_lock_nochecks(ctxt, ctxt->ct_ctxt_lock_name, 0,
+				  O2DLM_LEVEL_PRMODE);
 	if (ret) {
 		if (dir_created)
 			o2dlm_delete_domain_dir(ctxt); /* best effort
@@ -301,22 +327,16 @@
 
 #define O2DLM_OPEN_MODE         0664
 
-errcode_t o2dlm_lock(struct o2dlm_ctxt *ctxt,
-		     const char *lockid,
-		     int lockflags,
-		     enum o2dlm_lock_level level)
+/* Use this internally to avoid the check for a reserved name */
+static errcode_t o2dlm_lock_nochecks(struct o2dlm_ctxt *ctxt,
+				     const char *lockid,
+				     int lockflags,
+				     enum o2dlm_lock_level level)
 {
 	int ret, flags, fd;
 	char *path;
 	struct o2dlm_lock_res *lockres;
 
-	if (!ctxt || !lockid)
-		return O2DLM_ET_INVALID_ARGS;
-
-	/* names starting with '.' are reserved. */
-	if (lockid[0] == '.')
-		return O2DLM_ET_INVALID_LOCK_NAME;
-
 	if (strlen(lockid) >= O2DLM_LOCK_ID_MAX_LEN)
 		return O2DLM_ET_INVALID_LOCK_NAME;
 
@@ -363,6 +383,21 @@
 	return 0;
 }
 
+errcode_t o2dlm_lock(struct o2dlm_ctxt *ctxt,
+		     const char *lockid,
+		     int lockflags,
+		     enum o2dlm_lock_level level)
+{
+	if (!ctxt || !lockid)
+		return O2DLM_ET_INVALID_ARGS;
+
+	/* names starting with '.' are reserved. */
+	if (lockid[0] == '.')
+		return O2DLM_ET_INVALID_LOCK_NAME;
+
+	return o2dlm_lock_nochecks(ctxt, lockid, lockflags, level);
+}
+
 static errcode_t o2dlm_unlock_lock_res(struct o2dlm_ctxt *ctxt,
 				      struct o2dlm_lock_res *lockres)
 {

Modified: trunk/libo2dlm/o2dlm_err.et.in
===================================================================
--- trunk/libo2dlm/o2dlm_err.et.in	2005-01-26 21:51:35 UTC (rev 597)
+++ trunk/libo2dlm/o2dlm_err.et.in	2005-01-26 21:53:39 UTC (rev 598)
@@ -45,9 +45,15 @@
 ec	O2DLM_ET_STATFS,
 	"Could not stat user_dlmfs mountpoint"
 
+ec	O2DLM_ET_NO_FS_DIR,
+	"Dlmfs path specified is not a directory."
+
 ec	O2DLM_ET_NO_FS,
 	"ocfs2_dlmfs file system was not found"
 
+ec	O2DLM_ET_OPEN_DLM_DIR,
+	"Could not open dlm directory"
+
 ec	O2DLM_ET_NO_DOMAIN_DIR,
 	"No directory for domain was found"
 



More information about the Ocfs2-tools-commits mailing list