[Ocfs2-commits] bryce commits r1573 - in trunk: . mount.ocfs
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Thu Oct 14 09:25:13 CDT 2004
Author: bryce
Date: 2004-10-14 09:25:11 -0500 (Thu, 14 Oct 2004)
New Revision: 1573
Added:
trunk/mount.ocfs/
trunk/mount.ocfs/Makefile
trunk/mount.ocfs/mount.ocfs.c
trunk/mount.ocfs/update_filesystems
Log:
Added: trunk/mount.ocfs/Makefile
===================================================================
--- trunk/mount.ocfs/Makefile 2004-10-14 01:36:15 UTC (rev 1572)
+++ trunk/mount.ocfs/Makefile 2004-10-14 14:25:11 UTC (rev 1573)
@@ -0,0 +1,15 @@
+prefix=${RPM_BUILD_ROOT}/
+CFLAGS+= -O2 -g
+
+SRCS=mount.ocfs.c
+TARGETS=$(patsubst %.c,%,$(SRCS))
+
+all: $(TARGETS)
+
+install:
+ install -s -m 755 $(TARGETS) $(prefix)/bin
+ $(shell ./update_filesystems)
+
+clean:
+ rm -f $(TARGETS)
+
Added: trunk/mount.ocfs/mount.ocfs.c
===================================================================
--- trunk/mount.ocfs/mount.ocfs.c 2004-10-14 01:36:15 UTC (rev 1572)
+++ trunk/mount.ocfs/mount.ocfs.c 2004-10-14 14:25:11 UTC (rev 1573)
@@ -0,0 +1,285 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#define CONF_FILE "/etc/ocfs.conf"
+#define MAX_LINE_LENGTH 132
+#define OCFS_MODULE "ocfs"
+#define MOUNT "/bin/mount " /* end space required */
+
+/* Valid options */
+struct options {
+ char *node_name;
+ char *node_number;
+ char *debug_context;
+ char *debug_level;
+ char *ip_address;
+ char *ip_port;
+ char *guid;
+ char *comm_voting;
+} options;
+
+int required = 0;
+
+
+/* This is passed a string containing the GUID found in /etc/ocfs.conf
+ and returns the checksum that will be passed to the ocfs kernel module
+*/
+int calc_checksum(guid_opt) {
+ char *guid_string;
+ char letter;
+ int loop = 0;
+ int cs = 0;
+
+ guid_string = calloc(sizeof(guid_opt), sizeof (char));
+
+
+ while (loop < sprintf(guid_string, "%s", guid_opt)) {
+ letter = guid_string[loop++];
+ switch (letter) {
+ case 'A':
+ cs += 65;
+ break;
+
+ case 'B':
+ cs += 66;
+ break;
+
+ case 'C':
+ cs += 67;
+ break;
+
+ case 'D':
+ cs += 68;
+ break;
+
+ case 'E':
+ cs += 69;
+ break;
+
+ case 'F':
+ cs += 70;
+ break;
+
+ default:
+ cs += atoi(&letter) + 48;
+ break;
+
+ }
+ }
+
+ return cs;
+}
+
+/* fill out the blanks */
+int parse_config_file(char *config_file) {
+
+ FILE *fp;
+ int fd;
+ char *config_line;
+ char *copied_line;
+ int loop, index;
+ int str_len = 0;
+
+ /* no line should be greater than umm 132 chars and if it is
+ you've OTHER problems to worry about
+ */
+ config_line = calloc (MAX_LINE_LENGTH, sizeof(char));
+ copied_line = calloc (MAX_LINE_LENGTH, sizeof(char));
+
+ fp = fopen(config_file,"r");
+ if (fp == NULL ) {
+ perror(NULL);
+ exit(1);
+ }
+
+
+ while ( fgets(config_line, MAX_LINE_LENGTH, fp) != NULL ) {
+ /* kill white space */
+ str_len = strlen(config_line);
+ for (loop=0, index=0; loop < str_len; loop++) {
+ skip:
+ if (isspace (config_line[loop])) {
+ /* advance to next char */
+ loop++;
+ goto skip;
+ }
+
+ copied_line[index] = config_line[loop];
+ index++;
+ }
+ if (!ispunct(copied_line[0]))
+ if (strlen(copied_line) > 3)
+ parse_line(copied_line);
+
+ }
+
+ fclose (fp);
+return 0;
+}
+
+int parse_line(char *conf_line) {
+ char *first;
+ char *value;
+ char *copy;
+
+ /* Remember, you need 1 byte extra to hold the NULL */
+ copy = calloc(strlen(conf_line) +1, sizeof(char));
+ strcpy(copy, conf_line);
+
+ /* +1 to skip the NULL from the next line */
+ value = strpbrk(copy,"=") +1 ;
+ first = strtok(copy, "=");
+
+ /* Not pretty. BTW we need a spare byte for a null */
+ if (strcasecmp(first, "node_name") == 0 ) {
+ options.node_name = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.node_name, value);
+ required |= 0x01;
+ }
+ if (strcasecmp(first, "node_number") == 0 ) {
+ options.node_number = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.node_number, value);
+ }
+ if (strcasecmp(first, "debug_context") == 0 ) {
+ options.debug_context = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.debug_context, value);
+ }
+ if (strcasecmp(first, "debug_level") == 0 ) {
+ options.debug_level = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.debug_level, value);
+ }
+ if (strcasecmp(first, "ip_address") == 0 ) {
+ options.ip_address = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.ip_address, value);
+ required |= 0x02;
+ }
+ if (strcasecmp(first, "ip_port") == 0 ) {
+ options.ip_port = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.ip_port, value);
+ required |= 0x04;
+ }
+ if (strcasecmp(first, "guid") == 0 ) {
+ options.guid = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.guid, value);
+ required |= 0x08;
+ }
+ if (strcasecmp(first, "comm_voting") == 0 ) {
+ options.comm_voting = calloc (strlen(value) +1, sizeof(char));
+ strcpy(options.comm_voting, value);
+ }
+
+
+ free (copy);
+return 0;
+}
+
+
+int module_loaded(char * module) {
+ int fd;
+ int i;
+ char line[100];
+
+ if ((fd = open("/proc/modules", O_RDONLY)) >= 0 ) {
+ while ((i = read(fd, line, 100)) > 0) {
+ if (strstr(line, module) != 0) {
+ close(fd);
+ return (1);
+ }
+ close(fd);
+ return (0);
+ }
+ }
+}
+
+
+int main(int argc, char * argv[]) {
+ int checksum=0;
+ int idx=0;
+ char * module_call;
+ char * add_option;
+ char * mount_call;
+
+ /* a 1K buffer should be more than enough */
+ module_call = calloc(1024, sizeof(char));
+ add_option = calloc(1024, sizeof(char));
+ mount_call = calloc(1024, sizeof(char));
+
+ parse_config_file(CONF_FILE);
+
+ checksum = calc_checksum(options.guid);
+
+ /* Sanity spew */
+ if (!(required & 0x01) == 1) {
+ fprintf (stderr, "%s is missing node_name directive\n", CONF_FILE);
+ exit (1);
+ }
+ if (!(required & 0x02) == 2) {
+ fprintf (stderr, "%s is missing ip_address directive\n", CONF_FILE);
+ exit (1);
+ }
+ if (!(required & 0x04) == 4) {
+ fprintf (stderr, "%s is missing ip_port directive\n", CONF_FILE);
+ exit (1);
+ }
+ if (!(required & 0x08) == 8) {
+ fprintf (stderr, "%s is missing guid directive\n", CONF_FILE);
+ exit (1);
+ }
+
+ /* All righty, we have everything from the config file */
+
+ sprintf(module_call, "/sbin/insmod %s node_name=%s ip_address=%s cs=%d guid=%s",
+ OCFS_MODULE,
+ options.node_name,
+ options.ip_address,
+ checksum,
+ options.guid);
+
+ /* Add in optionals */
+ if (options.node_number != NULL) {
+ sprintf(add_option, " node_number=%d", options.node_number);
+ strcat(module_call, add_option);
+ }
+ if (options.debug_context != NULL) {
+ sprintf(add_option, " debug_context=%d", options.debug_context);
+ strcat(module_call, add_option);
+ }
+ if (options.debug_level != NULL) {
+ sprintf(add_option, " debug_level=%d", options.debug_level);
+ strcat(module_call, add_option);
+ }
+ if (options.comm_voting != NULL) {
+ sprintf(add_option, " comm_voting=%d", options.comm_voting);
+ strcat(module_call, add_option);
+ }
+
+ /* Check if ocfs is loade, if not, load it with arguments */
+ if (module_loaded(OCFS_MODULE) != 1) {
+ /* printf ("Calling %s\n", module_call); */
+ if (system(module_call) == -1)
+ exit (-1);
+ }
+
+ /* Finally we're at the good stuff where we can now mount.
+ mount passes the mount options to us on argv minus the
+ "-t ocfs" bit
+ */
+
+ strcat(mount_call, MOUNT);
+/* strcat(mount_call, " -t ocfs "); */
+ for (idx=1; argv[idx] != NULL; idx++) {
+ strcat(mount_call, argv[idx]);
+ strcat(mount_call, " "); /* seperator */
+ }
+
+ if (system(mount_call) == -1)
+ exit (-1);
+
+ free (module_call);
+ free (add_option);
+ return 0;
+}
Added: trunk/mount.ocfs/update_filesystems
===================================================================
--- trunk/mount.ocfs/update_filesystems 2004-10-14 01:36:15 UTC (rev 1572)
+++ trunk/mount.ocfs/update_filesystems 2004-10-14 14:25:11 UTC (rev 1573)
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+DETECT=`grep -c ocfs /etc/filesystems`
+
+if [ $DETECT = "0" ] ; then
+ echo "ocfs" >> /etc/filesystems
+fi
+
+
+
Property changes on: trunk/mount.ocfs/update_filesystems
___________________________________________________________________
Name: svn:executable
+ *
More information about the Ocfs2-commits
mailing list