Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libceph, rbd: ignore addr->type while comparing in some cases

For libceph, this ensures that libceph instance sharing (share option)
continues to work. For rbd, this avoids blocklisting alive lock owners
(locker addr is always LEGACY, while watcher addr is ANY in nautilus).

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>

+18 -5
+6 -2
drivers/block/rbd.c
··· 3957 3957 3958 3958 sscanf(locker->id.cookie, RBD_LOCK_COOKIE_PREFIX " %llu", &cookie); 3959 3959 for (i = 0; i < num_watchers; i++) { 3960 - if (!memcmp(&watchers[i].addr, &locker->info.addr, 3961 - sizeof(locker->info.addr)) && 3960 + /* 3961 + * Ignore addr->type while comparing. This mimics 3962 + * entity_addr_t::get_legacy_str() + strcmp(). 3963 + */ 3964 + if (ceph_addr_equal_no_type(&watchers[i].addr, 3965 + &locker->info.addr) && 3962 3966 watchers[i].cookie == cookie) { 3963 3967 struct rbd_client_id cid = { 3964 3968 .gid = le64_to_cpu(watchers[i].name.num),
+8 -1
include/linux/ceph/msgr.h
··· 52 52 * entity_addr -- network address 53 53 */ 54 54 struct ceph_entity_addr { 55 - __le32 type; 55 + __le32 type; /* CEPH_ENTITY_ADDR_TYPE_* */ 56 56 __le32 nonce; /* unique id for process (e.g. pid) */ 57 57 struct sockaddr_storage in_addr; 58 58 } __attribute__ ((packed)); 59 + 60 + static inline bool ceph_addr_equal_no_type(const struct ceph_entity_addr *lhs, 61 + const struct ceph_entity_addr *rhs) 62 + { 63 + return !memcmp(&lhs->in_addr, &rhs->in_addr, sizeof(lhs->in_addr)) && 64 + lhs->nonce == rhs->nonce; 65 + } 59 66 60 67 struct ceph_entity_inst { 61 68 struct ceph_entity_name name;
+4 -2
net/ceph/mon_client.c
··· 161 161 { 162 162 int i; 163 163 164 - for (i = 0; i < m->num_mon; i++) 165 - if (memcmp(addr, &m->mon_inst[i].addr, sizeof(*addr)) == 0) 164 + for (i = 0; i < m->num_mon; i++) { 165 + if (ceph_addr_equal_no_type(addr, &m->mon_inst[i].addr)) 166 166 return 1; 167 + } 168 + 167 169 return 0; 168 170 } 169 171