Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) #include <linux/ceph/ceph_debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/ceph/ceph_features.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/ceph/mon_client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/ceph/libceph.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/ceph/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/ceph/decode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/ceph/auth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * Interact with Ceph monitor cluster.  Handle requests for new map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * versions, and periodically resend as needed.  Also implement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * statfs() and umount().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * A small cluster of Ceph "monitors" are responsible for managing critical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * cluster configuration and state information.  An odd number (e.g., 3, 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * of cmon daemons use a modified version of the Paxos part-time parliament
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * algorithm to manage the MDS map (mds cluster membership), OSD map, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * list of clients who have mounted the file system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * We maintain an open, active session with a monitor at all times in order to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * receive timely MDSMap updates.  We periodically send a keepalive byte on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * TCP socket to ensure we detect a failure.  If the connection does break, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  * randomly hunt for a new monitor.  Once the connection is reestablished, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * resend any outstanding requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static const struct ceph_connection_operations mon_con_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) static int __validate_auth(struct ceph_mon_client *monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  * Decode a monmap blob (e.g., during mount).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) static struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	struct ceph_monmap *m = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	int i, err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	struct ceph_fsid fsid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	u32 epoch, num_mon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	ceph_decode_32_safe(&p, end, len, bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	ceph_decode_need(&p, end, len, bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	dout("monmap_decode %p %p len %d (%d)\n", p, end, len, (int)(end-p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	p += sizeof(u16);  /* skip version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	ceph_decode_copy(&p, &fsid, sizeof(fsid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	epoch = ceph_decode_32(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	num_mon = ceph_decode_32(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	if (num_mon > CEPH_MAX_MON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	m = kmalloc(struct_size(m, mon_inst, num_mon), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	if (m == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	m->fsid = fsid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	m->epoch = epoch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	m->num_mon = num_mon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	for (i = 0; i < num_mon; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		struct ceph_entity_inst *inst = &m->mon_inst[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 		/* copy name portion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		ceph_decode_copy_safe(&p, end, &inst->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 					sizeof(inst->name), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 		err = ceph_decode_entity_addr(&p, end, &inst->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 			goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	dout("monmap_decode epoch %d, num_mon %d\n", m->epoch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	     m->num_mon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	for (i = 0; i < m->num_mon; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		dout("monmap_decode  mon%d is %s\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 		     ceph_pr_addr(&m->mon_inst[i].addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	return m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	dout("monmap_decode failed with %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	kfree(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  * return true if *addr is included in the monmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) int ceph_monmap_contains(struct ceph_monmap *m, struct ceph_entity_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	for (i = 0; i < m->num_mon; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		if (memcmp(addr, &m->mon_inst[i].addr, sizeof(*addr)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  * Send an auth request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static void __send_prepared_auth_request(struct ceph_mon_client *monc, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	monc->pending_auth = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	monc->m_auth->front.iov_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	monc->m_auth->hdr.front_len = cpu_to_le32(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	ceph_msg_revoke(monc->m_auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	ceph_msg_get(monc->m_auth);  /* keep our ref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	ceph_con_send(&monc->con, monc->m_auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119)  * Close monitor session, if any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) static void __close_session(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	dout("__close_session closing mon%d\n", monc->cur_mon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	ceph_msg_revoke(monc->m_auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	ceph_msg_revoke_incoming(monc->m_auth_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	ceph_msg_revoke(monc->m_subscribe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	ceph_msg_revoke_incoming(monc->m_subscribe_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	ceph_con_close(&monc->con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	monc->pending_auth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	ceph_auth_reset(monc->auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)  * Pick a new monitor at random and set cur_mon.  If we are repicking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  * (i.e. cur_mon is already set), be sure to pick a different one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static void pick_new_mon(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	int old_mon = monc->cur_mon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	BUG_ON(monc->monmap->num_mon < 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	if (monc->monmap->num_mon == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		monc->cur_mon = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		int max = monc->monmap->num_mon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		int o = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		if (monc->cur_mon >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 			if (monc->cur_mon < monc->monmap->num_mon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 				o = monc->cur_mon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 			if (o >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 				max--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		n = prandom_u32() % max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		if (o >= 0 && n >= o)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 			n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		monc->cur_mon = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	dout("%s mon%d -> mon%d out of %d mons\n", __func__, old_mon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	     monc->cur_mon, monc->monmap->num_mon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * Open a session with a new monitor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) static void __open_session(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	pick_new_mon(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	monc->hunting = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	if (monc->had_a_connection) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		monc->hunt_mult *= CEPH_MONC_HUNT_BACKOFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		if (monc->hunt_mult > CEPH_MONC_HUNT_MAX_MULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 			monc->hunt_mult = CEPH_MONC_HUNT_MAX_MULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	monc->sub_renew_after = jiffies; /* i.e., expired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	monc->sub_renew_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	dout("%s opening mon%d\n", __func__, monc->cur_mon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	ceph_con_open(&monc->con, CEPH_ENTITY_TYPE_MON, monc->cur_mon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		      &monc->monmap->mon_inst[monc->cur_mon].addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	 * send an initial keepalive to ensure our timestamp is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	 * by the time we are in an OPENED state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	ceph_con_keepalive(&monc->con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	/* initiate authentication handshake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	ret = ceph_auth_build_hello(monc->auth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 				    monc->m_auth->front.iov_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 				    monc->m_auth->front_alloc_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	BUG_ON(ret <= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	__send_prepared_auth_request(monc, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) static void reopen_session(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	if (!monc->hunting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		pr_info("mon%d %s session lost, hunting for new mon\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		    monc->cur_mon, ceph_pr_addr(&monc->con.peer_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	__close_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	__open_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) void ceph_monc_reopen_session(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	reopen_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static void un_backoff(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	monc->hunt_mult /= 2; /* reduce by 50% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	if (monc->hunt_mult < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		monc->hunt_mult = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	dout("%s hunt_mult now %d\n", __func__, monc->hunt_mult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232)  * Reschedule delayed work timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) static void __schedule_delayed(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	if (monc->hunting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		delay = CEPH_MONC_HUNT_INTERVAL * monc->hunt_mult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		delay = CEPH_MONC_PING_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	dout("__schedule_delayed after %lu\n", delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	mod_delayed_work(system_wq, &monc->delayed_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 			 round_jiffies_relative(delay));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) const char *ceph_sub_str[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	[CEPH_SUB_MONMAP] = "monmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	[CEPH_SUB_OSDMAP] = "osdmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	[CEPH_SUB_FSMAP]  = "fsmap.user",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	[CEPH_SUB_MDSMAP] = "mdsmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)  * Send subscribe request for one or more maps, according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)  * monc->subs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) static void __send_subscribe(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	struct ceph_msg *msg = monc->m_subscribe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	void *p = msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	void *const end = p + msg->front_alloc_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	dout("%s sent %lu\n", __func__, monc->sub_renew_sent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	BUG_ON(monc->cur_mon < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	if (!monc->sub_renew_sent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		monc->sub_renew_sent = jiffies | 1; /* never 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	msg->hdr.version = cpu_to_le16(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	for (i = 0; i < ARRAY_SIZE(monc->subs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		if (monc->subs[i].want)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 			num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	BUG_ON(num < 1); /* monmap sub is always there */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	ceph_encode_32(&p, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	for (i = 0; i < ARRAY_SIZE(monc->subs); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		char buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		if (!monc->subs[i].want)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		len = sprintf(buf, "%s", ceph_sub_str[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		if (i == CEPH_SUB_MDSMAP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		    monc->fs_cluster_id != CEPH_FS_CLUSTER_ID_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 			len += sprintf(buf + len, ".%d", monc->fs_cluster_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		dout("%s %s start %llu flags 0x%x\n", __func__, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		     le64_to_cpu(monc->subs[i].item.start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		     monc->subs[i].item.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		ceph_encode_string(&p, end, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		memcpy(p, &monc->subs[i].item, sizeof(monc->subs[i].item));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		p += sizeof(monc->subs[i].item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	BUG_ON(p > end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	msg->front.iov_len = p - msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	ceph_msg_revoke(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	ceph_con_send(&monc->con, ceph_msg_get(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) static void handle_subscribe_ack(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 				 struct ceph_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	unsigned int seconds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	struct ceph_mon_subscribe_ack *h = msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	if (msg->front.iov_len < sizeof(*h))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	seconds = le32_to_cpu(h->duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	if (monc->sub_renew_sent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		 * This is only needed for legacy (infernalis or older)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		 * MONs -- see delayed_work().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		monc->sub_renew_after = monc->sub_renew_sent +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 					    (seconds >> 1) * HZ - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		dout("%s sent %lu duration %d renew after %lu\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		     monc->sub_renew_sent, seconds, monc->sub_renew_after);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		monc->sub_renew_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		dout("%s sent %lu renew after %lu, ignoring\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		     monc->sub_renew_sent, monc->sub_renew_after);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	pr_err("got corrupt subscribe-ack msg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	ceph_msg_dump(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342)  * Register interest in a map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344)  * @sub: one of CEPH_SUB_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345)  * @epoch: X for "every map since X", or 0 for "just the latest"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) static bool __ceph_monc_want_map(struct ceph_mon_client *monc, int sub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 				 u32 epoch, bool continuous)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	__le64 start = cpu_to_le64(epoch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	u8 flags = !continuous ? CEPH_SUBSCRIBE_ONETIME : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	dout("%s %s epoch %u continuous %d\n", __func__, ceph_sub_str[sub],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	     epoch, continuous);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (monc->subs[sub].want &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	    monc->subs[sub].item.start == start &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	    monc->subs[sub].item.flags == flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	monc->subs[sub].item.start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	monc->subs[sub].item.flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	monc->subs[sub].want = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) bool ceph_monc_want_map(struct ceph_mon_client *monc, int sub, u32 epoch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			bool continuous)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	bool need_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	need_request = __ceph_monc_want_map(monc, sub, epoch, continuous);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	return need_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) EXPORT_SYMBOL(ceph_monc_want_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382)  * Keep track of which maps we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)  * @sub: one of CEPH_SUB_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) static void __ceph_monc_got_map(struct ceph_mon_client *monc, int sub,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 				u32 epoch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	dout("%s %s epoch %u\n", __func__, ceph_sub_str[sub], epoch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	if (monc->subs[sub].want) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		if (monc->subs[sub].item.flags & CEPH_SUBSCRIBE_ONETIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			monc->subs[sub].want = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			monc->subs[sub].item.start = cpu_to_le64(epoch + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	monc->subs[sub].have = epoch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) void ceph_monc_got_map(struct ceph_mon_client *monc, int sub, u32 epoch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	__ceph_monc_got_map(monc, sub, epoch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) EXPORT_SYMBOL(ceph_monc_got_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) void ceph_monc_renew_subs(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	__send_subscribe(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) EXPORT_SYMBOL(ceph_monc_renew_subs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  * Wait for an osdmap with a given epoch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)  * @epoch: epoch to wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)  * @timeout: in jiffies, 0 means "wait forever"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 			  unsigned long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	unsigned long started = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	while (monc->subs[CEPH_SUB_OSDMAP].have < epoch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		if (timeout && time_after_eq(jiffies, started + timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 			return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		ret = wait_event_interruptible_timeout(monc->client->auth_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 				     monc->subs[CEPH_SUB_OSDMAP].have >= epoch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 				     ceph_timeout_jiffies(timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) EXPORT_SYMBOL(ceph_monc_wait_osdmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  * Open a session with a random monitor.  Request monmap and osdmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)  * which are waited upon in __ceph_open_session().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) int ceph_monc_open_session(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	__ceph_monc_want_map(monc, CEPH_SUB_MONMAP, 0, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	__ceph_monc_want_map(monc, CEPH_SUB_OSDMAP, 0, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	__open_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	__schedule_delayed(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) EXPORT_SYMBOL(ceph_monc_open_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) static void ceph_monc_handle_map(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				 struct ceph_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	struct ceph_client *client = monc->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	struct ceph_monmap *monmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	void *p, *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	dout("handle_monmap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	p = msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	end = p + msg->front.iov_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	monmap = ceph_monmap_decode(p, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	if (IS_ERR(monmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		pr_err("problem decoding monmap, %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		       (int)PTR_ERR(monmap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		ceph_msg_dump(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	if (ceph_check_fsid(client, &monmap->fsid) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		kfree(monmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	kfree(monc->monmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	monc->monmap = monmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	__ceph_monc_got_map(monc, CEPH_SUB_MONMAP, monc->monmap->epoch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	client->have_fsid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	wake_up_all(&client->auth_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504)  * generic requests (currently statfs, mon_get_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) DEFINE_RB_FUNCS(generic_request, struct ceph_mon_generic_request, tid, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) static void release_generic_request(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	struct ceph_mon_generic_request *req =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		container_of(kref, struct ceph_mon_generic_request, kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	dout("%s greq %p request %p reply %p\n", __func__, req, req->request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	     req->reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	WARN_ON(!RB_EMPTY_NODE(&req->node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	if (req->reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		ceph_msg_put(req->reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	if (req->request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		ceph_msg_put(req->request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) static void put_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	if (req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		kref_put(&req->kref, release_generic_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) static void get_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	kref_get(&req->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) static struct ceph_mon_generic_request *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) alloc_generic_request(struct ceph_mon_client *monc, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	req = kzalloc(sizeof(*req), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	req->monc = monc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	kref_init(&req->kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	RB_CLEAR_NODE(&req->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	init_completion(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	dout("%s greq %p\n", __func__, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) static void register_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	struct ceph_mon_client *monc = req->monc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	WARN_ON(req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	get_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	req->tid = ++monc->last_tid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	insert_generic_request(&monc->generic_request_tree, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) static void send_generic_request(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 				 struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	WARN_ON(!req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	dout("%s greq %p tid %llu\n", __func__, req, req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	req->request->hdr.tid = cpu_to_le64(req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	ceph_con_send(&monc->con, ceph_msg_get(req->request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static void __finish_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	struct ceph_mon_client *monc = req->monc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	dout("%s greq %p tid %llu\n", __func__, req, req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	erase_generic_request(&monc->generic_request_tree, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	ceph_msg_revoke(req->request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	ceph_msg_revoke_incoming(req->reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) static void finish_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	__finish_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	put_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) static void complete_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	if (req->complete_cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		req->complete_cb(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		complete_all(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	put_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) static void cancel_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	struct ceph_mon_client *monc = req->monc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	struct ceph_mon_generic_request *lookup_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	dout("%s greq %p tid %llu\n", __func__, req, req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	lookup_req = lookup_generic_request(&monc->generic_request_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 					    req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	if (lookup_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		WARN_ON(lookup_req != req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		finish_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) static int wait_generic_request(struct ceph_mon_generic_request *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	dout("%s greq %p tid %llu\n", __func__, req, req->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	ret = wait_for_completion_interruptible(&req->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		cancel_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		ret = req->result; /* completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) static struct ceph_msg *get_generic_reply(struct ceph_connection *con,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 					 struct ceph_msg_header *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 					 int *skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	struct ceph_mon_client *monc = con->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	u64 tid = le64_to_cpu(hdr->tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	struct ceph_msg *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	req = lookup_generic_request(&monc->generic_request_tree, tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		dout("get_generic_reply %lld dne\n", tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		*skip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		m = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		dout("get_generic_reply %lld got %p\n", tid, req->reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		*skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		m = ceph_msg_get(req->reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		 * we don't need to track the connection reading into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		 * this reply because we only have one open connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		 * at a time, ever.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	return m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)  * statfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) static void handle_statfs_reply(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 				struct ceph_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	struct ceph_mon_statfs_reply *reply = msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	u64 tid = le64_to_cpu(msg->hdr.tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	dout("%s msg %p tid %llu\n", __func__, msg, tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	if (msg->front.iov_len != sizeof(*reply))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	req = lookup_generic_request(&monc->generic_request_tree, tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	req->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	*req->u.st = reply->st; /* struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	__finish_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	complete_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	pr_err("corrupt statfs reply, tid %llu\n", tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	ceph_msg_dump(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698)  * Do a synchronous statfs().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) int ceph_monc_do_statfs(struct ceph_mon_client *monc, u64 data_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			struct ceph_statfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	struct ceph_mon_statfs *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	req = alloc_generic_request(monc, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	req->request = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), GFP_NOFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 				    true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	if (!req->request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	req->reply = ceph_msg_new(CEPH_MSG_STATFS_REPLY, 64, GFP_NOFS, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	if (!req->reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	req->u.st = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	req->request->hdr.version = cpu_to_le16(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	register_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	/* fill out request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	h = req->request->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	h->monhdr.have_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	h->monhdr.session_mon = cpu_to_le16(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	h->monhdr.session_mon_tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	h->fsid = monc->monmap->fsid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	h->contains_data_pool = (data_pool != CEPH_NOPOOL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	h->data_pool = cpu_to_le64(data_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	send_generic_request(monc, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	ret = wait_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	put_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) EXPORT_SYMBOL(ceph_monc_do_statfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) static void handle_get_version_reply(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 				     struct ceph_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	u64 tid = le64_to_cpu(msg->hdr.tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	void *p = msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	void *end = p + msg->front_alloc_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	u64 handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	dout("%s msg %p tid %llu\n", __func__, msg, tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	ceph_decode_need(&p, end, 2*sizeof(u64), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	handle = ceph_decode_64(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	if (tid != 0 && tid != handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	req = lookup_generic_request(&monc->generic_request_tree, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	req->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	req->u.newest = ceph_decode_64(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	__finish_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	complete_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	pr_err("corrupt mon_get_version reply, tid %llu\n", tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	ceph_msg_dump(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) static struct ceph_mon_generic_request *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) __ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			ceph_monc_callback_t cb, u64 private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	req = alloc_generic_request(monc, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		goto err_put_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	req->request = ceph_msg_new(CEPH_MSG_MON_GET_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 				    sizeof(u64) + sizeof(u32) + strlen(what),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 				    GFP_NOIO, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	if (!req->request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		goto err_put_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	req->reply = ceph_msg_new(CEPH_MSG_MON_GET_VERSION_REPLY, 32, GFP_NOIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 				  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (!req->reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		goto err_put_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	req->complete_cb = cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	req->private_data = private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	register_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		void *p = req->request->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		void *const end = p + req->request->front_alloc_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		ceph_encode_64(&p, req->tid); /* handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		ceph_encode_string(&p, end, what, strlen(what));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		WARN_ON(p != end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	send_generic_request(monc, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	return req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) err_put_req:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	put_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  * Send MMonGetVersion and wait for the reply.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  * @what: one of "mdsmap", "osdmap" or "monmap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) int ceph_monc_get_version(struct ceph_mon_client *monc, const char *what,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			  u64 *newest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	req = __ceph_monc_get_version(monc, what, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		return PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	ret = wait_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		*newest = req->u.newest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	put_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) EXPORT_SYMBOL(ceph_monc_get_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848)  * Send MMonGetVersion,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850)  * @what: one of "mdsmap", "osdmap" or "monmap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) int ceph_monc_get_version_async(struct ceph_mon_client *monc, const char *what,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 				ceph_monc_callback_t cb, u64 private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	req = __ceph_monc_get_version(monc, what, cb, private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	if (IS_ERR(req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		return PTR_ERR(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	put_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) EXPORT_SYMBOL(ceph_monc_get_version_async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) static void handle_command_ack(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 			       struct ceph_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	void *p = msg->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	void *const end = p + msg->front_alloc_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	u64 tid = le64_to_cpu(msg->hdr.tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	dout("%s msg %p tid %llu\n", __func__, msg, tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	ceph_decode_need(&p, end, sizeof(struct ceph_mon_request_header) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 							    sizeof(u32), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	p += sizeof(struct ceph_mon_request_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	req = lookup_generic_request(&monc->generic_request_tree, tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	req->result = ceph_decode_32(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	__finish_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	complete_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	pr_err("corrupt mon_command ack, tid %llu\n", tid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	ceph_msg_dump(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) static __printf(2, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) int do_mon_command_vargs(struct ceph_mon_client *monc, const char *fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			 va_list ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	struct ceph_mon_command *h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	req = alloc_generic_request(monc, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	req->request = ceph_msg_new(CEPH_MSG_MON_COMMAND, 256, GFP_NOIO, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	if (!req->request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	req->reply = ceph_msg_new(CEPH_MSG_MON_COMMAND_ACK, 512, GFP_NOIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 				  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	if (!req->reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	register_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	h = req->request->front.iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	h->monhdr.have_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	h->monhdr.session_mon = cpu_to_le16(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	h->monhdr.session_mon_tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	h->fsid = monc->monmap->fsid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	h->num_strs = cpu_to_le32(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	len = vsprintf(h->str, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	h->str_len = cpu_to_le32(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	send_generic_request(monc, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	ret = wait_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	put_generic_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) static __printf(2, 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) int do_mon_command(struct ceph_mon_client *monc, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	va_start(ap, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	ret = do_mon_command_vargs(monc, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) int ceph_monc_blocklist_add(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			    struct ceph_entity_addr *client_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	ret = do_mon_command(monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 			     "{ \"prefix\": \"osd blocklist\", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 				\"blocklistop\": \"add\", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 				\"addr\": \"%pISpc/%u\" }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 			     &client_addr->in_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			     le32_to_cpu(client_addr->nonce));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if (ret == -EINVAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		 * The monitor returns EINVAL on an unrecognized command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		 * Try the legacy command -- it is exactly the same except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		 * for the name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		ret = do_mon_command(monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 				     "{ \"prefix\": \"osd blacklist\", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 					\"blacklistop\": \"add\", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 					\"addr\": \"%pISpc/%u\" }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 				     &client_addr->in_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 				     le32_to_cpu(client_addr->nonce));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	 * Make sure we have the osdmap that includes the blocklist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	 * entry.  This is needed to ensure that the OSDs pick up the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	 * new blocklist before processing any future requests from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	 * this client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	return ceph_wait_for_latest_osdmap(monc->client, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) EXPORT_SYMBOL(ceph_monc_blocklist_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990)  * Resend pending generic requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) static void __resend_generic_request(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	struct ceph_mon_generic_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	struct rb_node *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		req = rb_entry(p, struct ceph_mon_generic_request, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		ceph_msg_revoke(req->request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		ceph_msg_revoke_incoming(req->reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		ceph_con_send(&monc->con, ceph_msg_get(req->request));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)  * Delayed work.  If we haven't mounted yet, retry.  Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)  * renew/retry subscription as needed (in case it is timing out, or we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)  * got an ENOMEM).  And keep the monitor connection alive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) static void delayed_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	struct ceph_mon_client *monc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		container_of(work, struct ceph_mon_client, delayed_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	dout("monc delayed_work\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	if (monc->hunting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		dout("%s continuing hunt\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		reopen_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		int is_auth = ceph_auth_is_authenticated(monc->auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		if (ceph_con_keepalive_expired(&monc->con,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 					       CEPH_MONC_PING_TIMEOUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 			dout("monc keepalive timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 			is_auth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			reopen_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		if (!monc->hunting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			ceph_con_keepalive(&monc->con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			__validate_auth(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			un_backoff(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		if (is_auth &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		    !(monc->con.peer_features & CEPH_FEATURE_MON_STATEFUL_SUB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 			dout("%s renew subs? now %lu renew after %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			     __func__, now, monc->sub_renew_after);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			if (time_after_eq(now, monc->sub_renew_after))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 				__send_subscribe(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	__schedule_delayed(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)  * On startup, we build a temporary monmap populated with the IPs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)  * provided by mount(2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) static int build_initial_monmap(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	struct ceph_options *opt = monc->client->options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	struct ceph_entity_addr *mon_addr = opt->mon_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	int num_mon = opt->num_mon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	/* build initial monmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	monc->monmap = kzalloc(struct_size(monc->monmap, mon_inst, num_mon),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 			       GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	if (!monc->monmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	for (i = 0; i < num_mon; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		monc->monmap->mon_inst[i].addr = mon_addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		monc->monmap->mon_inst[i].addr.nonce = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		monc->monmap->mon_inst[i].name.type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 			CEPH_ENTITY_TYPE_MON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		monc->monmap->mon_inst[i].name.num = cpu_to_le64(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	monc->monmap->num_mon = num_mon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	dout("init\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	memset(monc, 0, sizeof(*monc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	monc->client = cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	monc->monmap = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	mutex_init(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	err = build_initial_monmap(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	/* connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	/* authentication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	monc->auth = ceph_auth_init(cl->options->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 				    cl->options->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	if (IS_ERR(monc->auth)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		err = PTR_ERR(monc->auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		goto out_monmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	monc->auth->want_keys =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		CEPH_ENTITY_TYPE_AUTH | CEPH_ENTITY_TYPE_MON |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		CEPH_ENTITY_TYPE_OSD | CEPH_ENTITY_TYPE_MDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	/* msgs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	monc->m_subscribe_ack = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 				     sizeof(struct ceph_mon_subscribe_ack),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 				     GFP_KERNEL, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	if (!monc->m_subscribe_ack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		goto out_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	monc->m_subscribe = ceph_msg_new(CEPH_MSG_MON_SUBSCRIBE, 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 					 GFP_KERNEL, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	if (!monc->m_subscribe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		goto out_subscribe_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	monc->m_auth_reply = ceph_msg_new(CEPH_MSG_AUTH_REPLY, 4096,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 					  GFP_KERNEL, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	if (!monc->m_auth_reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		goto out_subscribe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	monc->m_auth = ceph_msg_new(CEPH_MSG_AUTH, 4096, GFP_KERNEL, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	monc->pending_auth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	if (!monc->m_auth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		goto out_auth_reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	ceph_con_init(&monc->con, monc, &mon_con_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		      &monc->client->msgr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	monc->cur_mon = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	monc->had_a_connection = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	monc->hunt_mult = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	INIT_DELAYED_WORK(&monc->delayed_work, delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	monc->generic_request_tree = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	monc->last_tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	monc->fs_cluster_id = CEPH_FS_CLUSTER_ID_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) out_auth_reply:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	ceph_msg_put(monc->m_auth_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) out_subscribe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	ceph_msg_put(monc->m_subscribe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) out_subscribe_ack:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	ceph_msg_put(monc->m_subscribe_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) out_auth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	ceph_auth_destroy(monc->auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) out_monmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	kfree(monc->monmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) EXPORT_SYMBOL(ceph_monc_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) void ceph_monc_stop(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	dout("stop\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	cancel_delayed_work_sync(&monc->delayed_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	__close_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	monc->cur_mon = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	 * flush msgr queue before we destroy ourselves to ensure that:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	 *  - any work that references our embedded con is finished.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	 *  - any osd_client or other work that may reference an authorizer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	 *    finishes before we shut down the auth subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	ceph_msgr_flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	ceph_auth_destroy(monc->auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	WARN_ON(!RB_EMPTY_ROOT(&monc->generic_request_tree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	ceph_msg_put(monc->m_auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	ceph_msg_put(monc->m_auth_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	ceph_msg_put(monc->m_subscribe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	ceph_msg_put(monc->m_subscribe_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	kfree(monc->monmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) EXPORT_SYMBOL(ceph_monc_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) static void finish_hunting(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	if (monc->hunting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		dout("%s found mon%d\n", __func__, monc->cur_mon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		monc->hunting = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		monc->had_a_connection = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		un_backoff(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		__schedule_delayed(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static void handle_auth_reply(struct ceph_mon_client *monc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 			      struct ceph_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	int was_auth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	was_auth = ceph_auth_is_authenticated(monc->auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	monc->pending_auth = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	ret = ceph_handle_auth_reply(monc->auth, msg->front.iov_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 				     msg->front.iov_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 				     monc->m_auth->front.iov_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 				     monc->m_auth->front_alloc_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		__send_prepared_auth_request(monc, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	finish_hunting(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		monc->client->auth_err = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	} else if (!was_auth && ceph_auth_is_authenticated(monc->auth)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		dout("authenticated, starting session\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		monc->client->msgr.inst.name.type = CEPH_ENTITY_TYPE_CLIENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		monc->client->msgr.inst.name.num =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 					cpu_to_le64(monc->auth->global_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		__send_subscribe(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		__resend_generic_request(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 		pr_info("mon%d %s session established\n", monc->cur_mon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 			ceph_pr_addr(&monc->con.peer_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	if (monc->client->auth_err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		wake_up_all(&monc->client->auth_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) static int __validate_auth(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	if (monc->pending_auth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	ret = ceph_build_auth(monc->auth, monc->m_auth->front.iov_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 			      monc->m_auth->front_alloc_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		return ret; /* either an error, or no need to authenticate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	__send_prepared_auth_request(monc, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) int ceph_monc_validate_auth(struct ceph_mon_client *monc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	ret = __validate_auth(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) EXPORT_SYMBOL(ceph_monc_validate_auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)  * handle incoming message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	struct ceph_mon_client *monc = con->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	int type = le16_to_cpu(msg->hdr.type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	case CEPH_MSG_AUTH_REPLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		handle_auth_reply(monc, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	case CEPH_MSG_MON_SUBSCRIBE_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		handle_subscribe_ack(monc, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	case CEPH_MSG_STATFS_REPLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		handle_statfs_reply(monc, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	case CEPH_MSG_MON_GET_VERSION_REPLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		handle_get_version_reply(monc, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	case CEPH_MSG_MON_COMMAND_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		handle_command_ack(monc, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	case CEPH_MSG_MON_MAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 		ceph_monc_handle_map(monc, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	case CEPH_MSG_OSD_MAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		ceph_osdc_handle_map(&monc->client->osdc, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		/* can the chained handler handle it? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 		if (monc->client->extra_mon_dispatch &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		    monc->client->extra_mon_dispatch(monc->client, msg) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		pr_err("received unknown message type %d %s\n", type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		       ceph_msg_type_name(type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	ceph_msg_put(msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)  * Allocate memory for incoming message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 				      struct ceph_msg_header *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 				      int *skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	struct ceph_mon_client *monc = con->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	int type = le16_to_cpu(hdr->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	int front_len = le32_to_cpu(hdr->front_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	struct ceph_msg *m = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	*skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	case CEPH_MSG_MON_SUBSCRIBE_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		m = ceph_msg_get(monc->m_subscribe_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	case CEPH_MSG_STATFS_REPLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	case CEPH_MSG_MON_COMMAND_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		return get_generic_reply(con, hdr, skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	case CEPH_MSG_AUTH_REPLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		m = ceph_msg_get(monc->m_auth_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	case CEPH_MSG_MON_GET_VERSION_REPLY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		if (le64_to_cpu(hdr->tid) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 			return get_generic_reply(con, hdr, skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		 * Older OSDs don't set reply tid even if the orignal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		 * request had a non-zero tid.  Work around this weirdness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		 * by allocating a new message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	case CEPH_MSG_MON_MAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	case CEPH_MSG_MDS_MAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	case CEPH_MSG_OSD_MAP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	case CEPH_MSG_FS_MAP_USER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		m = ceph_msg_new(type, front_len, GFP_NOFS, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		if (!m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 			return NULL;	/* ENOMEM--return skip == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	if (!m) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		pr_info("alloc_msg unknown type %d\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		*skip = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	} else if (front_len > m->front_alloc_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		pr_warn("mon_alloc_msg front %d > prealloc %d (%u#%llu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			front_len, m->front_alloc_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			(unsigned int)con->peer_name.type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			le64_to_cpu(con->peer_name.num));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		ceph_msg_put(m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		m = ceph_msg_new(type, front_len, GFP_NOFS, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	return m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)  * If the monitor connection resets, pick a new monitor and resubmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)  * any pending requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static void mon_fault(struct ceph_connection *con)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	struct ceph_mon_client *monc = con->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	mutex_lock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	dout("%s mon%d\n", __func__, monc->cur_mon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	if (monc->cur_mon >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		if (!monc->hunting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 			dout("%s hunting for new mon\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 			reopen_session(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			__schedule_delayed(monc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 			dout("%s already hunting\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	mutex_unlock(&monc->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)  * We can ignore refcounting on the connection struct, as all references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)  * will come from the messenger workqueue, which is drained prior to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)  * mon_client destruction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) static struct ceph_connection *con_get(struct ceph_connection *con)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	return con;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) static void con_put(struct ceph_connection *con)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) static const struct ceph_connection_operations mon_con_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	.get = con_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	.put = con_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	.dispatch = dispatch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	.fault = mon_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	.alloc_msg = mon_alloc_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) };