[Ocfs2-tools-commits] jlbec commits r1375 -
branches/cman-based/ocfs2_controld
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri Aug 10 15:07:50 PDT 2007
Author: jlbec
Date: 2007-08-10 15:07:48 -0700 (Fri, 10 Aug 2007)
New Revision: 1375
Added:
branches/cman-based/ocfs2_controld/test_client.c
Modified:
branches/cman-based/ocfs2_controld/
branches/cman-based/ocfs2_controld/Makefile
branches/cman-based/ocfs2_controld/action.c
branches/cman-based/ocfs2_controld/client_proto.c
branches/cman-based/ocfs2_controld/main.c
branches/cman-based/ocfs2_controld/ocfs2_controld.h
branches/cman-based/ocfs2_controld/ocfs2_controld_internal.h
Log:
Fake mounting works. Fake unmounting, not so much. Somehow we're also
not filling out the heartbeat region.
Property changes on: branches/cman-based/ocfs2_controld
___________________________________________________________________
Name: svn:ignore
- .*.sw?
.*.d
ocfs2_controld
+ .*.sw?
.*.d
ocfs2_controld
test_client
Modified: branches/cman-based/ocfs2_controld/Makefile
===================================================================
--- branches/cman-based/ocfs2_controld/Makefile 2007-08-08 20:45:02 UTC (rev 1374)
+++ branches/cman-based/ocfs2_controld/Makefile 2007-08-10 22:07:48 UTC (rev 1375)
@@ -3,17 +3,16 @@
include $(TOPDIR)/Preamble.make
SBIN_PROGRAMS = ocfs2_controld
+UNINST_PROGRAMS = test_client
-#INCLUDES = -Iinclude -I$(TOPDIR)/libocfs2/include \
-# -I$(TOPDIR)/libo2cb/include -I$(TOPDIR)/libo2dlm/include
-#LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
-#LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
#LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
#LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
-INCLUDES = -I$(TOPDIR)/libo2dlm/include -I$(TOPDIR)/libo2cb/include
+INCLUDES = -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include -I$(TOPDIR)/libo2cb/include
LIBO2CB_LIBS = -L$(TOPDIR)/libo2cb -lo2cb
LIBO2CB_DEPS = $(TOPDIR)/libo2cb/libo2cb.a
+LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
+LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
ifdef OCFS2_DEBUG
OPTS += -ggdb
@@ -24,19 +23,34 @@
CFLAGS := $(OPTS) -Wall -Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations
-DEFINES = -DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
+DEFINES = -DOCFS2_FLAT_INCLUDES -DO2DLM_FLAT_INCLUDES \
+ -DO2CB_FLAT_INCLUDES -DVERSION=\"$(VERSION)\"
-CFILES = group.c main.c member_cman.c client_proto.c action.c
+PROTO_CFILES = client_proto.c
+DAEMON_CFILES = group.c main.c member_cman.c action.c
HFILES = ocfs2_controld.h
+UNINST_HFILES = ocfs2_controld_internal.h
-OBJS = $(subst .c,.o,$(CFILES))
-#MANS = ocfs2_dlm_controld
+TEST_CFILES = test_client.c
-DIST_FILES = $(CFILES) $(HFILES) $(addsuffix .in,$(MANS))
+DAEMON_OBJS = $(subst .c,.o,$(DAEMON_CFILES) $(PROTO_CFILES))
+TEST_OBJS = $(subst .c,.o,$(TEST_CFILES) $(PROTO_CFILES))
+MANS =
-ocfs2_controld: $(OBJS) $(LIBO2CB_DEPS)
+DIST_FILES = \
+ $(PROTO_CFILES) \
+ $(DAEMON_CFILES) \
+ $(TEST_CFILES) \
+ $(HFILES) \
+ $(UNINST_HFILES) \
+ $(addsuffix .in,$(MANS))
+
+ocfs2_controld: $(DAEMON_OBJS) $(LIBO2CB_DEPS)
$(LINK) $(LIBO2CB_LIBS) $(COM_ERR_LIBS) -lgroup -lcman
+test_client: $(TEST_OBJS) $(LIBO2CB_DEPS) $(LIBOCFS2_DEPS)
+ $(LINK) $(LIBOCFS2_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
+
include $(TOPDIR)/Postamble.make
Modified: branches/cman-based/ocfs2_controld/action.c
===================================================================
--- branches/cman-based/ocfs2_controld/action.c 2007-08-08 20:45:02 UTC (rev 1374)
+++ branches/cman-based/ocfs2_controld/action.c 2007-08-10 22:07:48 UTC (rev 1375)
@@ -33,19 +33,19 @@
enum mountgroup_state {
- MG_CREATED = 1 << 0,
- MG_JOIN_SENT = 1 << 1,
- MG_JOIN_START = 1 << 2,
- MG_JOIN_START_DONE = 1 << 3,
+ MG_CREATED = 0x0001,
+ MG_JOIN_SENT = 0x0002,
+ MG_JOIN_START = 0x0004,
+ MG_JOIN_START_DONE = 0x0008,
#define MG_JOINING (MG_JOIN_SENT | MG_JOIN_START | MG_JOIN_START_DONE)
- MG_JOINED = 1 << 4,
- MG_MOUNTED = 1 << 5,
+ MG_JOINED = 0x0010,
+ MG_MOUNTED = 0x0020,
#define MG_MEMBER (MG_JOINED | MG_MOUNTED)
- MG_LEAVE_SENT = 1 << 6,
- MG_LEAVE_START = 1 << 7,
- MG_LEAVE_START_DONE = 1 << 8,
+ MG_LEAVE_SENT = 0x0040,
+ MG_LEAVE_START = 0x0080,
+ MG_LEAVE_START_DONE = 0x0100,
#define MG_LEAVING (MG_LEAVE_SENT | MG_LEAVE_START | MG_LEAVE_START_DONE)
- MG_DEAD = 1 << 9,
+ MG_DEAD = 0x0200,
};
struct list_head mounts;
@@ -70,10 +70,17 @@
}
}
+static void mg_statechange(struct mountgroup *mg, enum mountgroup_state new)
+{
+ log_group(mg, "Changing from state 0x%x to 0x%x", mg->state, new);
+
+ mg->state = new;
+}
+
static int mg_statep(struct mountgroup *mg, enum mountgroup_state test,
enum mountgroup_state allowed)
{
- if (mg->state == test)
+ if (mg->state & test)
return 1;
if (allowed) {
@@ -104,11 +111,11 @@
if (mg->error_msg[0]) {
error_msg = mg->error_msg;
} else
- error_msg = strerror(-error);
+ error_msg = strerror(error);
mg->error = 0;
}
- log_group(mg, "notify_mount_client sending %d \"%s\"", -error,
+ log_group(mg, "notify_mount_client sending %d \"%s\"", error,
error_msg);
error = send_message(mg->mount_client_fd, CM_STATUS, error,
@@ -185,14 +192,14 @@
mountpoint, device, ci);
if (strcmp(mg->device, device)) {
- fill_error(mg, -EINVAL,
+ fill_error(mg, EINVAL,
"Trying to mount fs %s on device %s, but it already is mounted from device %s",
mg->uuid, mg->device, device);
goto out;
}
if (find_mountpoint(mg, mountpoint, 0)) {
- fill_error(mg, -EBUSY,
+ fill_error(mg, EBUSY,
"Filesystem %s is already mounted on %s",
mg->uuid, mountpoint);
goto out;
@@ -204,7 +211,7 @@
}
if (create_mountpoint(mg, mountpoint, ci)) {
- fill_error(mg, -ENOMEM,
+ fill_error(mg, ENOMEM,
"Unable to allocate mountpoint structure");
goto out;
}
@@ -216,7 +223,7 @@
* the mount is a secondary one and no additional work is required.
* It will just call mount(2).
*/
- fill_error(mg, -EALREADY, "Kernel mounted, go ahead");
+ fill_error(mg, EALREADY, "Kernel mounted, go ahead");
out:
return;
@@ -248,7 +255,7 @@
memset(mg, 0, sizeof(struct mountgroup));
INIT_LIST_HEAD(&mg->members);
INIT_LIST_HEAD(&mg->mountpoints);
- mg->state = MG_CREATED;
+ mg_statechange(mg, MG_CREATED);
strncpy(mg->uuid, uuid, sizeof(mg->uuid));
if (create_mountpoint(mg, mountpoint, ci)) {
@@ -270,24 +277,25 @@
};
struct mountgroup *mg = &mg_error;
+ fprintf(stderr, "%d \"%s\"\n", strlen(uuid), uuid);
log_debug("mount: MOUNT %s %s %s %s %s",
fstype, uuid, cluster, device, mountpoint);
if (strcmp(fstype, "ocfs2")) {
- fill_error(mg, -EINVAL, "Unsupported fstype: %s", fstype);
+ fill_error(mg, EINVAL, "Unsupported fstype: %s", fstype);
goto out;
}
if (!strlen(cluster) || (strlen(cluster) != strlen(clustername)) ||
strcmp(cluster, clustername)) {
- fill_error(mg, -EINVAL,
+ fill_error(mg, EINVAL,
"Request for mount in cluster %s but we belong to %s",
cluster, clustername);
goto out;
}
if (strlen(uuid) > MAXNAME) {
- fill_error(mg, -ENAMETOOLONG, "UUID too long: %s", uuid);
+ fill_error(mg, ENAMETOOLONG, "UUID too long: %s", uuid);
goto out;
}
@@ -301,7 +309,7 @@
mg = create_mg(uuid, mountpoint, ci);
if (!mg) {
mg = &mg_error; /* Well, almost */
- fill_error(mg, -ENOMEM,
+ fill_error(mg, ENOMEM,
"Unable to allocate mountgroup structure");
goto out;
}
@@ -314,7 +322,7 @@
rc = group_join(gh, (char *)uuid);
if (rc) {
- fill_error(mg, -errno, "Unable to start group join: %s",
+ fill_error(mg, errno, "Unable to start group join: %s",
strerror(errno));
/*
@@ -325,7 +333,7 @@
goto out;
}
- mg->state = MG_JOIN_SENT;
+ mg_statechange(mg, MG_JOIN_SENT);
*mg_ret = mg;
log_group(mg, "mount successfully started");
@@ -336,11 +344,11 @@
* until join completes (notify_mount_client()).
*/
if (mg->error) {
- rc = mg->error;
+ rc = -mg->error;
send_message(fd, CM_STATUS, mg->error, mg->error_msg);
/* -EALREADY magic is sent, clear it */
- if (mg->error == -EALREADY)
+ if (mg->error == EALREADY)
mg->error = 0;
else {
log_error("mount: %s", mg->error_msg);
@@ -363,28 +371,29 @@
const char *errcode, const char *mountpoint)
{
int rc = 0;
+ int reply_fd = mg->mount_client_fd;
int reply = 1;
char *ptr = NULL;
long err;
- log_debug("mount: MRESULT %s %s %s %s",
+ log_debug("mresult: MRESULT %s %s %s %s",
fstype, uuid, errcode, mountpoint);
assert(mg->mount_client == ci);
assert(!mg->error);
if (strcmp(fstype, "ocfs2")) {
- fill_error(mg, -EINVAL, "Unsupported fstype: %s", fstype);
+ fill_error(mg, EINVAL, "Unsupported fstype: %s", fstype);
goto out;
}
if (strlen(uuid) > MAXNAME) {
- fill_error(mg, -ENAMETOOLONG, "UUID too long: %s", uuid);
+ fill_error(mg, ENAMETOOLONG, "UUID too long: %s", uuid);
goto out;
}
if (strcmp(uuid, mg->uuid)) {
- fill_error(mg, -EINVAL,
+ fill_error(mg, EINVAL,
"UUID %s does not match mountgroup %s", uuid,
mg->uuid);
goto out;
@@ -394,13 +403,13 @@
err = strtol(errcode, &ptr, 10);
if (ptr && *ptr != '\0') {
- fill_error(mg, -EINVAL, "Invalid error code string: %s",
+ fill_error(mg, EINVAL, "Invalid error code string: %s",
errcode);
goto out;
}
if ((err == LONG_MIN) || (err == LONG_MAX) || (err < INT_MIN) ||
(err > INT_MAX)) {
- fill_error(mg, -ERANGE, "Error code %ld out of range", err);
+ fill_error(mg, ERANGE, "Error code %ld out of range", err);
goto out;
}
@@ -421,6 +430,7 @@
if (!err) {
/* Everyone's happy */
+ mg_statechange(mg, MG_MOUNTED);
mg->mount_client = 0;
mg->mount_client_fd = 0;
@@ -444,14 +454,14 @@
}
if (group_leave(gh, mg->uuid))
- fill_error(mg, -errno, "Unable to start group leave: %s",
+ fill_error(mg, errno, "Unable to start group leave: %s",
strerror(errno));
else
- mg->state = MG_LEAVE_SENT;
+ mg_statechange(mg, MG_LEAVE_SENT);
out:
if (reply)
- send_message(mg->mount_client_fd, CM_STATUS, mg->error,
+ send_message(reply_fd, CM_STATUS, mg->error,
mg->error ? mg->error_msg : "OK");
return rc;
@@ -472,13 +482,13 @@
fstype, uuid, mountpoint);
if (strcmp(fstype, "ocfs2")) {
- fill_error(&mg_error, -EINVAL, "Unsupported fstype: %s",
+ fill_error(&mg_error, EINVAL, "Unsupported fstype: %s",
fstype);
goto out;
}
if (strlen(uuid) > MAXNAME) {
- fill_error(&mg_error, -ENAMETOOLONG, "UUID too long: %s",
+ fill_error(&mg_error, ENAMETOOLONG, "UUID too long: %s",
uuid);
goto out;
}
@@ -486,7 +496,7 @@
/* Once we have our mg, we're done with &mg_error */
mg = find_mg(uuid);
if (!mg) {
- fill_error(&mg_error, -ENOENT, "Unknown uuid %s", uuid);
+ fill_error(&mg_error, ENOENT, "Unknown uuid %s", uuid);
goto out;
}
@@ -495,7 +505,7 @@
mp = find_mountpoint(mg, mountpoint, 0);
if (!mp) {
- fill_error(&mg_error, -ENOENT,
+ fill_error(&mg_error, ENOENT,
"Filesystem %s is not mounted on %s", uuid,
mountpoint);
goto out;
@@ -525,6 +535,7 @@
* we get to MG_MEMBER, but let's be safe
*/
if (!mg_statep(mg, MG_MEMBER, MG_MEMBER)) {
+ log_group(mg, "Postponing leave, state is 0x%x", mg->state);
mg->group_leave_on_finish = 1;
goto out;
}
@@ -533,15 +544,17 @@
/* We spoke too soon! */
/* XXX How can a client clean this up? */
reply = 1;
- fill_error(&mg_error, -errno, "Unable to leave group: %s",
+ fill_error(&mg_error, errno, "Unable to leave group: %s",
strerror(errno));
} else
- mg->state = MG_LEAVE_SENT;
+ mg_statechange(mg, MG_LEAVE_SENT);
out:
if (reply)
send_message(fd, CM_STATUS, mg_error.error,
mg_error.error ? mg_error.error_msg : "OK");
+ if (mg_error.error)
+ rc = -mg_error.error;
return rc;
}
@@ -806,9 +819,9 @@
int *nodeids)
{
if (mg_statep(mg, MG_JOIN_SENT, MG_MEMBER | MG_LEAVE_SENT))
- mg->state = MG_JOIN_START;
+ mg_statechange(mg, MG_JOIN_START);
else if (mg_statep(mg, MG_LEAVE_SENT, MG_MEMBER | MG_JOIN_SENT))
- mg->state = MG_LEAVE_START;
+ mg_statechange(mg, MG_LEAVE_START);
mg->start_event_nr = mg->last_start;
mg->start_type = type;
@@ -829,9 +842,9 @@
out:
group_start_done(gh, mg->uuid, mg->start_event_nr);
if (mg_statep(mg, MG_JOIN_START, MG_MEMBER | MG_LEAVE_START))
- mg->state = MG_JOIN_START_DONE;
+ mg_statechange(mg, MG_JOIN_START_DONE);
else if (mg_statep(mg, MG_LEAVE_START, MG_MEMBER | MG_JOIN_START))
- mg->state = MG_LEAVE_START_DONE;
+ mg_statechange(mg, MG_LEAVE_START_DONE);
}
void do_finish(struct mountgroup *mg)
@@ -839,7 +852,7 @@
log_group(mg, "finish called");
if (mg_statep(mg, MG_JOIN_START_DONE, MG_MEMBER)) {
- mg->state = MG_JOINED;
+ mg_statechange(mg, MG_JOINED);
if (!mg->error) {
assert(!mg->group_leave_on_finish);
notify_mount_client(mg);
@@ -870,7 +883,7 @@
log_error("group_leave(%s) failed: %s",
mg->uuid, strerror(errno));
else
- mg->state = MG_LEAVE_SENT;
+ mg_statechange(mg, MG_LEAVE_SENT);
mg->group_leave_on_finish = 0;
}
}
@@ -883,7 +896,7 @@
log_error("terminate called from state %d for group %s",
mg->state, mg->uuid);
- mg->state = MG_DEAD;
+ mg_statechange(mg, MG_DEAD);
if (mg->mount_client)
notify_mount_client(mg);
@@ -909,3 +922,29 @@
list_del(&mg->list);
free(mg);
}
+
+void dump_state(void)
+{
+ struct list_head *mgp, *mpp;
+ struct mountgroup *mg;
+ struct mountpoint *mp;
+
+ list_for_each(mgp, &mounts) {
+ mg = list_entry(mgp, struct mountgroup, list);
+ log_group(mg, "Cluster \"%s\", Device \"%s\"", mg->cluster,
+ mg->device);
+ log_group(mg, "Last (stop %d) (start %d) (finish %d)",
+ mg->last_stop, mg->last_start, mg->last_finish);
+ log_group(mg, "start_event_nr %d, start_type %d",
+ mg->start_event_nr, mg->start_type);
+ log_group(mg, "error %d, error_msg \"%s\"",
+ mg->error, mg->error ? mg->error_msg : "");
+ log_group(mg, "mount_client %d, mount_client_fd %d",
+ mg->mount_client, mg->mount_client_fd);
+ list_for_each(mpp, &mg->mountpoints) {
+ mp = list_entry(mpp, struct mountpoint, list);
+ log_group(mg, "Mountpoint \"%s\", client %d",
+ mp->mountpoint, mp->client);
+ }
+ }
+}
Modified: branches/cman-based/ocfs2_controld/client_proto.c
===================================================================
--- branches/cman-based/ocfs2_controld/client_proto.c 2007-08-08 20:45:02 UTC (rev 1374)
+++ branches/cman-based/ocfs2_controld/client_proto.c 2007-08-10 22:07:48 UTC (rev 1375)
@@ -41,6 +41,11 @@
DEFINE_MESSAGE(STATUS, 2, "%d %s")
END_MESSAGES(message_list)
+const char *message_to_string(client_message message)
+{
+ return message_list[message].cm_command;
+}
+
/* No short reads allowed */
static int full_read(int fd, void *buf, size_t count)
{
@@ -91,6 +96,7 @@
va_list args;
char mbuf[OCFS2_CONTROLD_MAXLINE];
+ memset(mbuf, 0, OCFS2_CONTROLD_MAXLINE);
va_start(args, message);
rc = vsnprintf(mbuf, OCFS2_CONTROLD_MAXLINE,
message_list[message].cm_format, args);
@@ -144,26 +150,26 @@
return rp;
}
-int receive_message_full(int fd, client_message *message, char **argv,
- char **rest)
+int receive_message_full(int fd, char *buf, client_message *message,
+ char **argv, char **rest)
{
int i, rc, len, count;
client_message msg;
char *r;
- char mbuf[OCFS2_CONTROLD_MAXLINE];
- rc = full_read(fd, mbuf, OCFS2_CONTROLD_MAXLINE);
+ rc = full_read(fd, buf, OCFS2_CONTROLD_MAXLINE);
if (rc)
goto out;
/* Safety first */
- mbuf[OCFS2_CONTROLD_MAXLINE - 1] = '\0';
+ buf[OCFS2_CONTROLD_MAXLINE - 1] = '\0';
+ fprintf(stderr, "Got messsage \"%s\"\n", buf);
for (i = 0; i < message_list_len; i++) {
len = strlen(message_list[i].cm_command);
- if (!strncmp(mbuf, message_list[i].cm_command, len) &&
- (mbuf[len] == ' '))
+ if (!strncmp(buf, message_list[i].cm_command, len) &&
+ (buf[len] == ' '))
break;
}
if (i >= message_list_len) {
@@ -172,11 +178,13 @@
}
msg = i;
- r = get_args(mbuf, &count, argv, ' ',
+ r = get_args(buf, &count, argv, ' ',
message_list[msg].cm_argcount);
if (count != message_list[msg].cm_argcount) {
rc = -EBADMSG;
} else {
+ for (i = 0; i < count; i++)
+ fprintf(stderr, "Arg %d: \"%s\"\n", i, argv[i]);
if (message)
*message = msg;
if (rest)
@@ -187,9 +195,9 @@
return rc;
}
-int receive_message(int fd, client_message *message, char **argv)
+int receive_message(int fd, char *buf, client_message *message, char **argv)
{
- return receive_message_full(fd, message, argv, NULL);
+ return receive_message_full(fd, buf, message, argv, NULL);
}
int client_listen(void)
@@ -237,8 +245,10 @@
int rv, fd;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
- if (fd < 0)
+ if (fd < 0) {
+ fd = -errno;
goto out;
+ }
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
@@ -248,7 +258,7 @@
rv = connect(fd, (struct sockaddr *) &sun, addrlen);
if (rv < 0) {
close(fd);
- fd = rv;
+ fd = -errno;
}
out:
return fd;
Modified: branches/cman-based/ocfs2_controld/main.c
===================================================================
--- branches/cman-based/ocfs2_controld/main.c 2007-08-08 20:45:02 UTC (rev 1374)
+++ branches/cman-based/ocfs2_controld/main.c 2007-08-10 22:07:48 UTC (rev 1375)
@@ -207,14 +207,12 @@
{
struct mountgroup *mg;
client_message message;
- char out[OCFS2_CONTROLD_MAXLINE];
char *argv[OCFS2_CONTROLD_MAXARGS + 1];
+ char buf[OCFS2_CONTROLD_MAXLINE];
int rv, fd = client[ci].fd;
- memset(out, 0, OCFS2_CONTROLD_MAXLINE);
-
/* receive_message ensures we have the proper number of arguments */
- rv = receive_message(fd, &message, argv);
+ rv = receive_message(fd, buf, &message, argv);
if (rv == -EPIPE) {
client_dead(ci);
return 0;
@@ -225,7 +223,8 @@
return rv;
}
- log_debug("client message %d: %d", ci, message);
+ log_debug("client message %d from %d: %s", message, ci,
+ message_to_string(message));
switch (message) {
case CM_MOUNT:
@@ -261,19 +260,10 @@
log_error("Invalid message received");
break;
}
+ if (daemon_debug_opt)
+ dump_state();
#if 0
- } else if (!strcmp(cmd, "mount_result")) {
- got_mount_result(client[ci].mg, atoi(argv[3]), ci,
- client[ci].another_mount);
- } else if (!strcmp(cmd, "leave")) {
- rv = do_unmount(ci, argv[1], atoi(argv[3]));
- goto reply;
-
- } else if (!strcmp(cmd, "remount")) {
- rv = do_remount(ci, argv[1], argv[3]);
- goto reply;
-
} else if (!strcmp(cmd, "dump")) {
dump_debug(ci);
@@ -540,7 +530,7 @@
char *prog_name;
int daemon_debug_opt;
-char daemon_debug_buf[256];
+char daemon_debug_buf[1024];
char dump_buf[DUMP_SIZE];
int dump_point;
int dump_wrap;
Modified: branches/cman-based/ocfs2_controld/ocfs2_controld.h
===================================================================
--- branches/cman-based/ocfs2_controld/ocfs2_controld.h 2007-08-08 20:45:02 UTC (rev 1374)
+++ branches/cman-based/ocfs2_controld/ocfs2_controld.h 2007-08-10 22:07:48 UTC (rev 1375)
@@ -40,9 +40,11 @@
int client_listen(void);
int client_connect(void);
+const char *message_to_string(client_message message);
int send_message(int fd, client_message message, ...);
-int receive_message(int fd, client_message *message, char **argv);
-int receive_message_full(int fd, client_message *message, char **argv,
- char **rest);
+int receive_message(int fd, char *buf, client_message *message,
+ char **argv);
+int receive_message_full(int fd, char *buf, client_message *message,
+ char **argv, char **rest);
#endif
Modified: branches/cman-based/ocfs2_controld/ocfs2_controld_internal.h
===================================================================
--- branches/cman-based/ocfs2_controld/ocfs2_controld_internal.h 2007-08-08 20:45:02 UTC (rev 1374)
+++ branches/cman-based/ocfs2_controld/ocfs2_controld_internal.h 2007-08-10 22:07:48 UTC (rev 1375)
@@ -80,7 +80,7 @@
extern int our_nodeid;
extern group_handle_t gh;
extern int daemon_debug_opt;
-extern char daemon_debug_buf[256];
+extern char daemon_debug_buf[1024];
extern char dump_buf[DUMP_SIZE];
extern int dump_point;
extern int dump_wrap;
@@ -89,14 +89,16 @@
#define log_debug(fmt, args...) \
do { \
- snprintf(daemon_debug_buf, 255, "%ld " fmt "\n", time(NULL), ##args); \
+ snprintf(daemon_debug_buf, 1023, "%ld %s@%d: " fmt "\n", \
+ time(NULL), __FUNCTION__, __LINE__, ##args); \
if (daemon_debug_opt) fprintf(stderr, "%s", daemon_debug_buf); \
daemon_dump_save(); \
} while (0)
#define log_group(g, fmt, args...) \
do { \
- snprintf(daemon_debug_buf, 255, "%ld %s " fmt "\n", time(NULL), \
+ snprintf(daemon_debug_buf, 1023, "%ld %s@%d %s " fmt "\n", \
+ time(NULL), __FUNCTION__, __LINE__, \
(g)->uuid, ##args); \
if (daemon_debug_opt) fprintf(stderr, "%s", daemon_debug_buf); \
daemon_dump_save(); \
@@ -152,9 +154,6 @@
int group_leave_on_finish;
int remount_client;
int state;
- int got_our_options;
- int got_our_journals;
- int delay_send_journals;
int kernel_mount_error;
int kernel_mount_done;
int got_kernel_mount;
@@ -253,4 +252,6 @@
void update_flow_control_status(void);
+void dump_state(void);
+
#endif
Added: branches/cman-based/ocfs2_controld/test_client.c
===================================================================
--- branches/cman-based/ocfs2_controld/test_client.c 2007-08-08 20:45:02 UTC (rev 1374)
+++ branches/cman-based/ocfs2_controld/test_client.c 2007-08-10 22:07:48 UTC (rev 1375)
@@ -0,0 +1,335 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2007 Oracle. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <mntent.h>
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+
+#include "o2cb.h"
+#include "ocfs2_fs.h"
+#include "ocfs2.h"
+#include "ocfs2_controld.h"
+
+#define OCFS2_FSTYPE "ocfs2"
+
+
+static int parse_status(char **args, int *error, char **error_msg)
+{
+ int rc = 0;
+ long err;
+ char *ptr = NULL;
+
+ err = strtol(args[0], &ptr, 10);
+ if (ptr && *ptr != '\0') {
+ fprintf(stderr, "Invalid error code string: %s", args[0]);
+ rc = -EINVAL;
+ } else if ((err == LONG_MIN) || (err == LONG_MAX) ||
+ (err < INT_MIN) || (err > INT_MAX)) {
+ fprintf(stderr, "Error code %ld out of range", err);
+ rc = -ERANGE;
+ } else {
+ *error_msg = args[1];
+ *error = err;
+ }
+
+ return rc;
+}
+
+static errcode_t fill_uuid(const char *device, char *uuid)
+{
+ errcode_t err;
+ ocfs2_filesys *fs;
+ struct o2cb_region_desc desc;
+
+ err = ocfs2_open(device, OCFS2_FLAG_RO, 0, 0, &fs);
+ if (err)
+ goto out;
+
+ err = ocfs2_fill_heartbeat_desc(fs, &desc);
+ ocfs2_close(fs);
+
+ if (!err)
+ strncpy(uuid, desc.r_name, OCFS2_VOL_UUID_LEN + 1);
+out:
+ return err;
+}
+
+static int call_mount(int fd, const char *uuid, const char *cluster,
+ const char *device, const char *mountpoint)
+{
+ int rc;
+ int error;
+ char *error_msg;
+ client_message message;
+ char *argv[OCFS2_CONTROLD_MAXARGS + 1];
+ char buf[OCFS2_CONTROLD_MAXLINE];
+
+ rc = send_message(fd, CM_MOUNT, OCFS2_FSTYPE, uuid, cluster,
+ device, mountpoint);
+ if (rc) {
+ fprintf(stderr, "Unable to send MOUNT message: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+
+ rc = receive_message(fd, buf, &message, argv);
+ if (rc < 0) {
+ fprintf(stderr, "Error reading from daemon: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+
+ switch (message) {
+ case CM_STATUS:
+ rc = parse_status(argv, &error, &error_msg);
+ if (rc) {
+ fprintf(stderr, "Bad status message: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+ if (error && (error != EALREADY)) {
+ rc = -error;
+ fprintf(stderr,
+ "Error %d from daemon: %s\n",
+ error, error_msg);
+ goto out;
+ }
+ break;
+
+ default:
+ rc = -EINVAL;
+ fprintf(stderr,
+ "Unexpected message %s from daemon\n",
+ message_to_string(message));
+ goto out;
+ break;
+ }
+
+ /* XXX Here we fake mount */
+ /* rc = mount(...); */
+ rc = 0;
+
+ rc = send_message(fd, CM_MRESULT, OCFS2_FSTYPE, uuid, rc,
+ mountpoint);
+ if (rc) {
+ fprintf(stderr, "Unable to send MRESULT message: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+
+ rc = receive_message(fd, buf, &message, argv);
+ if (rc < 0) {
+ fprintf(stderr, "Error reading from daemon: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+
+ switch (message) {
+ case CM_STATUS:
+ rc = parse_status(argv, &error, &error_msg);
+ if (rc) {
+ fprintf(stderr, "Bad status message: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+ if (error) {
+ rc = -error;
+ fprintf(stderr,
+ "Error %d from daemon: %s\n",
+ error, error_msg);
+ }
+ break;
+
+ default:
+ rc = -EINVAL;
+ fprintf(stderr,
+ "Unexpected message %s from daemon\n",
+ message_to_string(message));
+ break;
+ }
+
+out:
+ return rc;
+}
+
+static int call_unmount(int fd, const char *uuid, const char *mountpoint)
+{
+ int rc = 0;
+ int error;
+ char *error_msg;
+ client_message message;
+ char *argv[OCFS2_CONTROLD_MAXARGS + 1];
+ char buf[OCFS2_CONTROLD_MAXLINE];
+#if 0
+ errcode_t err;
+ FILE *mntfile;
+ struct mntent *entp;
+ char device[PATH_MAX + 1];
+ char uuid[OCFS2_VOL_UUID_LEN + 1];
+
+ device[0] = '\0';
+
+ mntfile = setmntent("/tmp/fakemtab", "r");
+ if (!mntfile) {
+ rc = -errno;
+ fprintf(stderr, "Unable to open mtab: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+
+ while ((entp = getmntent(mntfile)) != NULL) {
+ if (strcmp(entp->mnt_type, OCFS2_FSTYPE))
+ continue;
+ if (strcmp(entp->mnt_type, mountpoint))
+ continue;
+ strncpy(device, entp->mnt_fsname, PATH_MAX);
+ }
+ endmntent(mntfile);
+
+ if (!*device) {
+ rc = -ENOENT;
+ fprintf(stderr, "Unable to find filesystem %s\n",
+ mountpoint);
+ goto out;
+ }
+
+ err = fill_uuid(device, uuid);
+ if (err) {
+ com_err("test_client", err,
+ "while trying to read uuid from %s", device);
+ rc = -EIO;
+ goto out;
+ }
+#endif
+
+ rc = send_message(fd, CM_UNMOUNT, OCFS2_FSTYPE, uuid, mountpoint);
+ if (rc) {
+ fprintf(stderr, "Unable to send UNMOUNT message: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+
+ rc = receive_message(fd, buf, &message, argv);
+ if (rc < 0) {
+ fprintf(stderr, "Error reading from daemon: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+
+ switch (message) {
+ case CM_STATUS:
+ rc = parse_status(argv, &error, &error_msg);
+ if (rc) {
+ fprintf(stderr, "Bad status message: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+ if (error) {
+ rc = -error;
+ fprintf(stderr,
+ "Error %d from daemon: %s\n",
+ error, error_msg);
+ goto out;
+ }
+ break;
+
+ default:
+ rc = -EINVAL;
+ fprintf(stderr,
+ "Unexpected message %s from daemon\n",
+ message_to_string(message));
+ goto out;
+ break;
+ }
+
+out:
+ return rc;
+}
+
+enum {
+ OP_MOUNT,
+ OP_UMOUNT,
+};
+static int parse_options(int argc, char **argv, int *op, char ***args)
+{
+ int rc = 0;
+
+ if (argc < 2) {
+ fprintf(stderr, "Operation required\n");
+ return -EINVAL;
+ }
+
+ if (!strcmp(argv[1], "mount")) {
+ if (argc == 6) {
+ *op = OP_MOUNT;
+ *args = argv + 2;
+ } else {
+ fprintf(stderr, "Invalid number of arguments\n");
+ rc = -EINVAL;
+ }
+ } else if (!strcmp(argv[1], "umount")) {
+ if (argc == 4) {
+ *op = OP_UMOUNT;
+ *args = argv + 2;
+ } else {
+ fprintf(stderr, "Invalid number of arguments\n");
+ rc = -EINVAL;
+ }
+ } else {
+ fprintf(stderr, "Invalid operation: %s\n", argv[1]);
+ rc = -EINVAL;
+ }
+
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ int rc, fd, op;
+ char **args;
+
+ rc = parse_options(argc, argv, &op, &args);
+ if (rc)
+ goto out;
+
+ rc = client_connect();
+ if (rc < 0) {
+ fprintf(stderr, "Unable to connect to ocfs2_controld: %s\n",
+ strerror(-rc));
+ goto out;
+ }
+ fd = rc;
+
+ switch (op) {
+ case OP_MOUNT:
+ rc = call_mount(fd, args[0], args[1], args[2],
+ args[3]);
+ break;
+
+ case OP_UMOUNT:
+ rc = call_unmount(fd, args[0], args[1]);
+ break;
+
+ default:
+ fprintf(stderr, "Can't get here!\n");
+ rc = -ENOTSUP;
+ break;
+ }
+
+ close(fd);
+
+out:
+ return rc;
+}
More information about the Ocfs2-tools-commits
mailing list