* [PATCH 1/2] btrfs-progs: replace blkid_probe_get_wholedisk_devno
@ 2013-04-11 15:39 Eric Sandeen
2013-04-11 15:44 ` [PATCH 2/2] btrfs-progs: use clearer var names in is_ssd() Eric Sandeen
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2013-04-11 15:39 UTC (permalink / raw)
To: linux-btrfs
blkid_probe_get_wholedisk_devno() isn't available in some older
versions of libblkid. It was used to work around an old
bug in blkid_devno_to_wholedisk(), but that has been fixed since
5cd0823 libblkid: fix blkid_devno_to_wholedisk(), present in
util-linux 2.17 and beyond.
If we happen to be missing that fix, the worst that happens is
that we'd fail to detect that a device is an ssd; the upside is
that this code compiles on older systems.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/mkfs.c b/mkfs.c
index c8cb395..7df78fc 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1215,9 +1215,8 @@ static int check_leaf_or_node_size(u32 size, u32 sectorsize)
static int is_ssd(const char *file)
{
- char *devname;
blkid_probe probe;
- char *dev;
+ char dev[32];
char path[PATH_MAX];
dev_t disk;
int fd;
@@ -1227,24 +1226,16 @@ static int is_ssd(const char *file)
if (!probe)
return 0;
- /*
- * We want to use blkid_devno_to_wholedisk() but it's broken for some
- * reason on F17 at least so we'll do this trickery
- */
- disk = blkid_probe_get_wholedisk_devno(probe);
+ /* Device number of this disk (possibly a partition) */
+ disk = blkid_probe_get_devno(probe);
if (!disk)
return 0;
- devname = blkid_devno_to_devname(disk);
- if (!devname)
- return 0;
-
- dev = strrchr(devname, '/');
- dev++;
+ /* Get whole disk name (not full path) for this devno */
+ blkid_devno_to_wholedisk(disk, dev, sizeof(dev), NULL);
snprintf(path, PATH_MAX, "/sys/block/%s/queue/rotational", dev);
- free(devname);
blkid_free_probe(probe);
fd = open(path, O_RDONLY);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] btrfs-progs: use clearer var names in is_ssd()
2013-04-11 15:39 [PATCH 1/2] btrfs-progs: replace blkid_probe_get_wholedisk_devno Eric Sandeen
@ 2013-04-11 15:44 ` Eric Sandeen
2013-04-12 17:17 ` Zach Brown
0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2013-04-11 15:44 UTC (permalink / raw)
To: linux-btrfs
is_ssd() uses nondescript variable names; path - to what?
disk - it's a dev_t not a disk name, unlike dev, which is
a name not a dev_t!
Rename some vars to make things hopefully clearer:
wholedisk - the name of the node for the entire disk
devno - the dev_t of the device we're mkfs'ing
sysfs_path - the path in sysfs we ultimately check
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
Hopefully that's slightly clearer; if not, this patch is
just cleanup, so it's not at all critical.
diff --git a/mkfs.c b/mkfs.c
index 7df78fc..d735d65 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1216,9 +1216,9 @@ static int check_leaf_or_node_size(u32 size, u32 sectorsize)
static int is_ssd(const char *file)
{
blkid_probe probe;
- char dev[32];
- char path[PATH_MAX];
- dev_t disk;
+ char wholedisk[32];
+ char sysfs_path[PATH_MAX];
+ dev_t devno;
int fd;
char rotational;
@@ -1227,18 +1227,19 @@ static int is_ssd(const char *file)
return 0;
/* Device number of this disk (possibly a partition) */
- disk = blkid_probe_get_devno(probe);
- if (!disk)
+ devno= blkid_probe_get_devno(probe);
+ if (!devno)
return 0;
/* Get whole disk name (not full path) for this devno */
- blkid_devno_to_wholedisk(disk, dev, sizeof(dev), NULL);
+ blkid_devno_to_wholedisk(devno, wholedisk, sizeof(wholedisk), NULL);
- snprintf(path, PATH_MAX, "/sys/block/%s/queue/rotational", dev);
+ snprintf(sysfs_path, PATH_MAX, "/sys/block/%s/queue/rotational",
+ wholedisk);
blkid_free_probe(probe);
- fd = open(path, O_RDONLY);
+ fd = open(sysfs_path, O_RDONLY);
if (fd < 0) {
return 0;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] btrfs-progs: use clearer var names in is_ssd()
2013-04-11 15:44 ` [PATCH 2/2] btrfs-progs: use clearer var names in is_ssd() Eric Sandeen
@ 2013-04-12 17:17 ` Zach Brown
0 siblings, 0 replies; 3+ messages in thread
From: Zach Brown @ 2013-04-12 17:17 UTC (permalink / raw)
To: Eric Sandeen; +Cc: linux-btrfs
> + devno= blkid_probe_get_devno(probe);
*gasp*
:)
- z
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-04-12 17:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-11 15:39 [PATCH 1/2] btrfs-progs: replace blkid_probe_get_wholedisk_devno Eric Sandeen
2013-04-11 15:44 ` [PATCH 2/2] btrfs-progs: use clearer var names in is_ssd() Eric Sandeen
2013-04-12 17:17 ` Zach Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox