[PATCH 1/2] bs_rbd.c: store active_rbd info in addition to struct, scsi_lu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use bs_datasize feature to allocate bs_rbd-private data on the end
of scsi_lu, and then access it with pointer arithmetic; no need to
manage an array indexed by fd, so no fixed number of devices anymore.

Signed-off-by: Dan Mick <dan.mick@xxxxxxxxxxx>
---
 usr/bs_rbd.c |   35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/usr/bs_rbd.c b/usr/bs_rbd.c
index f1dd77d..22818e0 100644
--- a/usr/bs_rbd.c
+++ b/usr/bs_rbd.c
@@ -56,10 +56,12 @@ struct active_rbd {
 	rbd_image_t rbd_image;
 };

-#define MAX_IMAGES	20
-struct active_rbd active_rbds[MAX_IMAGES];
-
-#define RBDP(fd)	(&active_rbds[fd])
+/* active_rbd is allocated just after the bs_thread_info */
+#define RBDP(lu)	((struct active_rbd *) \
+				((char *)lu + \
+				sizeof(struct scsi_lu) + \
+				sizeof(struct bs_thread_info)) \
+			)

static void parse_imagepath(char *path, char **pool, char **image, char **snap)
 {
@@ -100,7 +102,7 @@ static void bs_sync_sync_range(struct scsi_cmd *cmd, uint32_t length,
 {
 	int ret;

-	ret = rbd_flush(RBDP(cmd->dev->fd)->rbd_image);
+	ret = rbd_flush(RBDP(cmd->dev)->rbd_image);
 	if (ret)
 		set_medium_error(result, key, asc);
 }
@@ -130,7 +132,7 @@ static void bs_rbd_request(struct scsi_cmd *cmd)
 	const char *write_buf = NULL;
 	ret = length = 0;
 	key = asc = 0;
+	struct active_rbd *rbd = RBDP(cmd->dev);

 	switch (cmd->scb[0]) {
 	case ORWRITE_16:
@@ -420,21 +422,9 @@ static int bs_rbd_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
 	char *poolname;
 	char *imagename;
 	char *snapname;
-	struct active_rbd *rbd = NULL;
-	int lfd;
+	struct active_rbd *rbd = RBDP(lu);

 	parse_imagepath(path, &poolname, &imagename, &snapname);
-	for (lfd = 0; lfd < MAX_IMAGES; lfd++) {
-		if (active_rbds[lfd].rbd_image == NULL) {
-			rbd = &active_rbds[lfd];
-			*fd = lfd;
-			break;
-		}
-	}
-	if (!rbd) {
-		*fd = -1;
-		return -EMFILE;
-	}

 	rbd->poolname = poolname;
 	rbd->imagename = imagename;
@@ -446,7 +436,7 @@ static int bs_rbd_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)
 		eprintf("bs_rbd_open: rados_ioctx_create: %d\n", ret);
 		return -EIO;
 	}
-	/* null snap name */
+
 	ret = rbd_open(rbd->ioctx, imagename, &rbd->rbd_image, snapname);
 	if (ret < 0) {
 		eprintf("bs_rbd_open: rbd_open: %d\n", ret);
@@ -467,7 +457,7 @@ static int bs_rbd_open(struct scsi_lu *lu, char *path, int *fd, uint64_t *size)

 static void bs_rbd_close(struct scsi_lu *lu)
 {
-	struct active_rbd *rbd = RBDP(lu->fd);
+	struct active_rbd *rbd = RBDP(lu);

 	if (rbd->rbd_image) {
 		rbd_close(rbd->rbd_image);
@@ -520,7 +510,8 @@ static void bs_rbd_exit(struct scsi_lu *lu)

 static struct backingstore_template rbd_bst = {
 	.bs_name		= "rbd",
-	.bs_datasize		= sizeof(struct bs_thread_info),
+	.bs_datasize		= sizeof(struct bs_thread_info) +
+				  sizeof(struct active_rbd),
 	.bs_open		= bs_rbd_open,
 	.bs_close		= bs_rbd_close,
 	.bs_init		= bs_rbd_init,
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux