[Ocfs2-tools-commits] manish commits r240 - trunk/ocfs2cdsl
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Sep 16 18:33:53 CDT 2004
Author: manish
Date: 2004-09-16 18:33:51 -0500 (Thu, 16 Sep 2004)
New Revision: 240
Modified:
trunk/ocfs2cdsl/ocfs2cdsl.c
Log:
We handle nodenum now
Modified: trunk/ocfs2cdsl/ocfs2cdsl.c
===================================================================
--- trunk/ocfs2cdsl/ocfs2cdsl.c 2004-09-16 21:56:08 UTC (rev 239)
+++ trunk/ocfs2cdsl/ocfs2cdsl.c 2004-09-16 23:33:51 UTC (rev 240)
@@ -36,17 +36,21 @@
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/utsname.h>
+#include <sys/sysmacros.h>
#include <glib.h>
#define OCFS_MAGIC 0xa156f7eb
-#define CDSL_BASE ".cluster"
+#define CDSL_BASE ".cluster"
+#define PROC_OCFS2 "/proc/fs/ocfs2"
+
typedef enum {
CDSL_TYPE_HOSTNAME,
CDSL_TYPE_MACH,
@@ -82,6 +86,7 @@
static char *cdsl_path_expand(State *s);
static char *cdsl_target(State *s, const char *path);
static void delete(State *s, const char *path);
+static char *get_node_num(State *s);
extern char *optarg;
@@ -104,8 +109,8 @@
s = get_state(argc, argv);
if (statfs(s->dirname, &sbuf) != 0) {
- fprintf(stderr, "%s: %s: %s\n", s->progname, s->filename,
- g_strerror(errno));
+ fprintf(stderr, "%s: couldn't statfs %s: %s\n",
+ s->progname, s->dirname, g_strerror(errno));
exit(1);
}
@@ -138,11 +143,17 @@
exit(1);
}
- if (exists && !s->copy && !s->force) {
- fprintf(stderr, "%s: %s already exists, but copy (-c) or "
- "force (-f) not given\n",
- s->progname, s->fullname);
- exit(1);
+ if (exists && !s->copy) {
+ if (s->force) {
+ delete(s, s->fullname);
+ exists = FALSE;
+ }
+ else {
+ fprintf(stderr, "%s: %s already exists, but copy (-c) "
+ "or force (-f) not given\n",
+ s->progname, s->fullname);
+ exit(1);
+ }
}
path = s->dirname + strlen(fsroot) + 1;
@@ -174,7 +185,7 @@
if (s->force)
delete(s, cdsl_full);
else {
- fprintf(stderr, "%s: CDSL already exists "
+ fprintf(stderr, "%s: CDSL already exists. "
"To replace, use the force "
"(-f) option\n",
s->progname);
@@ -379,7 +390,6 @@
g_free(found_type);
g_free(found);
- ret = g_strdup("/tmp/ocfs2");
return ret;
}
@@ -406,7 +416,7 @@
break;
case CDSL_TYPE_NODENUM:
prefix = "nodenum";
- val = "0";
+ val = get_node_num(s);
break;
default:
g_assert_not_reached();
@@ -485,3 +495,55 @@
g_free(cmd);
}
+
+static char *
+get_node_num(State *s)
+{
+ struct stat sbuf;
+ char *dev, *path, buf[20];
+ FILE *f;
+ int i;
+
+ if (stat(s->dirname, &sbuf) != 0) {
+ fprintf(stderr, "%s: couldn't stat %s: %s\n",
+ s->progname, s->dirname, g_strerror(errno));
+ exit(1);
+ }
+
+ dev = g_strdup_printf("%u_%u", major(sbuf.st_dev), minor(sbuf.st_dev));
+ path = g_build_filename(PROC_OCFS2, dev, "nodenum", NULL);
+ g_free(dev);
+
+ f = fopen(path, "r");
+
+ if (f == NULL) {
+ fprintf(stderr, "%s: could not open %s: %s\n",
+ s->progname, path, g_strerror(errno));
+ exit(1);
+ }
+
+ if (fgets(buf, sizeof(buf), f) == NULL) {
+ fprintf(stderr, "%s: could not read node number: %s\n",
+ s->progname, g_strerror(errno));
+ exit(1);
+ }
+
+ fclose(f);
+
+ g_free(path);
+
+ for (i = 0; i < sizeof(buf); i++) {
+ if (buf[i] < '0' || buf[i] > '9') {
+ buf[i] = '\0';
+ break;
+ }
+ }
+
+ if (buf[0] == '\0') {
+ fprintf(stderr, "%s: invalid node number: %s\n",
+ s->progname, g_strerror(errno));
+ exit(1);
+ }
+
+ return g_strdup(buf);
+}
More information about the Ocfs2-tools-commits
mailing list