[Ocfs2-tools-commits] jlbec commits r534 - in branches/kabi/libo2cb: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Jan 4 20:45:25 CST 2005


Author: jlbec
Date: 2005-01-04 20:45:23 -0600 (Tue, 04 Jan 2005)
New Revision: 534

Added:
   branches/kabi/libo2cb/include/o2cb_kabi.h
Modified:
   branches/kabi/libo2cb/Makefile
   branches/kabi/libo2cb/include/o2cb_abi.h
   branches/kabi/libo2cb/o2cb_abi.c
   branches/kabi/libo2cb/o2cb_err.et.in
Log:
o Add first KABI work

Modified: branches/kabi/libo2cb/Makefile
===================================================================
--- branches/kabi/libo2cb/Makefile	2005-01-05 02:42:14 UTC (rev 533)
+++ branches/kabi/libo2cb/Makefile	2005-01-05 02:45:23 UTC (rev 534)
@@ -43,6 +43,7 @@
 	include/ocfs2_heartbeat.h	\
 	include/ocfs2_nodemanager.h	\
 	include/ocfs2_tcp.h.h		\
+	include/o2cb_kabi.h		\
 	include/o2cb_abi.h		\
 	include/o2cb.h
 

Modified: branches/kabi/libo2cb/include/o2cb_abi.h
===================================================================
--- branches/kabi/libo2cb/include/o2cb_abi.h	2005-01-05 02:42:14 UTC (rev 533)
+++ branches/kabi/libo2cb/include/o2cb_abi.h	2005-01-05 02:45:23 UTC (rev 534)
@@ -29,6 +29,7 @@
 #define O2CB_CLUSTER_FILE 	"/proc/cluster/nm/.cluster"
 #define O2CB_GROUP_FILE		"/proc/cluster/nm/.group"
 #define O2CB_NODE_FILE		"/proc/cluster/nm/.node"
+#define O2CB_LIVE_FILE		"/proc/cluster/nm/.live"
 #define O2CB_NETWORKING_FILE	"/proc/cluster/net"
 
 #endif  /* _O2CB_ABI_H */

Added: branches/kabi/libo2cb/include/o2cb_kabi.h
===================================================================
--- branches/kabi/libo2cb/include/o2cb_kabi.h	2005-01-05 02:42:14 UTC (rev 533)
+++ branches/kabi/libo2cb/include/o2cb_kabi.h	2005-01-05 02:45:23 UTC (rev 534)
@@ -0,0 +1,131 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * o2cb_kabi.h
+ *
+ * Header describing the generic interface bits between userspace and 
+ * he kernel for the O2CB stuff.
+ *
+ * Copyright (C) 2004 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2
+ * of the License.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#ifndef _O2CB_KABI_H
+#define _O2CB_KABI_H
+
+#define O2CB_KABI_V1		1U
+#define O2CB_KABI_VERSION	O2CB_KABI_V1
+#define O2CB_KABI_MAGIC		0x02CBCA75
+
+enum o2cb_kabi_operations
+{
+	O2CB_OP_NONE = 0,
+	O2CB_OP_CLUSTER_SET_LIVE,
+	O2CB_OP_CLUSTER_IS_LIVE,
+};
+
+enum o2cb_kabi_errors
+{
+	O2CB_KE_NONE = 0,
+	O2CB_KE_BAD_MAGIC,
+	O2CB_KE_INVALID_ABI_VERSION,
+	O2CB_KE_INVALID_REQUEST_SIZE,
+	O2CB_KE_INVALID_OPERATION,
+	O2CB_KE_CLUSTER_ALREADY_LIVE,
+	O2CB_KE_NOT_SUPPORTED,
+};
+
+struct o2cb_kabi_info {
+/*00*/	__u32	ki_magic;	/* O2CB_KABI_MAGIC */
+	__u16	ki_version;	/* ABI version */
+	__u16	ki_op;		/* Operation */
+	__u32	ki_size;	/* Size of passed structure */
+	__u32   ki_status;      /* Returns status code */
+/*10*/
+};
+
+struct o2cb_kabi_live {
+/*00*/	struct o2cb_kabi_info	kl_abi;
+/*10*/	__u32			kl_live;	/* 0 is DOWN */
+/*14*/
+};
+
+/**
+ * o2cb_kabi_verify(k, member, size)
+ * @k:		An O2CB KABI object embedding a struct o2cb_kabi_info.
+ * @member:	The name of the struct o2cb_kabi_info member.
+ * @size:	The expected size passed in to ->write().
+ *
+ * For example, if you had:
+ *
+ * struct o2cb_kabi_start_cluster {
+ * 	struct o2cb_kabi_info	sc_abi;
+ * 	__u32			sc_start;
+ * };
+ *
+ * You would verify this structure with:
+ *
+ * struct o2cb_kabi_start_cluster *sc;
+ * o2cb_kabi_verify(sc, sc_abi, size);
+ *
+ * Along with verifying the magic value in ki_magic and the ABI version
+ * in ki_version, this function verifies that
+ * ki_size == size == sizeof(*k).  Make sure that 'size' is the size
+ * passed to ->write().  If you simply use sizeof(*k), you aren't
+ * getting anything from that verification step.
+ *
+ * If 'size' is bad, -EINVAL is returned.  Otherwise, the caller
+ * must check ki_status for any ABI errors.
+ */
+#define o2cb_kabi_verify(k, member, size) ({ \
+	typeof(k) _k = (k);					\
+	struct o2cb_kabi_info *_i = &(_k->member);		\
+	int _rc = 						\
+	(_i->ki_size != (size)) ? -EINVAL :			\
+	((_i->ki_magic != O2CB_KABI_MAGIC) ?			\
+	 O2CB_KE_BAD_MAGIC :					\
+	 ((_i->ki_version != O2CB_KABI_VERSION) ?		\
+	  O2CB_KE_INVALID_ABI_VERSION :				\
+	  ((_i->ki_size != sizeof(typeof(*_k))) ?		\
+	   O2CB_KE_INVALID_REQUEST_SIZE : 0)));			\
+	if (_rc != -EINVAL) {					\
+		_i->ki_status = _rc;				\
+		_rc = 0;					\
+	}							\
+	_rc;							\
+})
+
+/**
+ * o2cb_kabi_verify(k, member, size)
+ * @k:		An O2CB KABI object embedding a struct o2cb_kabi_info.
+ * @member:	The name of the struct o2cb_kabi_info member.
+ * @op:		The ABI operation.
+ *
+ * Fills the struct o2cb_kabi_info part of the structure with the
+ * appropriate magic numbers and sizes.
+ */
+#define o2cb_kabi_init(k, member, op) ({ \
+	typeof(k) _k = (k);				\
+	struct o2cb_kabi_info *_i = &(_k->member);	\
+	_i->ki_magic = O2CB_KABI_MAGIC;			\
+	_i->ki_version = O2CB_KABI_VERSION;		\
+	_i->ki_op = (op);				\
+	_i->ki_size = sizeof(typeof(*_k));		\
+	_i->ki_status = 0;				\
+})
+
+#endif  /* _O2CB_KABI_H */

Modified: branches/kabi/libo2cb/o2cb_abi.c
===================================================================
--- branches/kabi/libo2cb/o2cb_abi.c	2005-01-05 02:42:14 UTC (rev 533)
+++ branches/kabi/libo2cb/o2cb_abi.c	2005-01-05 02:45:23 UTC (rev 534)
@@ -39,6 +39,7 @@
 
 #include "o2cb.h"
 
+#include "o2cb_kabi.h"
 #include "o2cb_abi.h"
 
 errcode_t o2cb_set_cluster_name(const char *cluster_name)
@@ -148,34 +149,26 @@
 errcode_t o2cb_activate_cluster()
 {
 	errcode_t ret;
-	int fd, rc, page_size = getpagesize();
-	char *buf;
-	nm_op *op;
+	int fd, rc;
+	struct o2cb_kabi_live kl;
 
-	buf = malloc(sizeof(char*) * page_size);
-	if (!buf)
-		return O2CB_ET_NO_MEMORY;
+	o2cb_kabi_init(&kl, kl_abi, O2CB_OP_CLUSTER_SET_LIVE);
 
-	op = (nm_op *)buf;
-	op->magic = NM_OP_MAGIC;
-	op->opcode = NM_OP_CREATE_CLUSTER;
-
 	ret = O2CB_ET_SERVICE_UNAVAILABLE;
-	fd = open(O2CB_CLUSTER_FILE, O_RDWR);
+	fd = open(O2CB_LIVE_FILE, O_RDWR);
 	if (fd < 0)
-		goto out;
+		return ret;
 
-	rc = write(fd, op, sizeof(nm_op));
+	kl.kl_live = 1;
+	rc = write(fd, &kl, sizeof(struct o2cb_kabi_live));
 	if (rc < 0)
 		goto out_close;
 
 	ret = O2CB_ET_IO;
-	if (rc < sizeof(nm_op))
+	if (rc < sizeof(struct o2cb_kabi_live))
 		goto out_close;
 
-	memset(buf, 0, page_size);
-
-	rc = read(fd, buf, page_size);
+	rc = read(fd, &kl, sizeof(struct o2cb_kabi_live));
 	if (rc < 0)
 		goto out_close;
 
@@ -183,14 +176,19 @@
 	if (!rc)
 		goto out_close;
 
-	ret = O2CB_ET_IO;  /* FIXME */
-	if (buf[0] == '0')
+	ret = O2CB_ET_IO;
+	if (rc < sizeof(struct o2cb_kabi_live))
+		goto out_close;
+
+	if (kl.kl_abi.ki_status == O2CB_KE_CLUSTER_ALREADY_LIVE)
+		ret = O2CB_ET_CLUSTER_ALREADY_ACTIVE;
+	else if (kl.kl_abi.ki_status)
+		ret = O2CB_ET_INTERNAL_FAILURE;
+	else
 		ret = 0;
 
 out_close:
 	close(fd);
-out:
-	free(buf);
 
 	return ret;
 }  /* o2cb_activate_cluster() */

Modified: branches/kabi/libo2cb/o2cb_err.et.in
===================================================================
--- branches/kabi/libo2cb/o2cb_err.et.in	2005-01-05 02:42:14 UTC (rev 533)
+++ branches/kabi/libo2cb/o2cb_err.et.in	2005-01-05 02:45:23 UTC (rev 534)
@@ -39,4 +39,7 @@
 ec	O2CB_ET_INTERNAL_FAILURE,
 	"Internal logic failure"
 
+ec	O2CB_ET_CLUSTER_ALREADY_ACTIVE,
+	"The cluster is already active, no changes can be made"
+
 	end



More information about the Ocfs2-tools-commits mailing list