From: Cong Meng <mc@linux.vnet.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
stefanha@linux.vnet.ibm.com, zwanp@cn.ibm.com,
Rusty Russell <rusty@rustcorp.com.au>,
linuxram@us.ibm.com, qemu-devel@nongnu.org,
virtualization@lists.linux-foundation.org,
Cong Meng <mc@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 1/2 v1] blkdrv: Add queue limits parameters for sg block drive
Date: Tue, 21 Aug 2012 16:23:46 +0800 [thread overview]
Message-ID: <1345537427-21601-1-git-send-email-mc@linux.vnet.ibm.com> (raw)
This patch adds some queue limit parameters into block drive. And inits them
for sg block drive. Some interfaces are also added for accessing them.
Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
---
block/raw-posix.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
block_int.h | 4 +++
blockdev.c | 15 +++++++++++++
hw/block-common.h | 3 ++
4 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 0dce089..a086f89 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -53,6 +53,7 @@
#include <linux/cdrom.h>
#include <linux/fd.h>
#include <linux/fs.h>
+#include <dirent.h>
#endif
#ifdef CONFIG_FIEMAP
#include <linux/fiemap.h>
@@ -829,6 +830,62 @@ static int hdev_probe_device(const char *filename)
return 0;
}
+static void read_queue_limit(char *path, const char *filename, unsigned int *val)
+{
+ FILE *f;
+ char *tail = path + strlen(path);
+
+ pstrcat(path, MAXPATHLEN, filename);
+ f = fopen(path, "r");
+ if (!f) {
+ goto out;
+ }
+
+ fscanf(f, "%u", val);
+ fclose(f);
+
+out:
+ *tail = 0;
+}
+
+static void sg_get_queue_limits(BlockDriverState *bs, const char *filename)
+{
+ DIR *ffs;
+ struct dirent *d;
+ char path[MAXPATHLEN];
+
+ snprintf(path, MAXPATHLEN,
+ "/sys/class/scsi_generic/sg%s/device/block/",
+ filename + strlen("/dev/sg"));
+
+ ffs = opendir(path);
+ if (!ffs) {
+ return;
+ }
+
+ for (;;) {
+ d = readdir(ffs);
+ if (!d) {
+ return;
+ }
+
+ if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) {
+ continue;
+ }
+
+ break;
+ }
+
+ closedir(ffs);
+
+ pstrcat(path, MAXPATHLEN, d->d_name);
+ pstrcat(path, MAXPATHLEN, "/queue/");
+
+ read_queue_limit(path, "max_sectors_kb", &bs->max_sectors);
+ read_queue_limit(path, "max_segments", &bs->max_segments);
+ read_queue_limit(path, "max_segment_size", &bs->max_segment_size);
+}
+
static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVRawState *s = bs->opaque;
@@ -868,6 +925,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
temp = realpath(filename, resolved_path);
if (temp && strstart(temp, "/dev/sg", NULL)) {
bs->sg = 1;
+ sg_get_queue_limits(bs, temp);
}
}
#endif
diff --git a/block_int.h b/block_int.h
index d72317f..a9d07a2 100644
--- a/block_int.h
+++ b/block_int.h
@@ -333,6 +333,10 @@ struct BlockDriverState {
/* long-running background operation */
BlockJob *job;
+
+ unsigned int max_sectors;
+ unsigned int max_segments;
+ unsigned int max_segment_size;
};
int get_tmp_filename(char *filename, int size);
diff --git a/blockdev.c b/blockdev.c
index 3d75015..e17edbf 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1191,3 +1191,18 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
bdrv_iterate(do_qmp_query_block_jobs_one, &prev);
return dummy.next;
}
+
+unsigned int get_queue_max_sectors(BlockDriverState *bs)
+{
+ return (bs->file && bs->file->sg) ? bs->file->max_sectors : 0;
+}
+
+unsigned int get_queue_max_segments(BlockDriverState *bs)
+{
+ return (bs->file && bs->file->sg) ? bs->file->max_segments : 0;
+}
+
+unsigned int get_queue_max_segment_size(BlockDriverState *bs)
+{
+ return (bs->file && bs->file->sg) ? bs->file->max_segment_size : 0;
+}
diff --git a/hw/block-common.h b/hw/block-common.h
index bb808f7..d47fcd7 100644
--- a/hw/block-common.h
+++ b/hw/block-common.h
@@ -76,4 +76,7 @@ void hd_geometry_guess(BlockDriverState *bs,
int *ptrans);
int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs);
+unsigned int get_queue_max_sectors(BlockDriverState *bs);
+unsigned int get_queue_max_segments(BlockDriverState *bs);
+unsigned int get_queue_max_segment_size(BlockDriverState *bs);
#endif
--
1.7.7.6
next reply other threads:[~2012-08-21 8:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-21 8:23 Cong Meng [this message]
2012-08-21 8:23 ` [Qemu-devel] [PATCH 2/2 v1] virtio-scsi: set per-LUN queue limits for sg devices Cong Meng
2012-08-21 9:56 ` Stefan Hajnoczi
2012-08-21 8:48 ` [Qemu-devel] [PATCH 1/2 v1] blkdrv: Add queue limits parameters for sg block drive Paolo Bonzini
2012-08-21 9:41 ` Cong Meng
2012-08-21 9:52 ` Stefan Hajnoczi
2012-08-21 10:14 ` Paolo Bonzini
2012-08-22 11:04 ` Cong Meng
2012-08-22 12:09 ` Paolo Bonzini
2012-08-22 13:13 ` Stefan Hajnoczi
2012-08-22 14:13 ` Paolo Bonzini
2012-08-23 9:31 ` Cong Meng
2012-08-23 10:03 ` Paolo Bonzini
2012-08-23 10:08 ` Stefan Hajnoczi
2012-08-23 10:52 ` Paolo Bonzini
2012-08-23 12:08 ` Stefan Hajnoczi
2012-08-24 0:45 ` Nicholas A. Bellinger
2012-08-24 7:56 ` Paolo Bonzini
2012-08-24 10:43 ` Hannes Reinecke
2012-08-24 9:05 ` Stefan Hajnoczi
2012-08-24 9:14 ` Paolo Bonzini
2012-08-21 9:49 ` Stefan Hajnoczi
2012-08-21 18:31 ` Blue Swirl
2012-08-22 8:25 ` Stefan Hajnoczi
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=1345537427-21601-1-git-send-email-mc@linux.vnet.ibm.com \
--to=mc@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=linuxram@us.ibm.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rusty@rustcorp.com.au \
--cc=stefanha@linux.vnet.ibm.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=zwanp@cn.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).