Skip to content

Commit a40c4f1

Browse files
Yehuda Sadehliewegas
authored andcommitted
libceph: add lingering request and watch/notify event framework
Lingering requests are requests that are sent to the OSD normally but tracked also after we get a successful request. This keeps the OSD connection open and resends the original request if the object moves to another OSD. The OSD can then send notification messages back to us if another client initiates a notify. This framework will be used by RBD so that the client gets notification when a snapshot is created by another node or tool. Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 55b00ba commit a40c4f1

3 files changed

Lines changed: 426 additions & 12 deletions

File tree

‎include/linux/ceph/osd_client.h‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct ceph_osd {
3232
struct rb_node o_node;
3333
struct ceph_connection o_con;
3434
struct list_head o_requests;
35+
struct list_head o_linger_requests;
3536
struct list_head o_osd_lru;
3637
struct ceph_authorizer *o_authorizer;
3738
void *o_authorizer_buf, *o_authorizer_reply_buf;
@@ -47,6 +48,8 @@ struct ceph_osd_request {
4748
struct rb_node r_node;
4849
struct list_head r_req_lru_item;
4950
struct list_head r_osd_item;
51+
struct list_head r_linger_item;
52+
struct list_head r_linger_osd;
5053
struct ceph_osd *r_osd;
5154
struct ceph_pg r_pgid;
5255
int r_pg_osds[CEPH_PG_MAX_SIZE];
@@ -59,6 +62,7 @@ struct ceph_osd_request {
5962
int r_flags; /* any additional flags for the osd */
6063
u32 r_sent; /* >0 if r_request is sending/sent */
6164
int r_got_reply;
65+
int r_linger;
6266

6367
struct ceph_osd_client *r_osdc;
6468
struct kref r_kref;
@@ -89,6 +93,26 @@ struct ceph_osd_request {
8993
struct ceph_pagelist *r_trail; /* trailing part of the data */
9094
};
9195

96+
struct ceph_osd_event {
97+
u64 cookie;
98+
int one_shot;
99+
struct ceph_osd_client *osdc;
100+
void (*cb)(u64, u64, u8, void *);
101+
void *data;
102+
struct rb_node node;
103+
struct list_head osd_node;
104+
struct kref kref;
105+
struct completion completion;
106+
};
107+
108+
struct ceph_osd_event_work {
109+
struct work_struct work;
110+
struct ceph_osd_event *event;
111+
u64 ver;
112+
u64 notify_id;
113+
u8 opcode;
114+
};
115+
92116
struct ceph_osd_client {
93117
struct ceph_client *client;
94118

@@ -106,6 +130,7 @@ struct ceph_osd_client {
106130
struct list_head req_lru; /* in-flight lru */
107131
struct list_head req_unsent; /* unsent/need-resend queue */
108132
struct list_head req_notarget; /* map to no osd */
133+
struct list_head req_linger; /* lingering requests */
109134
int num_requests;
110135
struct delayed_work timeout_work;
111136
struct delayed_work osds_timeout_work;
@@ -117,6 +142,12 @@ struct ceph_osd_client {
117142

118143
struct ceph_msgpool msgpool_op;
119144
struct ceph_msgpool msgpool_op_reply;
145+
146+
spinlock_t event_lock;
147+
struct rb_root event_tree;
148+
u64 event_count;
149+
150+
struct workqueue_struct *notify_wq;
120151
};
121152

122153
struct ceph_osd_req_op {
@@ -151,6 +182,13 @@ struct ceph_osd_req_op {
151182
struct {
152183
u64 snapid;
153184
} snap;
185+
struct {
186+
u64 cookie;
187+
u64 ver;
188+
__u8 flag;
189+
u32 prot_ver;
190+
u32 timeout;
191+
} watch;
154192
};
155193
u32 payload_len;
156194
};
@@ -199,6 +237,11 @@ extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
199237
bool use_mempool, int num_reply,
200238
int page_align);
201239

240+
extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
241+
struct ceph_osd_request *req);
242+
extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
243+
struct ceph_osd_request *req);
244+
202245
static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
203246
{
204247
kref_get(&req->r_kref);
@@ -234,5 +277,14 @@ extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
234277
struct page **pages, int nr_pages,
235278
int flags, int do_sync, bool nofail);
236279

280+
/* watch/notify events */
281+
extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
282+
void (*event_cb)(u64, u64, u8, void *),
283+
int one_shot, void *data,
284+
struct ceph_osd_event **pevent);
285+
extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
286+
extern int ceph_osdc_wait_event(struct ceph_osd_event *event,
287+
unsigned long timeout);
288+
extern void ceph_osdc_put_event(struct ceph_osd_event *event);
237289
#endif
238290

‎net/ceph/ceph_common.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const char *ceph_msg_type_name(int type)
6262
case CEPH_MSG_OSD_MAP: return "osd_map";
6363
case CEPH_MSG_OSD_OP: return "osd_op";
6464
case CEPH_MSG_OSD_OPREPLY: return "osd_opreply";
65+
case CEPH_MSG_WATCH_NOTIFY: return "watch_notify";
6566
default: return "unknown";
6667
}
6768
}

0 commit comments

Comments
 (0)