Skip to content

Commit 6305a3b

Browse files
Douglas Fulleridryomov
authored andcommitted
libceph: support for blacklisting clients
Reuse ceph_mon_generic_request infrastructure for sending monitor commands. In particular, add support for 'blacklist add' to prevent other, non-responsive clients from making further updates. Signed-off-by: Douglas Fuller <dfuller@redhat.com> [idryomov@gmail.com: refactor, misc fixes throughout] Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Mike Christie <mchristi@redhat.com> Reviewed-by: Alex Elder <elder@linaro.org>
1 parent d4ed4a5 commit 6305a3b

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

include/linux/ceph/ceph_fs.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ struct ceph_dir_layout {
138138
#define CEPH_MSG_POOLOP_REPLY 48
139139
#define CEPH_MSG_POOLOP 49
140140

141+
/* mon commands */
142+
#define CEPH_MSG_MON_COMMAND 50
143+
#define CEPH_MSG_MON_COMMAND_ACK 51
141144

142145
/* osd */
143146
#define CEPH_MSG_OSD_MAP 41
@@ -176,6 +179,14 @@ struct ceph_mon_statfs_reply {
176179
struct ceph_statfs st;
177180
} __attribute__ ((packed));
178181

182+
struct ceph_mon_command {
183+
struct ceph_mon_request_header monhdr;
184+
struct ceph_fsid fsid;
185+
__le32 num_strs; /* always 1 */
186+
__le32 str_len;
187+
char str[];
188+
} __attribute__ ((packed));
189+
179190
struct ceph_osd_getmap {
180191
struct ceph_mon_request_header monhdr;
181192
struct ceph_fsid fsid;

include/linux/ceph/mon_client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
141141
int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
142142
ceph_monc_callback_t cb, u64 private_data);
143143

144+
int ceph_monc_blacklist_add(struct ceph_mon_client *monc,
145+
struct ceph_entity_addr *client_addr);
146+
144147
extern int ceph_monc_open_session(struct ceph_mon_client *monc);
145148

146149
extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);

net/ceph/mon_client.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,83 @@ int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
835835
}
836836
EXPORT_SYMBOL(ceph_monc_get_version_async);
837837

838+
static void handle_command_ack(struct ceph_mon_client *monc,
839+
struct ceph_msg *msg)
840+
{
841+
struct ceph_mon_generic_request *req;
842+
void *p = msg->front.iov_base;
843+
void *const end = p + msg->front_alloc_len;
844+
u64 tid = le64_to_cpu(msg->hdr.tid);
845+
846+
dout("%s msg %p tid %llu\n", __func__, msg, tid);
847+
848+
ceph_decode_need(&p, end, sizeof(struct ceph_mon_request_header) +
849+
sizeof(u32), bad);
850+
p += sizeof(struct ceph_mon_request_header);
851+
852+
mutex_lock(&monc->mutex);
853+
req = lookup_generic_request(&monc->generic_request_tree, tid);
854+
if (!req) {
855+
mutex_unlock(&monc->mutex);
856+
return;
857+
}
858+
859+
req->result = ceph_decode_32(&p);
860+
__finish_generic_request(req);
861+
mutex_unlock(&monc->mutex);
862+
863+
complete_generic_request(req);
864+
return;
865+
866+
bad:
867+
pr_err("corrupt mon_command ack, tid %llu\n", tid);
868+
ceph_msg_dump(msg);
869+
}
870+
871+
int ceph_monc_blacklist_add(struct ceph_mon_client *monc,
872+
struct ceph_entity_addr *client_addr)
873+
{
874+
struct ceph_mon_generic_request *req;
875+
struct ceph_mon_command *h;
876+
int ret = -ENOMEM;
877+
int len;
878+
879+
req = alloc_generic_request(monc, GFP_NOIO);
880+
if (!req)
881+
goto out;
882+
883+
req->request = ceph_msg_new(CEPH_MSG_MON_COMMAND, 256, GFP_NOIO, true);
884+
if (!req->request)
885+
goto out;
886+
887+
req->reply = ceph_msg_new(CEPH_MSG_MON_COMMAND_ACK, 512, GFP_NOIO,
888+
true);
889+
if (!req->reply)
890+
goto out;
891+
892+
mutex_lock(&monc->mutex);
893+
register_generic_request(req);
894+
h = req->request->front.iov_base;
895+
h->monhdr.have_version = 0;
896+
h->monhdr.session_mon = cpu_to_le16(-1);
897+
h->monhdr.session_mon_tid = 0;
898+
h->fsid = monc->monmap->fsid;
899+
h->num_strs = cpu_to_le32(1);
900+
len = sprintf(h->str, "{ \"prefix\": \"osd blacklist\", \
901+
\"blacklistop\": \"add\", \
902+
\"addr\": \"%pISpc/%u\" }",
903+
&client_addr->in_addr, le32_to_cpu(client_addr->nonce));
904+
h->str_len = cpu_to_le32(len);
905+
send_generic_request(monc, req);
906+
mutex_unlock(&monc->mutex);
907+
908+
ret = wait_generic_request(req);
909+
out:
910+
put_generic_request(req);
911+
return ret;
912+
}
913+
EXPORT_SYMBOL(ceph_monc_blacklist_add);
914+
838915
/*
839916
* Resend pending generic requests.
840917
*/
@@ -1139,6 +1216,10 @@ static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
11391216
handle_get_version_reply(monc, msg);
11401217
break;
11411218

1219+
case CEPH_MSG_MON_COMMAND_ACK:
1220+
handle_command_ack(monc, msg);
1221+
break;
1222+
11421223
case CEPH_MSG_MON_MAP:
11431224
ceph_monc_handle_map(monc, msg);
11441225
break;
@@ -1178,6 +1259,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
11781259
m = ceph_msg_get(monc->m_subscribe_ack);
11791260
break;
11801261
case CEPH_MSG_STATFS_REPLY:
1262+
case CEPH_MSG_MON_COMMAND_ACK:
11811263
return get_generic_reply(con, hdr, skip);
11821264
case CEPH_MSG_AUTH_REPLY:
11831265
m = ceph_msg_get(monc->m_auth_reply);

0 commit comments

Comments
 (0)