From 5f91791561c865cd32d53b3e45d27ebd85ed36a3 Mon Sep 17 00:00:00 2001
From: Mike Christie <michaelc@cs.wisc.edu>
Date: Wed, 29 Jul 2015 04:23:53 -0500
Subject: [PATCH] rbd: move structs used by lio rbd to new header
References: fate#318836
Patch-mainline: Not yet, SES2 clustered LIO/RBD
This moves structs and other definitions needed by the lio rbd
backend module to a header.
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Acked-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Luis Henriques <lhenriques@suse.com>
[luis: rebased on top of a1fbb5e7bbb5 ("rbd: start enums at 1 instead of 0")]
---
drivers/block/rbd.c | 168 --------------------------------------
include/linux/ceph/librbd.h | 194 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 195 insertions(+), 167 deletions(-)
create mode 100644 include/linux/ceph/librbd.h
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -33,6 +33,7 @@
#include <linux/ceph/mon_client.h>
#include <linux/ceph/cls_lock_client.h>
#include <linux/ceph/decode.h>
+#include <linux/ceph/librbd.h>
#include <linux/parser.h>
#include <linux/bsearch.h>
@@ -84,8 +85,6 @@ static int atomic_dec_return_safe(atomic
return -EINVAL;
}
-#define RBD_DRV_NAME "rbd"
-
#define RBD_MINORS_PER_MAJOR 256
#define RBD_SINGLE_MAJOR_PART_SHIFT 4
@@ -129,31 +128,6 @@ static int atomic_dec_return_safe(atomic
#define RBD_FEATURES_SUPPORTED (RBD_FEATURES_ALL)
/*
- * An RBD device name will be "rbd#", where the "rbd" comes from
- * RBD_DRV_NAME above, and # is a unique integer identifier.
- */
-#define DEV_NAME_LEN 32
-
-/*
- * block device image metadata (in-memory version)
- */
-struct rbd_image_header {
- /* These six fields never change for a given rbd image */
- char *object_prefix;
- __u8 obj_order;
- u64 stripe_unit;
- u64 stripe_count;
- s64 data_pool_id;
- u64 features; /* Might be changeable someday? */
-
- /* The remaining fields need to be updated occasionally */
- u64 image_size;
- struct ceph_snap_context *snapc;
- char *snap_names; /* format 1 only */
- u64 *snap_sizes; /* format 1 only */
-};
-
-/*
* An rbd image specification.
*
* The tuple (pool_id, image_id, snap_id) is sufficient to uniquely
@@ -200,29 +174,11 @@ struct rbd_client {
struct list_head node;
};
-struct rbd_img_request;
-typedef void (*rbd_img_callback_t)(struct rbd_img_request *);
-
#define BAD_WHICH U32_MAX /* Good which or bad which, which? */
struct rbd_obj_request;
typedef void (*rbd_obj_callback_t)(struct rbd_obj_request *);
-enum obj_request_type {
- OBJ_REQUEST_NODATA = 1,
- OBJ_REQUEST_BIO, /* pointer into provided bio (list) */
- OBJ_REQUEST_BVECS, /* pointer into provided bio_vec array */
- OBJ_REQUEST_SG,
-};
-
-enum obj_operation_type {
- OBJ_OP_READ = 1,
- OBJ_OP_WRITE,
- OBJ_OP_DISCARD,
- OBJ_OP_CMP_AND_WRITE,
- OBJ_OP_WRITESAME,
-};
-
enum obj_req_flags {
OBJ_REQ_DONE, /* completion flag: not done = 0, done = 1 */
OBJ_REQ_IMG_DATA, /* object usage: standalone = 0, image = 1 */
@@ -297,37 +253,6 @@ enum img_req_flags {
IMG_REQ_WRITESAME, /* normal = 0, write same = 1 */
};
-struct rbd_img_request {
- struct rbd_device *rbd_dev;
- u64 offset; /* starting image byte offset */
- u64 length; /* byte count from offset */
- unsigned long flags;
-
- u64 snap_id; /* for reads */
- struct ceph_snap_context *snapc; /* for writes */
-
- struct request *rq; /* block request */
- struct rbd_obj_request *obj_request; /* obj req initiator */
- void *lio_cmd_data; /* lio specific data */
-
- spinlock_t completion_lock;/* protects next_completion */
- u32 next_completion;
- rbd_img_callback_t callback;
- /*
- * xferred is the bytes that have successfully been transferred.
- * completed is the bytes that have been accounted for and includes
- * both failed and successfully transffered bytes.
- */
- u64 xferred;/* aggregate bytes transferred */
- u64 completed;
- int result; /* first nonzero obj_request result */
-
- u32 obj_request_count;
- struct list_head obj_requests; /* rbd_obj_request structs */
-
- struct kref kref;
-};
-
#define for_each_obj_request(ireq, oreq) \
list_for_each_entry(oreq, &(ireq)->obj_requests, links)
#define for_each_obj_request_from(ireq, oreq) \
@@ -335,95 +260,6 @@ struct rbd_img_request {
#define for_each_obj_request_safe(ireq, oreq, n) \
list_for_each_entry_safe_reverse(oreq, n, &(ireq)->obj_requests, links)
-enum rbd_watch_state {
- RBD_WATCH_STATE_UNREGISTERED,
- RBD_WATCH_STATE_REGISTERED,
- RBD_WATCH_STATE_ERROR,
-};
-
-enum rbd_lock_state {
- RBD_LOCK_STATE_UNLOCKED,
- RBD_LOCK_STATE_LOCKED,
- RBD_LOCK_STATE_RELEASING,
-};
-
-/* WatchNotify::ClientId */
-struct rbd_client_id {
- u64 gid;
- u64 handle;
-};
-
-struct rbd_mapping {
- u64 size;
- u64 features;
-};
-
-/*
- * a single device
- */
-struct rbd_device {
- int dev_id; /* blkdev unique id */
-
- int major; /* blkdev assigned major */
- int minor;
- struct gendisk *disk; /* blkdev's gendisk and rq */
-
- u32 image_format; /* Either 1 or 2 */
- struct rbd_client *rbd_client;
-
- char name[DEV_NAME_LEN]; /* blkdev name, e.g. rbd3 */
-
- spinlock_t lock; /* queue, flags, open_count */
-
- struct rbd_image_header header;
- unsigned long flags; /* possibly lock protected */
- struct rbd_spec *spec;
- struct rbd_options *opts;
- char *config_info; /* add{,_single_major} string */
-
- struct ceph_object_id header_oid;
- struct ceph_object_locator header_oloc;
-
- struct ceph_file_layout layout; /* used for all rbd requests */
-
- struct mutex watch_mutex;
- enum rbd_watch_state watch_state;
- struct ceph_osd_linger_request *watch_handle;
- u64 watch_cookie;
- struct delayed_work watch_dwork;
-
- struct rw_semaphore lock_rwsem;
- enum rbd_lock_state lock_state;
- char lock_cookie[32];
- struct rbd_client_id owner_cid;
- struct work_struct acquired_lock_work;
- struct work_struct released_lock_work;
- struct delayed_work lock_dwork;
- struct work_struct unlock_work;
- wait_queue_head_t lock_waitq;
-
- struct workqueue_struct *task_wq;
-
- struct rbd_spec *parent_spec;
- u64 parent_overlap;
- atomic_t parent_ref;
- struct rbd_device *parent;
-
- /* Block layer tags. */
- struct blk_mq_tag_set tag_set;
-
- /* protects updating the header */
- struct rw_semaphore header_rwsem;
-
- struct rbd_mapping mapping;
-
- struct list_head node;
-
- /* sysfs related */
- struct device dev;
- unsigned long open_count; /* protected by lock */
-};
-
/*
* Flag bits for rbd_dev->flags:
* - REMOVING (which is coupled with rbd_dev->open_count) is protected
@@ -461,8 +297,6 @@ static bool single_major = true;
module_param(single_major, bool, S_IRUGO);
MODULE_PARM_DESC(single_major, "Use a single major number for all rbd devices (default: true)");
-static int rbd_img_request_submit(struct rbd_img_request *img_request);
-
static ssize_t rbd_add(struct bus_type *bus, const char *buf,
size_t count);
static ssize_t rbd_remove(struct bus_type *bus, const char *buf,
--- /dev/null
+++ b/include/linux/ceph/librbd.h
@@ -0,0 +1,194 @@
+#ifndef _LIBRBD_H
+#define _LIBRBD_H
+
+#include <linux/blk-mq.h>
+#include <linux/device.h>
+
+#define RBD_DRV_NAME "rbd"
+
+/*
+ * An RBD device name will be "rbd#", where the "rbd" comes from
+ * RBD_DRV_NAME above, and # is a unique integer identifier.
+ */
+#define DEV_NAME_LEN 32
+
+/*
+ * block device image metadata (in-memory version)
+ */
+struct rbd_image_header {
+ /* These six fields never change for a given rbd image */
+ char *object_prefix;
+ __u8 obj_order;
+ u64 stripe_unit;
+ u64 stripe_count;
+ s64 data_pool_id;
+ u64 features; /* Might be changeable someday? */
+
+ /* The remaining fields need to be updated occasionally */
+ u64 image_size;
+ struct ceph_snap_context *snapc;
+ char *snap_names; /* format 1 only */
+ u64 *snap_sizes; /* format 1 only */
+};
+
+enum obj_request_type {
+ OBJ_REQUEST_NODATA = 1,
+ OBJ_REQUEST_BIO, /* pointer into provided bio (list) */
+ OBJ_REQUEST_BVECS, /* pointer into provided bio_vec array */
+ OBJ_REQUEST_SG,
+};
+
+enum obj_operation_type {
+ OBJ_OP_READ = 1,
+ OBJ_OP_WRITE,
+ OBJ_OP_DISCARD,
+ OBJ_OP_CMP_AND_WRITE,
+ OBJ_OP_WRITESAME,
+};
+
+struct rbd_img_request;
+typedef void (*rbd_img_callback_t)(struct rbd_img_request *);
+
+struct rbd_obj_request;
+
+struct rbd_img_request {
+ struct rbd_device *rbd_dev;
+ u64 offset; /* starting image byte offset */
+ u64 length; /* byte count from offset */
+ unsigned long flags;
+
+ u64 snap_id; /* for reads */
+ struct ceph_snap_context *snapc; /* for writes */
+
+ struct request *rq; /* block request */
+ struct rbd_obj_request *obj_request; /* obj req initiator */
+ void *lio_cmd_data; /* lio specific data */
+
+ spinlock_t completion_lock;/* protects next_completion */
+ u32 next_completion;
+ rbd_img_callback_t callback;
+ /*
+ * xferred is the bytes that have successfully been transferred.
+ * completed is the bytes that have been accounted for and includes
+ * both failed and successfully transffered bytes.
+ */
+ u64 xferred;/* aggregate bytes transferred */
+ u64 completed;
+ int result; /* first nonzero obj_request result */
+
+ u32 obj_request_count;
+ struct list_head obj_requests; /* rbd_obj_request structs */
+
+ struct kref kref;
+};
+
+struct rbd_mapping {
+ u64 size;
+ u64 features;
+};
+
+enum rbd_watch_state {
+ RBD_WATCH_STATE_UNREGISTERED,
+ RBD_WATCH_STATE_REGISTERED,
+ RBD_WATCH_STATE_ERROR,
+};
+
+enum rbd_lock_state {
+ RBD_LOCK_STATE_UNLOCKED,
+ RBD_LOCK_STATE_LOCKED,
+ RBD_LOCK_STATE_RELEASING,
+};
+
+/* WatchNotify::ClientId */
+struct rbd_client_id {
+ u64 gid;
+ u64 handle;
+};
+
+struct rbd_client;
+struct rbd_spec;
+struct rbd_options;
+
+/*
+ * a single device
+ */
+struct rbd_device {
+ int dev_id; /* blkdev unique id */
+
+ int major; /* blkdev assigned major */
+ int minor;
+ struct gendisk *disk; /* blkdev's gendisk and rq */
+
+ u32 image_format; /* Either 1 or 2 */
+ struct rbd_client *rbd_client;
+
+ char name[DEV_NAME_LEN]; /* blkdev name, e.g. rbd3 */
+
+ spinlock_t lock; /* queue, flags, open_count */
+
+ struct rbd_image_header header;
+ unsigned long flags; /* possibly lock protected */
+ struct rbd_spec *spec;
+ struct rbd_options *opts;
+ char *config_info; /* add{,_single_major} string */
+
+ struct ceph_object_id header_oid;
+ struct ceph_object_locator header_oloc;
+
+ struct ceph_file_layout layout; /* used for all rbd requests */
+
+ struct mutex watch_mutex;
+ enum rbd_watch_state watch_state;
+ struct ceph_osd_linger_request *watch_handle;
+ u64 watch_cookie;
+ struct delayed_work watch_dwork;
+
+ struct rw_semaphore lock_rwsem;
+ enum rbd_lock_state lock_state;
+ char lock_cookie[32];
+ struct rbd_client_id owner_cid;
+ struct work_struct acquired_lock_work;
+ struct work_struct released_lock_work;
+ struct delayed_work lock_dwork;
+ struct work_struct unlock_work;
+ wait_queue_head_t lock_waitq;
+
+ struct workqueue_struct *task_wq;
+
+ struct rbd_spec *parent_spec;
+ u64 parent_overlap;
+ atomic_t parent_ref;
+ struct rbd_device *parent;
+
+ /* Block layer tags. */
+ struct blk_mq_tag_set tag_set;
+
+ /* protects updating the header */
+ struct rw_semaphore header_rwsem;
+
+ struct rbd_mapping mapping;
+
+ struct list_head node;
+
+ /* sysfs related */
+ struct device dev;
+ unsigned long open_count; /* protected by lock */
+};
+
+extern struct rbd_img_request *rbd_img_request_create(
+ struct rbd_device *rbd_dev,
+ u64 offset, u64 length,
+ enum obj_operation_type op_type,
+ struct ceph_snap_context *snapc);
+extern int rbd_img_cmp_and_write_request_fill(
+ struct rbd_img_request *img_request,
+ struct scatterlist *cmp_sgl,
+ u64 cmp_length,
+ struct scatterlist *write_sgl,
+ u64 write_length);
+extern int rbd_img_request_fill(struct rbd_img_request *img_request,
+ enum obj_request_type type, void *data_desc);
+extern int rbd_img_request_submit(struct rbd_img_request *img_request);
+extern void rbd_img_request_put(struct rbd_img_request *img_request);
+
+#endif