[pve-devel] r6405 - in pve-cluster/trunk/data: . src

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Aug 3 10:52:16 CEST 2011


Author: dietmar
Date: 2011-08-03 10:52:16 +0200 (Wed, 03 Aug 2011)
New Revision: 6405

Added:
   pve-cluster/trunk/data/src/cfs-plug-func.c
Modified:
   pve-cluster/trunk/data/ChangeLog
   pve-cluster/trunk/data/src/Makefile.am
   pve-cluster/trunk/data/src/Makefile.in
   pve-cluster/trunk/data/src/cfs-plug.h
   pve-cluster/trunk/data/src/pmxcfs.c
Log:
	* src/cfs-plug-func.c: simple plugin to view data returned by
	function. We use that to display status inside the filesystem
	(.version, .members, .vmlist, .rrd, .clusterlog)



Modified: pve-cluster/trunk/data/ChangeLog
===================================================================
--- pve-cluster/trunk/data/ChangeLog	2011-08-03 06:53:52 UTC (rev 6404)
+++ pve-cluster/trunk/data/ChangeLog	2011-08-03 08:52:16 UTC (rev 6405)
@@ -1,3 +1,9 @@
+2011-08-03  Proxmox Support Team  <support at proxmox.com>
+
+	* src/cfs-plug-func.c: simple plugin to view data returned by
+	function. We use that to display status inside the filesystem
+	(.version, .members, .vmlist, .rrd, .clusterlog)
+
 2011-08-02  Proxmox Support Team  <support at proxmox.com>
 
 	* src/dfsm.c (dfsm_set_mode): call new callback dfsm_synced_fn()

Modified: pve-cluster/trunk/data/src/Makefile.am
===================================================================
--- pve-cluster/trunk/data/src/Makefile.am	2011-08-03 06:53:52 UTC (rev 6404)
+++ pve-cluster/trunk/data/src/Makefile.am	2011-08-03 08:52:16 UTC (rev 6405)
@@ -31,6 +31,7 @@
 	cfs-plug.h 		\
 	cfs-plug.c 		\
 	cfs-plug-link.c		\
+	cfs-plug-func.c		\
 	cfs-plug-memdb.h 	\
 	cfs-plug-memdb.c 	\
 	cfs-utils.h		\

Modified: pve-cluster/trunk/data/src/Makefile.in
===================================================================
--- pve-cluster/trunk/data/src/Makefile.in	2011-08-03 06:53:52 UTC (rev 6404)
+++ pve-cluster/trunk/data/src/Makefile.in	2011-08-03 08:52:16 UTC (rev 6405)
@@ -56,8 +56,8 @@
 	server.$(OBJEXT) status.$(OBJEXT) confdb.$(OBJEXT) \
 	quorum.$(OBJEXT) dcdb.$(OBJEXT) dfsm.$(OBJEXT) \
 	cfs-plug.$(OBJEXT) cfs-plug-link.$(OBJEXT) \
-	cfs-plug-memdb.$(OBJEXT) cfs-utils.$(OBJEXT) \
-	database.$(OBJEXT) memdb.$(OBJEXT)
+	cfs-plug-func.$(OBJEXT) cfs-plug-memdb.$(OBJEXT) \
+	cfs-utils.$(OBJEXT) database.$(OBJEXT) memdb.$(OBJEXT)
 libpmxcfs_a_OBJECTS = $(am_libpmxcfs_a_OBJECTS)
 am__installdirs = "$(DESTDIR)$(bindir)"
 am__EXEEXT_1 = check_memdb$(EXEEXT)
@@ -236,6 +236,7 @@
 	cfs-plug.h 		\
 	cfs-plug.c 		\
 	cfs-plug-link.c		\
+	cfs-plug-func.c		\
 	cfs-plug-memdb.h 	\
 	cfs-plug-memdb.c 	\
 	cfs-utils.h		\
@@ -346,6 +347,7 @@
 distclean-compile:
 	-rm -f *.tab.c
 
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cfs-plug-func.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cfs-plug-link.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cfs-plug-memdb.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cfs-plug.Po at am__quote@

Added: pve-cluster/trunk/data/src/cfs-plug-func.c
===================================================================
--- pve-cluster/trunk/data/src/cfs-plug-func.c	                        (rev 0)
+++ pve-cluster/trunk/data/src/cfs-plug-func.c	2011-08-03 08:52:16 UTC (rev 6405)
@@ -0,0 +1,177 @@
+/*
+  Copyright (C) 2011 Proxmox Server Solutions GmbH
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU Affero General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  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 Affero General Public License for more details.
+
+  You should have received a copy of the GNU Affero General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+  Author: Dietmar Maurer <dietmar at proxmox.com>
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <glib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <dirent.h>
+
+#include "cfs-utils.h"
+#include "cfs-plug.h"
+
+static struct cfs_operations cfs_ops;
+
+static cfs_plug_t *cfs_plug_func_lookup_plug(cfs_plug_t *plug, char **path)
+{
+	g_return_val_if_fail(plug != NULL, NULL);
+	g_return_val_if_fail(plug->ops == &cfs_ops, NULL);
+
+	return (!*path || !(*path)[0]) ? plug : NULL;
+}
+
+static void cfs_plug_func_destroy(cfs_plug_t *plug)
+{
+	g_return_if_fail(plug != NULL);
+	g_return_if_fail(plug->ops == &cfs_ops);
+
+	cfs_plug_func_t *fplug = (cfs_plug_func_t *)plug;
+
+	cfs_debug("enter cfs_plug_func_destroy %s", plug->name);
+
+	if (fplug->data)
+		g_free(fplug->data);
+
+	g_free(plug->name);
+
+	g_free(plug);
+}
+
+static int 
+cfs_plug_func_getattr(
+	cfs_plug_t *plug, 
+	const char *path, 
+	struct stat *stbuf)
+{
+	g_return_val_if_fail(plug != NULL, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(plug->ops == &cfs_ops, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(path != NULL, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(stbuf != NULL, PARAM_CHECK_ERRNO);
+
+	cfs_debug("enter cfs_plug_func_getattr %s", path);
+
+	cfs_plug_func_t *fplug = (cfs_plug_func_t *)plug;
+
+	memset(stbuf, 0, sizeof(struct stat));
+
+	fplug->data = fplug->update_callback(plug);
+
+	stbuf->st_mode = fplug->mode;
+	stbuf->st_nlink = 1;
+	stbuf->st_size = fplug->data ? strlen(fplug->data) : 0;
+
+	return 0;
+}
+
+static int 
+cfs_plug_func_read(
+	cfs_plug_t *plug, 
+	const char *path, 
+	char *buf, 
+	size_t size, 
+	off_t offset,
+	struct fuse_file_info *fi)
+{
+	(void) fi;
+
+	g_return_val_if_fail(plug != NULL, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(plug->ops == &cfs_ops, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(path != NULL, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(buf != NULL, PARAM_CHECK_ERRNO);
+
+	cfs_plug_func_t *fplug = (cfs_plug_func_t *)plug;
+
+	char *data = fplug->data;
+
+	cfs_debug("enter cfs_plug_func_read %s", data);
+
+	if (!data)
+		return 0;
+
+	int len = strlen(data);
+
+	if (offset < len) {
+		if (offset + size > len)
+			size = len - offset;
+		memcpy(buf, data + offset, size);
+	} else {
+		size = 0;
+	}
+
+	return size;
+}
+
+static int 
+cfs_plug_func_open(
+	cfs_plug_t *plug, 
+	const char *path, 
+	struct fuse_file_info *fi)
+{
+	g_return_val_if_fail(plug != NULL, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(plug->ops == &cfs_ops, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(path != NULL, PARAM_CHECK_ERRNO);
+	g_return_val_if_fail(fi != NULL, PARAM_CHECK_ERRNO);
+
+	cfs_debug("enter cfs_plug_func_open %s", path);
+
+	return 0;
+}
+
+static struct cfs_operations cfs_ops = {
+	.getattr = cfs_plug_func_getattr,
+	.read = cfs_plug_func_read,
+	.open = cfs_plug_func_open,
+};
+
+
+cfs_plug_func_t *
+cfs_plug_func_new(
+	const char *name, 
+	mode_t mode,
+	cfs_plug_func_udpate_data_fn_t update_callback)
+{
+	g_return_val_if_fail(name != NULL, NULL);
+	g_return_val_if_fail(update_callback != NULL, NULL);
+
+	cfs_plug_func_t *fplug = g_new0(cfs_plug_func_t, 1);
+
+	fplug->plug.ops = &cfs_ops;
+
+	fplug->plug.lookup_plug = cfs_plug_func_lookup_plug;
+	fplug->plug.destroy_plug = cfs_plug_func_destroy;
+
+	fplug->plug.name = g_strdup(name);
+
+	fplug->update_callback = update_callback;
+	fplug->mode = S_IFREG | mode;
+
+	return fplug;
+}
+

Modified: pve-cluster/trunk/data/src/cfs-plug.h
===================================================================
--- pve-cluster/trunk/data/src/cfs-plug.h	2011-08-03 06:53:52 UTC (rev 6404)
+++ pve-cluster/trunk/data/src/cfs-plug.h	2011-08-03 08:52:16 UTC (rev 6405)
@@ -27,6 +27,9 @@
 
 #include <errno.h>
 #include <fuse.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #define PARAM_CHECK_ERRNO -EREMOTEIO
 
@@ -73,10 +76,22 @@
 	char *symlink;
 } cfs_plug_link_t;
 
+typedef char *(*cfs_plug_func_udpate_data_fn_t)(cfs_plug_t *plug);
+typedef struct {
+	cfs_plug_t plug;
+	char *data;
+	mode_t mode;
+	cfs_plug_func_udpate_data_fn_t update_callback;
+} cfs_plug_func_t;
+
 cfs_plug_base_t *cfs_plug_base_new(const char *name, cfs_plug_t *base);
 void cfs_plug_base_insert(cfs_plug_base_t *base, cfs_plug_t *sub);
 
 cfs_plug_link_t *cfs_plug_link_new(const char *name, const char *symlink);
+cfs_plug_func_t *cfs_plug_func_new(
+	const char *name, 
+	mode_t mode,
+	cfs_plug_func_udpate_data_fn_t update_callback);
 
 
 #endif /* _PVE_CFS_PLUG_H_ */

Modified: pve-cluster/trunk/data/src/pmxcfs.c
===================================================================
--- pve-cluster/trunk/data/src/pmxcfs.c	2011-08-03 06:53:52 UTC (rev 6404)
+++ pve-cluster/trunk/data/src/pmxcfs.c	2011-08-03 08:52:16 UTC (rev 6405)
@@ -132,10 +132,7 @@
 	char *subpath = NULL;
 	cfs_plug_t *plug = find_plug(path, &subpath);
 	
-	if (!plug)
-		goto ret;
-
-	if (plug->ops && plug->ops->getattr) {
+	if (plug && plug->ops && plug->ops->getattr) {
 		ret = plug->ops->getattr(plug, subpath ? subpath : "", stbuf);
 
 		stbuf->st_gid = cfs.gid;
@@ -146,7 +143,6 @@
 			stbuf->st_mode &= 0777700;
 	}
 
- ret:
 	cfs_debug("leave cfs_fuse_getattr %s (%d)", path, ret);
 
 	if (subpath)
@@ -273,13 +269,12 @@
 	char *subpath = NULL;
 	cfs_plug_t *plug = find_plug(path, &subpath);
 	
-	if (!plug)
-		goto ret;
+	if (plug && plug->ops) { 
+		if ((subpath || !plug->ops->readdir) && plug->ops->open) {
+			ret = plug->ops->open(plug, subpath ? subpath : "", fi);
+		}
+	}
 
-	if (subpath && plug->ops && plug->ops->open)
-		ret = plug->ops->open(plug, subpath, fi);
-	    
-ret:
 	cfs_debug("leave cfs_fuse_open %s (%d)", path, ret);
 
 	if (subpath)
@@ -300,13 +295,11 @@
 	char *subpath = NULL;
 	cfs_plug_t *plug = find_plug(path, &subpath);
 	
-	if (!plug)
-		goto ret;
+	if (plug && plug->ops) { 
+		if ((subpath || !plug->ops->readdir) && plug->ops->read)
+			ret = plug->ops->read(plug, subpath ? subpath : "", buf, size, offset, fi);
+	}
 
-	if (subpath && plug->ops && plug->ops->read)
-		ret = plug->ops->read(plug, subpath, buf, size, offset, fi);
-
-ret:
 	cfs_debug("leave cfs_fuse_read %s (%d)", path, ret);
 
 	if (subpath)
@@ -494,8 +487,81 @@
 	.init = cfs_fuse_init
 };
 
-static void create_symlinks(cfs_plug_base_t *bplug, const char *nodename)
+static char *
+create_dot_version_cb(cfs_plug_t *plug)
 {
+	GString *outbuf = g_string_new(NULL);
+	char *data = NULL;
+
+	if (cfs_create_version_msg(outbuf) == 0) {
+		data = outbuf->str;
+		g_string_free(outbuf, FALSE);
+	} else {
+		g_string_free(outbuf, TRUE);
+	}
+
+	return data;
+}
+
+static char *
+create_dot_members_cb(cfs_plug_t *plug)
+{
+	GString *outbuf = g_string_new(NULL);
+	char *data = NULL;
+
+	if (cfs_create_memberlist_msg(outbuf) == 0) {
+		data = outbuf->str;
+		g_string_free(outbuf, FALSE);
+	} else {
+		g_string_free(outbuf, TRUE);
+	}
+
+	return data;
+}
+
+static char *
+create_dot_vmlist_cb(cfs_plug_t *plug)
+{
+	GString *outbuf = g_string_new(NULL);
+	char *data = NULL;
+
+	if (cfs_create_vmlist_msg(outbuf) == 0) {
+		data = outbuf->str;
+		g_string_free(outbuf, FALSE);
+	} else {
+		g_string_free(outbuf, TRUE);
+	}
+
+	return data;
+}
+
+static char *
+create_dot_rrd_cb(cfs_plug_t *plug)
+{
+	GString *outbuf = g_string_new(NULL);
+
+	cfs_rrd_dump(outbuf);
+	char *data = outbuf->str;
+	g_string_free(outbuf, FALSE);
+
+	return data;
+}
+
+static char *
+create_dot_clusterlog_cb(cfs_plug_t *plug)
+{
+	GString *outbuf = g_string_new(NULL);
+
+	cfs_cluster_log_dump(outbuf, NULL, 50);
+	char *data = outbuf->str;
+	g_string_free(outbuf, FALSE);
+
+	return data;
+}
+
+static void 
+create_symlinks(cfs_plug_base_t *bplug, const char *nodename)
+{
 	g_return_if_fail(bplug != NULL);
 	g_return_if_fail(nodename != NULL);
 
@@ -516,6 +582,21 @@
 
 	lnk = cfs_plug_link_new("status", STATUSDIR);
 	cfs_plug_base_insert(bplug, (cfs_plug_t*)lnk);
+
+	cfs_plug_func_t *fplug = cfs_plug_func_new(".version", 0440, create_dot_version_cb);
+	cfs_plug_base_insert(bplug, (cfs_plug_t*)fplug);
+	
+	fplug = cfs_plug_func_new(".members", 0440, create_dot_members_cb);
+	cfs_plug_base_insert(bplug, (cfs_plug_t*)fplug);
+
+	fplug = cfs_plug_func_new(".vmlist", 0440, create_dot_vmlist_cb);
+	cfs_plug_base_insert(bplug, (cfs_plug_t*)fplug);
+
+	fplug = cfs_plug_func_new(".rrd", 0440, create_dot_rrd_cb);
+	cfs_plug_base_insert(bplug, (cfs_plug_t*)fplug);
+
+	fplug = cfs_plug_func_new(".clusterlog", 0440, create_dot_clusterlog_cb);
+	cfs_plug_base_insert(bplug, (cfs_plug_t*)fplug);
 }
 
 static char *



More information about the pve-devel mailing list