[Ocfs2-tools-commits] mfasheh commits r629 - in trunk/libo2dlm: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Feb 2 17:00:43 CST 2005


Author: mfasheh
Date: 2005-02-02 17:00:41 -0600 (Wed, 02 Feb 2005)
New Revision: 629

Modified:
   trunk/libo2dlm/include/o2dlm.h
   trunk/libo2dlm/o2dlm.c
   trunk/libo2dlm/o2dlm_err.et.in
   trunk/libo2dlm/o2dlm_test.c
Log:
* add support in libo2dlm for the new lvb stuff in dlmfs.



Modified: trunk/libo2dlm/include/o2dlm.h
===================================================================
--- trunk/libo2dlm/include/o2dlm.h	2005-02-02 19:44:41 UTC (rev 628)
+++ trunk/libo2dlm/include/o2dlm.h	2005-02-02 23:00:41 UTC (rev 629)
@@ -100,6 +100,26 @@
 errcode_t o2dlm_unlock(struct o2dlm_ctxt *ctxt,
 		       char *lockid);
 
+/* Read the LVB out of a lock.
+ * 'len' is the amount to read into 'lvb'
+ *
+ * We can only read LVB_MAX bytes out of the lock, even if you
+ * specificy a len larger than that.
+ * 
+ * If you want to know how much was read, then pass 'bytes_read'
+ */
+errcode_t o2dlm_read_lvb(struct o2dlm_ctxt *ctxt,
+			 char *lockid,
+			 char *lvb,
+			 unsigned int len,
+			 unsigned int *bytes_read);
+
+errcode_t o2dlm_write_lvb(struct o2dlm_ctxt *ctxt,
+			  char *lockid,
+			  const char *lvb,
+			  unsigned int len,
+			  unsigned int *bytes_written);
+
 /*
  * Unlocks all pending locks and frees the lock context.
  */

Modified: trunk/libo2dlm/o2dlm.c
===================================================================
--- trunk/libo2dlm/o2dlm.c	2005-02-02 19:44:41 UTC (rev 628)
+++ trunk/libo2dlm/o2dlm.c	2005-02-02 23:00:41 UTC (rev 629)
@@ -292,7 +292,7 @@
 		flags = O_RDONLY;
 		break;
 	case O2DLM_LEVEL_EXMODE:
-		flags = O_WRONLY;
+		flags = O_RDWR;
 		break;
 	default:
 		flags = 0;
@@ -458,6 +458,70 @@
 	return 0;
 }
 
+errcode_t o2dlm_read_lvb(struct o2dlm_ctxt *ctxt,
+			 char *lockid,
+			 char *lvb,
+			 unsigned int len,
+			 unsigned int *bytes_read)
+{
+	int fd, ret;
+	struct o2dlm_lock_res *lockres;
+
+	if (!ctxt || !lockid || !lvb)
+		return O2DLM_ET_INVALID_ARGS;
+
+	lockres = o2dlm_find_lock_res(ctxt, lockid);
+	if (!lockres)
+		return O2DLM_ET_UNKNOWN_LOCK;
+
+	fd = lockres->l_fd;
+
+	ret = lseek(fd, 0, SEEK_SET);
+	if (ret < 0)
+		return O2DLM_ET_SEEK;
+
+	ret = read(fd, lvb, len);
+	if (ret < 0)
+		return O2DLM_ET_LVB_READ;
+
+	if (bytes_read)
+		*bytes_read = ret;
+
+	return 0;
+}
+
+errcode_t o2dlm_write_lvb(struct o2dlm_ctxt *ctxt,
+			  char *lockid,
+			  const char *lvb,
+			  unsigned int len,
+			  unsigned int *bytes_written)
+{
+	int fd, ret;
+	struct o2dlm_lock_res *lockres;
+
+	if (!ctxt || !lockid || !lvb)
+		return O2DLM_ET_INVALID_ARGS;
+
+	lockres = o2dlm_find_lock_res(ctxt, lockid);
+	if (!lockres)
+		return O2DLM_ET_UNKNOWN_LOCK;
+
+	fd = lockres->l_fd;
+
+	ret = lseek(fd, 0, SEEK_SET);
+	if (ret < 0)
+		return O2DLM_ET_SEEK;
+
+	ret = write(fd, lvb, len);
+	if (ret < 0)
+		return O2DLM_ET_LVB_READ;
+
+	if (bytes_written)
+		*bytes_written = ret;
+
+	return 0;
+}
+
 static errcode_t o2dlm_unlink_all(struct o2dlm_ctxt *ctxt)
 {
 	int ret;

Modified: trunk/libo2dlm/o2dlm_err.et.in
===================================================================
--- trunk/libo2dlm/o2dlm_err.et.in	2005-02-02 19:44:41 UTC (rev 628)
+++ trunk/libo2dlm/o2dlm_err.et.in	2005-02-02 23:00:41 UTC (rev 629)
@@ -102,4 +102,13 @@
 ec	O2DLM_ET_TRYLOCK_FAILED,
 	"Trylock failed"
 
+ec	O2DLM_ET_LVB_READ,
+	"Error reading LVB"
+
+ec	O2DLM_ET_LVB_WRITE,
+	"Error writing LVB"
+
+ec      O2DLM_ET_SEEK,
+	"Could not seek within file descriptor"
+
 	end

Modified: trunk/libo2dlm/o2dlm_test.c
===================================================================
--- trunk/libo2dlm/o2dlm_test.c	2005-02-02 19:44:41 UTC (rev 628)
+++ trunk/libo2dlm/o2dlm_test.c	2005-02-02 23:00:41 UTC (rev 629)
@@ -34,6 +34,8 @@
 	LOCK,
 	TRYLOCK,
 	UNLOCK,
+	GETLVB,
+	SETLVB,
 	HELP,
 	NUM_COMMANDS
 };
@@ -44,6 +46,8 @@
         [LOCK]       "LOCK",
 	[TRYLOCK]    "TRYLOCK",
 	[UNLOCK]     "UNLOCK",
+	[GETLVB]     "GETLVB",
+	[SETLVB]     "SETLVB",
 	[HELP]       "HELP",
 };
 
@@ -69,6 +73,7 @@
 	char                  c_domain[O2DLM_DOMAIN_MAX_LEN];
 	char                  c_id[O2DLM_LOCK_ID_MAX_LEN];
 	enum o2dlm_lock_level c_level;
+	char                  *c_lvb;
 };
 
 static void print_commands(void)
@@ -81,6 +86,8 @@
 	printf("lock \"level\" \"lockid\"\n");
 	printf("trylock \"level\" \"lockid\"\n");
 	printf("unlock \"lockid\"\n");
+	printf("getlvb \"lockid\"\n");
+	printf("setlvb \"lockid\" \"lvb\"\n");
 }
 
 static int decode_type(struct command_s *c, char *buf)
@@ -165,9 +172,13 @@
 		else
 			printf("O2DLM_LEVEL_EXMODE ");
 		/* fall through */
+	case GETLVB:
 	case UNLOCK:
 		printf("\"%s\" %s\n", c->c_id, str);
 		break;
+	case SETLVB:
+		printf("\"%s\" \"%s\" %s\n", c->c_id, c->c_lvb, str);
+		break;
 	case HELP:
 		printf("%s\n", str);
 		break;
@@ -226,11 +237,26 @@
 		}
 
 		/* fall through */
+	case SETLVB:
+	case GETLVB:
 	case UNLOCK:
 		if (decode_lock(command, next)) {
 			fprintf(stderr, "Invalid lock \"%s\"\n", next);
 			goto again;
 		}
+
+		if (command->c_type == SETLVB) {
+			/* for setlvb we want to get a pointer to the
+			 * start of the string to stuff */
+			next = strtok(NULL, "\n");
+			if (!next) {
+				fprintf(stderr, "invalid input!\n");
+				goto again;
+			}
+
+			kill_return(next);
+			command->c_lvb = next;
+		}
 		break;
 	default:
 		fprintf(stderr, "whoa, can't parse this\n");
@@ -238,9 +264,13 @@
 	return 0;
 }
 
+#define LVB_LEN 64
+static char lvb_buf[LVB_LEN];
+
 static errcode_t exec_command(struct command_s *c)
 {
 	errcode_t ret = 0;
+	unsigned int bytes, len;
 
 	switch (c->c_type) {
 	case REGISTER:
@@ -259,6 +289,23 @@
 	case TRYLOCK:
 		ret = o2dlm_lock(dlm_ctxt, c->c_id, O2DLM_TRYLOCK, c->c_level);
 		break;
+	case GETLVB:
+		ret = o2dlm_read_lvb(dlm_ctxt, c->c_id, lvb_buf, LVB_LEN,
+				     &bytes);
+		if (!ret) {
+			printf("%u bytes read. LVB begins on following "
+			       "line and is terminated by a newline\n",
+			       bytes);
+			printf("%.*s\n", bytes, lvb_buf);
+		}
+		break;
+	case SETLVB:
+		len = strlen(c->c_lvb);
+		ret = o2dlm_write_lvb(dlm_ctxt, c->c_id, c->c_lvb, len,
+				      &bytes);
+		if (!ret)
+			printf("%u bytes written.\n", bytes);
+		break;
 	case HELP:
 	default:
 		print_commands();
@@ -284,6 +331,8 @@
 		printf("Using fs at %s\n", dlmfs_path);
 	}
 
+	printf("Type \"help\" to see a list of commands\n");
+
 	while (!get_command(&c)) {
 		error = exec_command(&c);
 



More information about the Ocfs2-tools-commits mailing list