All of lore.kernel.org
 help / color / mirror / Atom feed
From: bmarzins@sourceware.org <bmarzins@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/gnbd/tools/gnbd_export Makefile gnbd_e ...
Date: 23 Jun 2006 21:55:09 -0000	[thread overview]
Message-ID: <20060623215509.28978.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	STABLE
Changes by:	bmarzins at sourceware.org	2006-06-23 21:55:08

Modified files:
	gnbd/tools/gnbd_export: Makefile gnbd_export.c 

Log message:
	Apparently, libsysfs is deprecated, so I'm pulling it.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gnbd/tools/gnbd_export/Makefile.diff?cvsroot=cluster&only_with_tag=STABLE&r1=1.1.2.1.6.2&r2=1.1.2.1.6.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gnbd/tools/gnbd_export/gnbd_export.c.diff?cvsroot=cluster&only_with_tag=STABLE&r1=1.5.2.1.6.1&r2=1.5.2.1.6.2

--- cluster/gnbd/tools/gnbd_export/Makefile	2006/04/10 16:07:28	1.1.2.1.6.2
+++ cluster/gnbd/tools/gnbd_export/Makefile	2006/06/23 21:55:06	1.1.2.1.6.3
@@ -22,7 +22,7 @@
 	-I$(top_srcdir)/utils -I${top_srcdir}/config \
 	-I${incdir}
 
-LDLIBS+= -L${libdir} -lmagma -ldl -lpthread -lsysfs
+LDLIBS+= -L${libdir} -lmagma -ldl -lpthread
 
 include ${top_srcdir}/make/defines.mk
 
--- cluster/gnbd/tools/gnbd_export/gnbd_export.c	2006/04/10 16:07:28	1.5.2.1.6.1
+++ cluster/gnbd/tools/gnbd_export/gnbd_export.c	2006/06/23 21:55:06	1.5.2.1.6.2
@@ -23,8 +23,7 @@
 #include <sys/un.h>
 #include <sys/wait.h>
 #include <arpa/inet.h>
-#include <sysfs/dlist.h>
-#include <sysfs/libsysfs.h>
+#include <dirent.h>
 #include <ctype.h>
 #define _GNU_SOURCE
 #include <getopt.h>
@@ -342,54 +341,65 @@
   *minor = minor(stat_buf.st_rdev);
 }
 
-
+#define SYSFS_PATH_MAX 64
+#define SYSFS_PATH_BASE "/sys/block"
+#define SYSFS_PATH_BASE_SIZE 10
 char *get_sysfs_name(char *dev_t){
-  unsigned char path[SYSFS_PATH_MAX], *name;
-  struct sysfs_directory *dir, *devdir;
-  struct dlist *devlist;
-
-  name = NULL;
-  if (sysfs_get_mnt_path(path, SYSFS_PATH_MAX) < 0){
-    printe("cannot get sysfs mount path for get_uid command : %s\n",
-           strerror(errno));
-    exit(1);
-  }
-  strcat(path, "/block");
-  dir = sysfs_open_directory(path);
+  char path[SYSFS_PATH_MAX];
+  char *name = NULL;
+  DIR *dir;
+  struct dirent *dp;
+
+  memset(path, 0, sizeof(path));
+  strcpy(path, SYSFS_PATH_BASE);
+  dir = opendir(path);
   if (!dir) {
-    printe("cannot open sysfs directory '%s' for get_uid command : %s\n",
-           path, strerror(errno));
-    exit(1);
-  }
-  devlist = sysfs_get_dir_subdirs(dir);
-  if (!devlist){
-    printe("cannot read sysfs subdirs for get_uid command : %s\n",
-           strerror(errno));
+    printe("cannot open /sys/block to find the device name for %s : %s\n",
+           dev_t, strerror(errno));
     exit(1);
   }
-  dlist_for_each_data(devlist, devdir, struct sysfs_directory) {
-    struct sysfs_attribute *attr;
-    attr = sysfs_get_directory_attribute(devdir, "dev");
-    if (!attr){
-      printe("cannot get 'dev' sysfs attribute for get_uid command : %s\n",
+  while ((dp = readdir(dir))) {
+    int fd;
+    int bytes;
+    int count = 0;
+
+    if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
+      continue;
+    snprintf(path + SYSFS_PATH_BASE_SIZE,
+	     SYSFS_PATH_MAX - SYSFS_PATH_BASE_SIZE - 1, "/%s/dev", dp->d_name);
+    fd = open(path, O_RDONLY);
+    if (fd < 0) {
+      printe("cannot open %s to find device name for %s : %s\n", path, dev_t,
              strerror(errno));
       exit(1);
     }
-    if (sysfs_read_attribute(attr) < 0){
-      printe("cannot get sysfs attribute data for get_uid command : %s\n",
-             strerror(errno));
-      exit(1);
+    while (count < 4096){
+      bytes = read(fd, &sysfs_buf[count], 4096 - count);
+      if (bytes < 0 && errno != EINTR) {
+        printe("cannot read from %s: %s\n", path, strerror(errno));
+        exit(1);
+      }
+      if (bytes == 0)
+         break;
+      count += bytes;
     }
-    if (strcmp(dev_t, attr->value) == 0){
-      name = strdup(devdir->name);
+    if (count == 4096)
+      sysfs_buf[4095] = 0;
+    else
+      sysfs_buf[count] = 0;
+    if (strcmp(dev_t, sysfs_buf) == 0){
+      name = strdup(dp->d_name);
       break;
     }
   }
-  if (!name){
-    printe("cannot find a sysfs block device for get_uid command\n");
+  if (closedir(dir) < 0){
+    printe("cannot close dir %s : %s\n", SYSFS_PATH_BASE, strerror(errno));
+    exit(1);
+  }
+  if (!name) {
+    printe("cannot find sysfs block device %s\n", dev_t);
     exit(1);
   }
-  sysfs_close_directory(dir);
   return name;
 }
 



             reply	other threads:[~2006-06-23 21:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-23 21:55 bmarzins [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-06-26 17:27 [Cluster-devel] cluster/gnbd/tools/gnbd_export Makefile gnbd_e bmarzins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060623215509.28978.qmail@sourceware.org \
    --to=bmarzins@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.