projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use length guarded sprintf functions
[fio.git]
/
diskutil.c
diff --git
a/diskutil.c
b/diskutil.c
index 62149d915558713554a40e801bcda7d38b219472..9fc309563ea55772125f81bd97389d7988cb82fe 100644
(file)
--- a/
diskutil.c
+++ b/
diskutil.c
@@
-16,11
+16,22
@@
static struct disk_util *last_du;
static struct flist_head disk_list = FLIST_HEAD_INIT(disk_list);
static struct flist_head disk_list = FLIST_HEAD_INIT(disk_list);
+static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
+ int majdev, int mindev, char *path);
+
static void disk_util_free(struct disk_util *du)
{
if (du == last_du)
last_du = NULL;
static void disk_util_free(struct disk_util *du)
{
if (du == last_du)
last_du = NULL;
+ while (!flist_empty(&du->slaves)) {
+ struct disk_util *slave;
+
+ slave = flist_entry(du->slaves.next, struct disk_util, slavelist);
+ flist_del(&slave->slavelist);
+ slave->users--;
+ }
+
fio_mutex_remove(du->lock);
sfree(du->name);
sfree(du);
fio_mutex_remove(du->lock);
sfree(du->name);
sfree(du);
@@
-64,10
+75,10
@@
static void update_io_tick_disk(struct disk_util *du)
struct disk_util_stat __dus, *dus, *ldus;
struct timeval t;
struct disk_util_stat __dus, *dus, *ldus;
struct timeval t;
- if (get_io_ticks(du, &__dus))
- return;
if (!du->users)
return;
if (!du->users)
return;
+ if (get_io_ticks(du, &__dus))
+ return;
dus = &du->dus;
ldus = &du->last_dus;
dus = &du->dus;
ldus = &du->last_dus;
@@
-182,11
+193,8
@@
static int read_block_dev_entry(char *path, int *maj, int *min)
return 0;
}
return 0;
}
-static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
- int majdev, int mindev, char * path);
-
static void find_add_disk_slaves(struct thread_data *td, char *path,
static void find_add_disk_slaves(struct thread_data *td, char *path,
- struct disk_util *masterdu)
+
struct disk_util *masterdu)
{
DIR *dirhandle = NULL;
struct dirent *dirent = NULL;
{
DIR *dirhandle = NULL;
struct dirent *dirent = NULL;
@@
-195,13
+203,14
@@
static void find_add_disk_slaves(struct thread_data *td, char *path,
int majdev, mindev;
ssize_t linklen;
int majdev, mindev;
ssize_t linklen;
- sprintf(slavesdir, "%s/%s",path, "slaves");
+ sprintf(slavesdir, "%s/%s",
path, "slaves");
dirhandle = opendir(slavesdir);
if (!dirhandle)
return;
while ((dirent = readdir(dirhandle)) != NULL) {
dirhandle = opendir(slavesdir);
if (!dirhandle)
return;
while ((dirent = readdir(dirhandle)) != NULL) {
- if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, ".."))
+ if (!strcmp(dirent->d_name, ".") ||
+ !strcmp(dirent->d_name, ".."))
continue;
sprintf(temppath, "%s/%s", slavesdir, dirent->d_name);
continue;
sprintf(temppath, "%s/%s", slavesdir, dirent->d_name);
@@
-209,11
+218,12
@@
static void find_add_disk_slaves(struct thread_data *td, char *path,
* are links to the real directories for the slave
* devices?
*/
* are links to the real directories for the slave
* devices?
*/
- if ((linklen = readlink(temppath, slavepath, PATH_MAX-1)) < 0) {
+ linklen = readlink(temppath, slavepath, PATH_MAX - 0);
+ if (linklen < 0) {
perror("readlink() for slave device.");
return;
}
perror("readlink() for slave device.");
return;
}
- slavepath[linklen]
=
'\0';
+ slavepath[linklen]
=
'\0';
sprintf(temppath, "%s/%s/dev", slavesdir, slavepath);
if (read_block_dev_entry(temppath, &majdev, &mindev)) {
sprintf(temppath, "%s/%s/dev", slavesdir, slavepath);
if (read_block_dev_entry(temppath, &majdev, &mindev)) {
@@
-234,15
+244,16
@@
static void find_add_disk_slaves(struct thread_data *td, char *path,
/* Should probably use an assert here. slavedu should
* always be present at this point. */
/* Should probably use an assert here. slavedu should
* always be present at this point. */
- if (slavedu)
+ if (slavedu) {
+ slavedu->users++;
flist_add_tail(&slavedu->slavelist, &masterdu->slaves);
flist_add_tail(&slavedu->slavelist, &masterdu->slaves);
+ }
}
closedir(dirhandle);
}
closedir(dirhandle);
- return;
}
}
-static struct disk_util *disk_util_add(struct thread_data *
td, int majdev,
+static struct disk_util *disk_util_add(struct thread_data *td, int majdev,
int mindev, char *path)
{
struct disk_util *du, *__du;
int mindev, char *path)
{
struct disk_util *du, *__du;
@@
-284,7
+295,6
@@
static struct disk_util *disk_util_add(struct thread_data * td, int majdev,
return du;
}
return du;
}
-
static int check_dev_match(int majdev, int mindev, char *path)
{
int major, minor;
static int check_dev_match(int majdev, int mindev, char *path)
{
int major, minor;
@@
-518,7
+528,7
@@
void show_disk_util(void)
* the master's stats line has been displayed in a
* previous iteration of this loop.
*/
* the master's stats line has been displayed in a
* previous iteration of this loop.
*/
- if(!flist_empty(&du->slavelist))
+ if
(!flist_empty(&du->slavelist))
log_info(" ");
log_info(" %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, "
log_info(" ");
log_info(" %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, "
@@
-531,7
+541,7
@@
void show_disk_util(void)
/* If the device has slaves, aggregate the stats for
* those slave devices also.
*/
/* If the device has slaves, aggregate the stats for
* those slave devices also.
*/
- if(!flist_empty(&du->slaves))
+ if
(!flist_empty(&du->slaves))
aggregate_slaves_stats(du);
log_info("\n");
aggregate_slaves_stats(du);
log_info("\n");