[Oracleasm-commits] jlbec commits r308 - trunk/tools
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Tue Jun 21 20:11:20 CDT 2005
Author: jlbec
Date: 2005-06-21 20:11:18 -0500 (Tue, 21 Jun 2005)
New Revision: 308
Modified:
trunk/tools/asmscan.c
trunk/tools/asmtool.c
Log:
o Teach asmscan to do backoff on ENOENT, because hotplug can take a
while.
o Use open64()/stat64().
Modified: trunk/tools/asmscan.c
===================================================================
--- trunk/tools/asmscan.c 2005-06-04 01:35:17 UTC (rev 307)
+++ trunk/tools/asmscan.c 2005-06-22 01:11:18 UTC (rev 308)
@@ -31,6 +31,8 @@
* Boston, MA 021110-1307, USA.
*/
+#define _LARGEFILE_SOURCE
+#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>
@@ -373,7 +375,7 @@
snprintf(proc_name, len, PROC_IDE_FORMAT, dev_name);
/* If not ide, file won't exist */
- f = fopen(proc_name, "r");
+ f = fopen64(proc_name, "r");
if (f)
{
if (fgets(proc_name, len, f))
@@ -411,7 +413,7 @@
return -ENOMEM;
}
- f = fopen("/proc/partitions", "r");
+ f = fopen64("/proc/partitions", "r");
if (!f)
{
rc = -errno;
@@ -759,8 +761,8 @@
} /* clean_disks() */
-static int device_is_disk(const char *manager, const char *device,
- char **disk_name)
+static int check_device_is_disk(const char *manager, const char *device,
+ char **disk_name)
{
int rc;
char *output, *errput, *ptr;
@@ -790,11 +792,11 @@
if (WEXITSTATUS(rc))
{
if (strstr(errput, "not marked"))
- return 0;
+ return -ENXIO;
if (strstr(errput, "No such"))
- return 0;
+ return -ENOENT;
if (strstr(errput, "Invalid argument")) /* Bad IDE lseek */
- return 0;
+ return -EINVAL;
fprintf(stderr,
"asmscan: Error on %s (%d): %s\n",
device, WEXITSTATUS(rc), errput);
@@ -805,13 +807,13 @@
{
ptr = strrchr(output, '"');
if (!ptr)
- return 0; /* Should error */
+ return -EINVAL; /* Should error */
*ptr = '\0';
ptr = strrchr(output, '"');
if (!ptr)
- return 0; /* Again, error */
+ return -EINVAL; /* Again, error */
*disk_name = strdup(ptr + 1);
- return 1;
+ return 0;
}
fprintf(stdout,
@@ -832,10 +834,36 @@
device);
}
- return 0;
-} /* device_is_disk() */
+ return -EIO;
+} /* check_device_is_disk() */
+static int device_is_disk(const char *manager, const char *device,
+ char **disk_name)
+{
+ int rc = -ENOENT;
+ int delay = 1;
+ /*
+ * This is a backoff of three tries:
+ *
+ * try1
+ * sleep 1
+ * try2
+ * sleep 5
+ * try3
+ * fail
+ */
+ do {
+ rc = check_device_is_disk(manager, device, disk_name);
+ if (rc == -ENOENT) {
+ sleep(delay);
+ delay += 4;
+ }
+ } while ((rc == -ENOENT) && (delay < 6));
+
+ return !rc; /* 0 is success */
+}
+
static int instantiate_disk(const char *manager,
const char *disk_name,
const char *device)
@@ -904,7 +932,7 @@
int rc, fd;
/* Any errors, return false. This will force BLKRRPART on the device. */
- fd = open(device->sd_path, O_RDONLY);
+ fd = open64(device->sd_path, O_RDONLY);
if (fd < 0)
return 0;
@@ -924,7 +952,7 @@
int rc, fd;
/* Any errors, return false. This will force BLKRRPART on the device. */
- fd = open(device->sd_path, O_RDONLY);
+ fd = open64(device->sd_path, O_RDONLY);
if (fd < 0)
return -errno;
Modified: trunk/tools/asmtool.c
===================================================================
--- trunk/tools/asmtool.c 2005-06-04 01:35:17 UTC (rev 307)
+++ trunk/tools/asmtool.c 2005-06-22 01:11:18 UTC (rev 308)
@@ -274,9 +274,9 @@
static int open_disk(const char *disk_name)
{
int fd, rc;
- struct stat stat_buf;
+ struct stat64 stat_buf;
- rc = stat(disk_name, &stat_buf);
+ rc = stat64(disk_name, &stat_buf);
if (rc)
return -errno;
@@ -284,12 +284,12 @@
if (!S_ISBLK(stat_buf.st_mode))
return -ENOTBLK;
- fd = open(disk_name, O_RDWR);
+ fd = open64(disk_name, O_RDWR);
if (fd < 0)
return -errno;
/* Second check, try not to write the wrong place */
- rc = fstat(fd, &stat_buf);
+ rc = fstat64(fd, &stat_buf);
if (rc)
{
close(fd);
@@ -704,7 +704,7 @@
int rc, dev_fd, disk_fd;
char *id, *asm_disk;
ASMHeaderInfo ahi;
- struct stat dev_stat_buf, disk_stat_buf;
+ struct stat64 dev_stat_buf, disk_stat_buf;
rc = open_disk(target);
if (rc < 0)
@@ -777,7 +777,7 @@
/* We've successfully opened the ASM disk */
disk_fd = rc;
- rc = fstat(disk_fd, &disk_stat_buf);
+ rc = fstat64(disk_fd, &disk_stat_buf);
close(disk_fd);
if (rc)
{
@@ -786,7 +786,7 @@
id, strerror(errno));
goto out_free;
}
- rc = fstat(dev_fd, &dev_stat_buf);
+ rc = fstat64(dev_fd, &dev_stat_buf);
if (rc)
{
fprintf(stderr,
@@ -844,7 +844,7 @@
{
int rc, t_fd;
char *asm_disk;
- struct stat stat_buf;
+ struct stat64 stat_buf;
asm_disk = asm_disk_path(manager, disk);
if (!asm_disk)
@@ -861,7 +861,7 @@
/* FIXME: Check if mounted ? */
- rc = fstat(t_fd, &stat_buf);
+ rc = fstat64(t_fd, &stat_buf);
if (rc)
{
fprintf(stderr, "asmtool: Unable to query device \"%s\": %s\n",
@@ -1070,7 +1070,7 @@
int c, rc, fd;
char *label, *asm_disk;
ASMHeaderInfo ahi;
- struct stat stat_buf;
+ struct stat64 stat_buf;
rc = -EINVAL;
c = asmdisk_toupper(disk, -1, 0);
@@ -1138,7 +1138,7 @@
}
else
{
- rc = fstat(fd, &stat_buf);
+ rc = fstat64(fd, &stat_buf);
if (rc)
{
fprintf(stdout,
@@ -1284,7 +1284,7 @@
int c, rc, fd = -1;
char *asm_disk, *label, *label_disk;
ASMHeaderInfo ahi;
- struct stat stat_buf;
+ struct stat64 stat_buf;
rc = -EINVAL;
c = asmdisk_toupper(disk, -1, 0);
@@ -1381,7 +1381,7 @@
}
fd = rc;
- rc = fstat(fd, &stat_buf);
+ rc = fstat64(fd, &stat_buf);
if (rc)
{
rc = -errno;
@@ -1487,7 +1487,7 @@
int rc, dev_fd, disk_fd;
char *id, *asm_disk, *label;
ASMHeaderInfo ahi;
- struct stat dev_stat_buf, disk_stat_buf;
+ struct stat64 dev_stat_buf, disk_stat_buf;
rc = -EINVAL;
label = (char *)attr_string(&attrs->attr_list, "label", NULL);
@@ -1600,7 +1600,7 @@
/* We've successfully opened the ASM disk */
disk_fd = rc;
- rc = fstat(disk_fd, &disk_stat_buf);
+ rc = fstat64(disk_fd, &disk_stat_buf);
close(disk_fd);
if (rc)
{
@@ -1609,7 +1609,7 @@
id, strerror(errno));
goto out_free;
}
- rc = fstat(dev_fd, &dev_stat_buf);
+ rc = fstat64(dev_fd, &dev_stat_buf);
if (rc)
{
fprintf(stderr,
@@ -1724,13 +1724,13 @@
static int is_manager(const char *filename)
{
int rc;
- struct statfs statfs_buf;
+ struct statfs64 statfs_buf;
if (!filename || !*filename)
return -EINVAL;
/* I wanted to use statvfs, but there is no f_type */
- rc = statfs(filename, &statfs_buf);
+ rc = statfs64(filename, &statfs_buf);
if (rc)
return -errno;
More information about the Oracleasm-commits
mailing list