aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorYan, Zheng <zyan@redhat.com>2016-02-13 22:24:31 -0500
committerIlya Dryomov <idryomov@gmail.com>2016-07-27 20:55:37 -0400
commit30c156d9951e0aa88202707d80c583b0a09d3167 (patch)
treeafda9d55374a9b078a5ddd8d5a8c1f2a847eccd5 /net
parent51e9273796a57c08801f45580d3db3c51987a0cb (diff)
libceph: rados pool namespace support
Add pool namesapce pointer to struct ceph_file_layout and struct ceph_object_locator. Pool namespace is used by when mapping object to PG, it's also used when composing OSD request. The namespace pointer in struct ceph_file_layout is RCU protected. So libceph can read namespace without taking lock. Signed-off-by: Yan, Zheng <zyan@redhat.com> [idryomov@gmail.com: ceph_oloc_destroy(), misc minor changes] Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'net')
-rw-r--r--net/ceph/debugfs.c12
-rw-r--r--net/ceph/osd_client.c32
-rw-r--r--net/ceph/osdmap.c52
3 files changed, 81 insertions, 15 deletions
diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
index e77b04ca7802..c62b2b029a6e 100644
--- a/net/ceph/debugfs.c
+++ b/net/ceph/debugfs.c
@@ -156,8 +156,16 @@ static void dump_target(struct seq_file *s, struct ceph_osd_request_target *t)
156 seq_printf(s, "]/%d\t[", t->up.primary); 156 seq_printf(s, "]/%d\t[", t->up.primary);
157 for (i = 0; i < t->acting.size; i++) 157 for (i = 0; i < t->acting.size; i++)
158 seq_printf(s, "%s%d", (!i ? "" : ","), t->acting.osds[i]); 158 seq_printf(s, "%s%d", (!i ? "" : ","), t->acting.osds[i]);
159 seq_printf(s, "]/%d\t%*pE\t0x%x", t->acting.primary, 159 seq_printf(s, "]/%d\t", t->acting.primary);
160 t->target_oid.name_len, t->target_oid.name, t->flags); 160 if (t->target_oloc.pool_ns) {
161 seq_printf(s, "%*pE/%*pE\t0x%x",
162 (int)t->target_oloc.pool_ns->len,
163 t->target_oloc.pool_ns->str,
164 t->target_oid.name_len, t->target_oid.name, t->flags);
165 } else {
166 seq_printf(s, "%*pE\t0x%x", t->target_oid.name_len,
167 t->target_oid.name, t->flags);
168 }
161 if (t->paused) 169 if (t->paused)
162 seq_puts(s, "\tP"); 170 seq_puts(s, "\tP");
163} 171}
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 23efcac80072..b68cc15e9cdc 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -387,7 +387,9 @@ static void target_copy(struct ceph_osd_request_target *dest,
387static void target_destroy(struct ceph_osd_request_target *t) 387static void target_destroy(struct ceph_osd_request_target *t)
388{ 388{
389 ceph_oid_destroy(&t->base_oid); 389 ceph_oid_destroy(&t->base_oid);
390 ceph_oloc_destroy(&t->base_oloc);
390 ceph_oid_destroy(&t->target_oid); 391 ceph_oid_destroy(&t->target_oid);
392 ceph_oloc_destroy(&t->target_oloc);
391} 393}
392 394
393/* 395/*
@@ -533,6 +535,11 @@ struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
533} 535}
534EXPORT_SYMBOL(ceph_osdc_alloc_request); 536EXPORT_SYMBOL(ceph_osdc_alloc_request);
535 537
538static int ceph_oloc_encoding_size(struct ceph_object_locator *oloc)
539{
540 return 8 + 4 + 4 + 4 + (oloc->pool_ns ? oloc->pool_ns->len : 0);
541}
542
536int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp) 543int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp)
537{ 544{
538 struct ceph_osd_client *osdc = req->r_osdc; 545 struct ceph_osd_client *osdc = req->r_osdc;
@@ -540,11 +547,13 @@ int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp)
540 int msg_size; 547 int msg_size;
541 548
542 WARN_ON(ceph_oid_empty(&req->r_base_oid)); 549 WARN_ON(ceph_oid_empty(&req->r_base_oid));
550 WARN_ON(ceph_oloc_empty(&req->r_base_oloc));
543 551
544 /* create request message */ 552 /* create request message */
545 msg_size = 4 + 4 + 4; /* client_inc, osdmap_epoch, flags */ 553 msg_size = 4 + 4 + 4; /* client_inc, osdmap_epoch, flags */
546 msg_size += 4 + 4 + 4 + 8; /* mtime, reassert_version */ 554 msg_size += 4 + 4 + 4 + 8; /* mtime, reassert_version */
547 msg_size += 2 + 4 + 8 + 4 + 4; /* oloc */ 555 msg_size += CEPH_ENCODING_START_BLK_LEN +
556 ceph_oloc_encoding_size(&req->r_base_oloc); /* oloc */
548 msg_size += 1 + 8 + 4 + 4; /* pgid */ 557 msg_size += 1 + 8 + 4 + 4; /* pgid */
549 msg_size += 4 + req->r_base_oid.name_len; /* oid */ 558 msg_size += 4 + req->r_base_oid.name_len; /* oid */
550 msg_size += 2 + req->r_num_ops * sizeof(struct ceph_osd_op); 559 msg_size += 2 + req->r_num_ops * sizeof(struct ceph_osd_op);
@@ -949,6 +958,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
949 958
950 req->r_flags = flags; 959 req->r_flags = flags;
951 req->r_base_oloc.pool = layout->pool_id; 960 req->r_base_oloc.pool = layout->pool_id;
961 req->r_base_oloc.pool_ns = ceph_try_get_string(layout->pool_ns);
952 ceph_oid_printf(&req->r_base_oid, "%llx.%08llx", vino.ino, objnum); 962 ceph_oid_printf(&req->r_base_oid, "%llx.%08llx", vino.ino, objnum);
953 963
954 req->r_snapid = vino.snap; 964 req->r_snapid = vino.snap;
@@ -1489,12 +1499,16 @@ static void encode_request(struct ceph_osd_request *req, struct ceph_msg *msg)
1489 p += sizeof(req->r_replay_version); 1499 p += sizeof(req->r_replay_version);
1490 1500
1491 /* oloc */ 1501 /* oloc */
1492 ceph_encode_8(&p, 4); 1502 ceph_start_encoding(&p, 5, 4,
1493 ceph_encode_8(&p, 4); 1503 ceph_oloc_encoding_size(&req->r_t.target_oloc));
1494 ceph_encode_32(&p, 8 + 4 + 4);
1495 ceph_encode_64(&p, req->r_t.target_oloc.pool); 1504 ceph_encode_64(&p, req->r_t.target_oloc.pool);
1496 ceph_encode_32(&p, -1); /* preferred */ 1505 ceph_encode_32(&p, -1); /* preferred */
1497 ceph_encode_32(&p, 0); /* key len */ 1506 ceph_encode_32(&p, 0); /* key len */
1507 if (req->r_t.target_oloc.pool_ns)
1508 ceph_encode_string(&p, end, req->r_t.target_oloc.pool_ns->str,
1509 req->r_t.target_oloc.pool_ns->len);
1510 else
1511 ceph_encode_32(&p, 0);
1498 1512
1499 /* pgid */ 1513 /* pgid */
1500 ceph_encode_8(&p, 1); 1514 ceph_encode_8(&p, 1);
@@ -2596,8 +2610,8 @@ static int ceph_oloc_decode(void **p, void *end,
2596 if (struct_v >= 5) { 2610 if (struct_v >= 5) {
2597 len = ceph_decode_32(p); 2611 len = ceph_decode_32(p);
2598 if (len > 0) { 2612 if (len > 0) {
2599 pr_warn("ceph_object_locator::nspace is set\n"); 2613 ceph_decode_need(p, end, len, e_inval);
2600 goto e_inval; 2614 *p += len;
2601 } 2615 }
2602 } 2616 }
2603 2617
@@ -2835,7 +2849,11 @@ static void handle_reply(struct ceph_osd *osd, struct ceph_msg *msg)
2835 unlink_request(osd, req); 2849 unlink_request(osd, req);
2836 mutex_unlock(&osd->lock); 2850 mutex_unlock(&osd->lock);
2837 2851
2838 ceph_oloc_copy(&req->r_t.target_oloc, &m.redirect.oloc); 2852 /*
2853 * Not ceph_oloc_copy() - changing pool_ns is not
2854 * supported.
2855 */
2856 req->r_t.target_oloc.pool = m.redirect.oloc.pool;
2839 req->r_flags |= CEPH_OSD_FLAG_REDIRECTED; 2857 req->r_flags |= CEPH_OSD_FLAG_REDIRECTED;
2840 req->r_tid = 0; 2858 req->r_tid = 0;
2841 __submit_request(req, false); 2859 __submit_request(req, false);
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 5947b2e9fb8e..d2436880b305 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -1510,6 +1510,24 @@ bad:
1510 return ERR_PTR(err); 1510 return ERR_PTR(err);
1511} 1511}
1512 1512
1513void ceph_oloc_copy(struct ceph_object_locator *dest,
1514 const struct ceph_object_locator *src)
1515{
1516 WARN_ON(!ceph_oloc_empty(dest));
1517 WARN_ON(dest->pool_ns); /* empty() only covers ->pool */
1518
1519 dest->pool = src->pool;
1520 if (src->pool_ns)
1521 dest->pool_ns = ceph_get_string(src->pool_ns);
1522}
1523EXPORT_SYMBOL(ceph_oloc_copy);
1524
1525void ceph_oloc_destroy(struct ceph_object_locator *oloc)
1526{
1527 ceph_put_string(oloc->pool_ns);
1528}
1529EXPORT_SYMBOL(ceph_oloc_destroy);
1530
1513void ceph_oid_copy(struct ceph_object_id *dest, 1531void ceph_oid_copy(struct ceph_object_id *dest,
1514 const struct ceph_object_id *src) 1532 const struct ceph_object_id *src)
1515{ 1533{
@@ -1844,12 +1862,34 @@ int ceph_object_locator_to_pg(struct ceph_osdmap *osdmap,
1844 if (!pi) 1862 if (!pi)
1845 return -ENOENT; 1863 return -ENOENT;
1846 1864
1847 raw_pgid->pool = oloc->pool; 1865 if (!oloc->pool_ns) {
1848 raw_pgid->seed = ceph_str_hash(pi->object_hash, oid->name, 1866 raw_pgid->pool = oloc->pool;
1849 oid->name_len); 1867 raw_pgid->seed = ceph_str_hash(pi->object_hash, oid->name,
1850 1868 oid->name_len);
1851 dout("%s %s -> raw_pgid %llu.%x\n", __func__, oid->name, 1869 dout("%s %s -> raw_pgid %llu.%x\n", __func__, oid->name,
1852 raw_pgid->pool, raw_pgid->seed); 1870 raw_pgid->pool, raw_pgid->seed);
1871 } else {
1872 char stack_buf[256];
1873 char *buf = stack_buf;
1874 int nsl = oloc->pool_ns->len;
1875 size_t total = nsl + 1 + oid->name_len;
1876
1877 if (total > sizeof(stack_buf)) {
1878 buf = kmalloc(total, GFP_NOIO);
1879 if (!buf)
1880 return -ENOMEM;
1881 }
1882 memcpy(buf, oloc->pool_ns->str, nsl);
1883 buf[nsl] = '\037';
1884 memcpy(buf + nsl + 1, oid->name, oid->name_len);
1885 raw_pgid->pool = oloc->pool;
1886 raw_pgid->seed = ceph_str_hash(pi->object_hash, buf, total);
1887 if (buf != stack_buf)
1888 kfree(buf);
1889 dout("%s %s ns %.*s -> raw_pgid %llu.%x\n", __func__,
1890 oid->name, nsl, oloc->pool_ns->str,
1891 raw_pgid->pool, raw_pgid->seed);
1892 }
1853 return 0; 1893 return 0;
1854} 1894}
1855EXPORT_SYMBOL(ceph_object_locator_to_pg); 1895EXPORT_SYMBOL(ceph_object_locator_to_pg);