diff options
author | Yehuda Sadeh <yehuda@hq.newdream.net> | 2010-04-06 15:14:15 -0700 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2010-10-20 15:37:28 -0700 |
commit | 3d14c5d2b6e15c21d8e5467dc62d33127c23a644 (patch) | |
tree | 7d123c47847df9d1e865b6b78dc7da3fe739b704 /fs/ceph | |
parent | ae1533b62b3369e6ae32338f4a77d64d0e88f676 (diff) |
ceph: factor out libceph from Ceph file system
This factors out protocol and low-level storage parts of ceph into a
separate libceph module living in net/ceph and include/linux/ceph. This
is mostly a matter of moving files around. However, a few key pieces
of the interface change as well:
- ceph_client becomes ceph_fs_client and ceph_client, where the latter
captures the mon and osd clients, and the fs_client gets the mds client
and file system specific pieces.
- Mount option parsing and debugfs setup is correspondingly broken into
two pieces.
- The mon client gets a generic handler callback for otherwise unknown
messages (mds map, in this case).
- The basic supported/required feature bits can be expanded (and are by
ceph_fs_client).
No functional change, aside from some subtle error handling cases that got
cleaned up in the refactoring process.
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph')
62 files changed, 926 insertions, 14078 deletions
diff --git a/fs/ceph/Kconfig b/fs/ceph/Kconfig index 0fcd2640c23f..9eb134ea6eb2 100644 --- a/fs/ceph/Kconfig +++ b/fs/ceph/Kconfig @@ -1,9 +1,11 @@ config CEPH_FS tristate "Ceph distributed file system (EXPERIMENTAL)" depends on INET && EXPERIMENTAL + select CEPH_LIB select LIBCRC32C select CRYPTO_AES select CRYPTO + default n help Choose Y or M here to include support for mounting the experimental Ceph distributed file system. Ceph is an extremely @@ -14,15 +16,3 @@ config CEPH_FS If unsure, say N. -config CEPH_FS_PRETTYDEBUG - bool "Include file:line in ceph debug output" - depends on CEPH_FS - default n - help - If you say Y here, debug output will include a filename and - line to aid debugging. This icnreases kernel size and slows - execution slightly when debug call sites are enabled (e.g., - via CONFIG_DYNAMIC_DEBUG). - - If unsure, say N. - diff --git a/fs/ceph/Makefile b/fs/ceph/Makefile index 278e1172600d..9e6c4f2e8ff1 100644 --- a/fs/ceph/Makefile +++ b/fs/ceph/Makefile @@ -8,15 +8,8 @@ obj-$(CONFIG_CEPH_FS) += ceph.o ceph-objs := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \ export.o caps.o snap.o xattr.o \ - messenger.o msgpool.o buffer.o pagelist.o \ - mds_client.o mdsmap.o \ - mon_client.o \ - osd_client.o osdmap.o crush/crush.o crush/mapper.o crush/hash.o \ - debugfs.o \ - auth.o auth_none.o \ - crypto.o armor.o \ - auth_x.o \ - ceph_fs.o ceph_strings.o ceph_hash.o ceph_frag.o + mds_client.o mdsmap.o strings.o ceph_frag.o \ + debugfs.o else #Otherwise we were called directly from the command diff --git a/fs/ceph/README b/fs/ceph/README deleted file mode 100644 index 18352fab37c0..000000000000 --- a/fs/ceph/README +++ /dev/null @@ -1,20 +0,0 @@ -# -# The following files are shared by (and manually synchronized -# between) the Ceph userland and kernel client. -# -# userland kernel -src/include/ceph_fs.h fs/ceph/ceph_fs.h -src/include/ceph_fs.cc fs/ceph/ceph_fs.c -src/include/msgr.h fs/ceph/msgr.h -src/include/rados.h fs/ceph/rados.h -src/include/ceph_strings.cc fs/ceph/ceph_strings.c -src/include/ceph_frag.h fs/ceph/ceph_frag.h -src/include/ceph_frag.cc fs/ceph/ceph_frag.c -src/include/ceph_hash.h fs/ceph/ceph_hash.h -src/include/ceph_hash.cc fs/ceph/ceph_hash.c -src/crush/crush.c fs/ceph/crush/crush.c -src/crush/crush.h fs/ceph/crush/crush.h -src/crush/mapper.c fs/ceph/crush/mapper.c -src/crush/mapper.h fs/ceph/crush/mapper.h -src/crush/hash.h fs/ceph/crush/hash.h -src/crush/hash.c fs/ceph/crush/hash.c diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index efbc604001c8..51bcc5ce3230 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -1,4 +1,4 @@ -#include "ceph_debug.h" +#include <linux/ceph/ceph_debug.h> #include <linux/backing-dev.h> #include <linux/fs.h> @@ -10,7 +10,8 @@ #include <linux/task_io_accounting_ops.h> #include "super.h" -#include "osd_client.h" +#include "mds_client.h" +#include <linux/ceph/osd_client.h> /* * Ceph address space ops. @@ -193,7 +194,8 @@ static int readpage_nounlock(struct file *filp, struct page *page) { struct inode *inode = filp->f_dentry->d_inode; struct ceph_inode_info *ci = ceph_inode(inode); - struct ceph_osd_client *osdc = &ceph_inode_to_client(inode)->osdc; + struct ceph_osd_client *osdc = + &ceph_inode_to_client(inode)->client->osdc; int err = 0; u64 len = PAGE_CACHE_SIZE; @@ -265,7 +267,8 @@ static int ceph_readpages(struct file *file, struct address_space *mapping, { struct inode *inode = file->f_dentry->d_inode; struct ceph_inode_info *ci = ceph_inode(inode); - struct ceph_osd_client *osdc = &ceph_inode_to_client(inode)->osdc; + struct ceph_osd_client *osdc = + &ceph_inode_to_client(inode)->client->osdc; int rc = 0; struct page **pages; loff_t offset; @@ -365,7 +368,7 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) { struct inode *inode; struct ceph_inode_info *ci; - struct ceph_client *client; + struct ceph_fs_client *fsc; struct ceph_osd_client *osdc; loff_t page_off = page->index << PAGE_CACHE_SHIFT; int len = PAGE_CACHE_SIZE; @@ -383,8 +386,8 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) } inode = page->mapping->host; ci = ceph_inode(inode); - client = ceph_inode_to_client(inode); - osdc = &client->osdc; + fsc = ceph_inode_to_client(inode); + osdc = &fsc->client->osdc; /* verify this is a writeable snap context */ snapc = (void *)page->private; @@ -414,10 +417,10 @@ static int writepage_nounlock(struct page *page, struct writeback_control *wbc) dout("writepage %p page %p index %lu on %llu~%u snapc %p\n", inode, page, page->index, page_off, len, snapc); - writeback_stat = atomic_long_inc_return(&client->writeback_count); + writeback_stat = atomic_long_inc_return(&fsc->writeback_count); if (writeback_stat > - CONGESTION_ON_THRESH(client->mount_args->congestion_kb)) - set_bdi_congested(&client->backing_dev_info, BLK_RW_ASYNC); + CONGESTION_ON_THRESH(fsc->mount_options->congestion_kb)) + set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC); set_page_writeback(page); err = ceph_osdc_writepages(osdc, ceph_vino(inode), @@ -496,7 +499,7 @@ static void writepages_finish(struct ceph_osd_request *req, struct address_space *mapping = inode->i_mapping; __s32 rc = -EIO; u64 bytes = 0; - struct ceph_client *client = ceph_inode_to_client(inode); + struct ceph_fs_client *fsc = ceph_inode_to_client(inode); long writeback_stat; unsigned issued = ceph_caps_issued(ci); @@ -529,10 +532,10 @@ static void writepages_finish(struct ceph_osd_request *req, WARN_ON(!PageUptodate(page)); writeback_stat = - atomic_long_dec_return(&client->writeback_count); + atomic_long_dec_return(&fsc->writeback_count); if (writeback_stat < - CONGESTION_OFF_THRESH(client->mount_args->congestion_kb)) - clear_bdi_congested(&client->backing_dev_info, + CONGESTION_OFF_THRESH(fsc->mount_options->congestion_kb)) + clear_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC); ceph_put_snap_context((void *)page->private); @@ -569,13 +572,13 @@ static void writepages_finish(struct ceph_osd_request *req, * mempool. we avoid the mempool if we can because req->r_num_pages * may be less than the maximum write size. */ -static void alloc_page_vec(struct ceph_client *client, +static void alloc_page_vec(struct ceph_fs_client *fsc, struct ceph_osd_request *req) { req->r_pages = kmalloc(sizeof(struct page *) * req->r_num_pages, GFP_NOFS); if (!req->r_pages) { - req->r_pages = mempool_alloc(client->wb_pagevec_pool, GFP_NOFS); + req->r_pages = mempool_alloc(fsc->wb_pagevec_pool, GFP_NOFS); req->r_pages_from_pool = 1; WARN_ON(!req->r_pages); } @@ -590,7 +593,7 @@ static int ceph_writepages_start(struct address_space *mapping, struct inode *inode = mapping->host; struct backing_dev_info *bdi = mapping->backing_dev_info; struct ceph_inode_info *ci = ceph_inode(inode); - struct ceph_client *client; + struct ceph_fs_client *fsc; pgoff_t index, start, end; int range_whole = 0; int should_loop = 1; @@ -617,13 +620,13 @@ static int ceph_writepages_start(struct address_space *mapping, wbc->sync_mode == WB_SYNC_NONE ? "NONE" : (wbc->sync_mode == WB_SYNC_ALL ? "ALL" : "HOLD")); - client = ceph_inode_to_client(inode); - if (client->mount_state == CEPH_MOUNT_SHUTDOWN) { + fsc = ceph_inode_to_client(inode); + if (fsc->mount_state == CEPH_MOUNT_SHUTDOWN) { pr_warning("writepage_start %p on forced umount\n", inode); return -EIO; /* we're in a forced umount, don't write! */ } - if (client->mount_args->wsize && client->mount_args->wsize < wsize) - wsize = client->mount_args->wsize; + if (fsc->mount_options->wsize && fsc->mount_options->wsize < wsize) + wsize = fsc->mount_options->wsize; if (wsize < PAGE_CACHE_SIZE) wsize = PAGE_CACHE_SIZE; max_pages_ever = wsize >> PAGE_CACHE_SHIFT; @@ -769,7 +772,7 @@ get_more_pages: offset = (unsigned long long)page->index << PAGE_CACHE_SHIFT; len = wsize; - req = ceph_osdc_new_request(&client->osdc, + req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout, ceph_vino(inode), offset, &len, @@ -782,7 +785,7 @@ get_more_pages: &inode->i_mtime, true, 1); max_pages = req->r_num_pages; - alloc_page_vec(client, req); + alloc_page_vec(fsc, req); req->r_callback = writepages_finish; req->r_inode = inode; } @@ -794,10 +797,10 @@ get_more_pages: inode, page, page->index); writeback_stat = - atomic_long_inc_return(&client->writeback_count); + atomic_long_inc_return(&fsc->writeback_count); if (writeback_stat > CONGESTION_ON_THRESH( - client->mount_args->congestion_kb)) { - set_bdi_congested(&client->backing_dev_info, + fsc->mount_options->congestion_kb)) { + set_bdi_congested(&fsc->backing_dev_info, BLK_RW_ASYNC); } @@ -846,7 +849,7 @@ get_more_pages: op->payload_len = cpu_to_le32(len); req->r_request->hdr.data_len = cpu_to_le32(len); - ceph_osdc_start_request(&client->osdc, req, true); + ceph_osdc_start_request(&fsc->client->osdc, req, true); req = NULL; /* continue? */ @@ -915,7 +918,7 @@ static int ceph_update_writeable_page(struct file *file, { struct inode *inode = file->f_dentry->d_inode; struct ceph_inode_info *ci = ceph_inode(inode); - struct ceph_mds_client *mdsc = &ceph_inode_to_client(inode)->mdsc; + struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; loff_t page_off = pos & PAGE_CACHE_MASK; int pos_in_page = pos & ~PAGE_CACHE_MASK; int end_in_page = pos_in_page + len; @@ -1053,8 +1056,8 @@ static int ceph_write_end(struct file *file, struct address_space *mapping, struct page *page, void *fsdata) { struct inode *inode = file->f_dentry->d_inode; - struct ceph_client *client = ceph_inode_to_client(inode); - struct ceph_mds_client *mdsc = &client->mdsc; + struct ceph_fs_client *fsc = ceph_inode_to_client(inode); + struct ceph_mds_client *mdsc = fsc->mdsc; unsigned from = pos & (PAGE_CACHE_SIZE - 1); int check_cap = 0; @@ -1123,7 +1126,7 @@ static int ceph_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) { struct inode *inode = vma->vm_file->f_dentry->d_inode; struct page *page = vmf->page; - struct ceph_mds_client *mdsc = &ceph_inode_to_client(inode)->mdsc; + struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; loff_t off = page->index << PAGE_CACHE_SHIFT; loff_t size, len; int ret; diff --git a/fs/ceph/armor.c b/fs/ceph/armor.c deleted file mode 100644 index eb2a666b0be7..000000000000 --- a/fs/ceph/armor.c +++ /dev/null @@ -1,103 +0,0 @@ - -#include <linux/errno.h> - -int ceph_armor(char *dst, const char *src, const char *end); -int ceph_unarmor(char *dst, const char *src, const char *end); - -/* - * base64 encode/decode. - */ - -static const char *pem_key = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -static int encode_bits(int c) -{ - return pem_key[c]; -} - -static int decode_bits(char c) -{ - if (c >= 'A' && c <= 'Z') - return c - 'A'; - if (c >= 'a' && c <= 'z') - return c - 'a' + 26; - if (c >= '0' && c <= '9') - return c - '0' + 52; - if (c == '+') - return 62; - if (c == '/') - return 63; - if (c == '=') - return 0; /* just non-negative, please */ - return -EINVAL; -} - -int ceph_armor(char *dst, const char *src, const char *end) -{ - int olen = 0; - int line = 0; - - while (src < end) { - unsigned char a, b, c; - - a = *src++; - *dst++ = encode_bits(a >> 2); - if (src < end) { - b = *src++; - *dst++ = encode_bits(((a & 3) << 4) | (b >> 4)); - if (src < end) { - c = *src++; - *dst++ = encode_bits(((b & 15) << 2) | - (c >> 6)); - *dst++ = encode_bits(c & 63); - } else { - *dst++ = encode_bits((b & 15) << 2); - *dst++ = '='; - } - } else { - *dst++ = encode_bits(((a & 3) << 4)); - *dst++ = '='; - *dst++ = '='; - } - olen += 4; - line += 4; - if (line == 64) { - line = 0; - *(dst++) = '\n'; - olen++; - } - } - return olen; -} - -int ceph_unarmor(char *dst, const char *src, const char *end) -{ - int olen = 0; - - while (src < end) { - int a, b, c, d; - - if (src < end && src[0] == '\n') - src++; - if (src + 4 > end) - return -EINVAL; - a = decode_bits(src[0]); - b = decode_bits(src[1]); - c = decode_bits(src[2]); - d = decode_bits(src[3]); - if (a < 0 || b < 0 || c < 0 || d < 0) - return -EINVAL; - - *dst++ = (a << 2) | (b >> 4); - if (src[2] == '=') - return olen + 1; - *dst++ = ((b & 15) << 4) | (c >> 2); - if (src[3] == '=') - return olen + 2; - *dst++ = ((c & 3) << 6) | d; - olen += 3; - src += 4; - } - return olen; -} diff --git a/fs/ceph/auth.c b/fs/ceph/auth.c deleted file mode 100644 index 6d2e30600627..000000000000 --- a/fs/ceph/auth.c +++ /dev/null @@ -1,259 +0,0 @@ -#include "ceph_debug.h" - -#include <linux/module.h> -#include <linux/err.h> -#include <linux/slab.h> - -#include "types.h" -#include "auth_none.h" -#include "auth_x.h" -#include "decode.h" -#include "super.h" - -#include "messenger.h" - -/* - * get protocol handler - */ -static u32 supported_protocols[] = { - CEPH_AUTH_NONE, - CEPH_AUTH_CEPHX -}; - -static int ceph_auth_init_protocol(struct ceph_auth_client *ac, int protocol) -{ - switch (protocol) { - case CEPH_AUTH_NONE: - return ceph_auth_none_init(ac); - case CEPH_AUTH_CEPHX: - return ceph_x_init(ac); - default: - return -ENOENT; - } -} - -/* - * setup, teardown. - */ -struct ceph_auth_client *ceph_auth_init(const char *name, const char *secret) -{ - struct ceph_auth_client *ac; - int ret; - - dout("auth_init name '%s' secret '%s'\n", name, secret); - - ret = -ENOMEM; - ac = kzalloc(sizeof(*ac), GFP_NOFS); - if (!ac) - goto out; - - ac->negotiating = true; - if (name) - ac->name = name; - else - ac->name = CEPH_AUTH_NAME_DEFAULT; - dout("auth_init name %s secret %s\n", ac->name, secret); - ac->secret = secret; - return ac; - -out: - return ERR_PTR(ret); -} - -void ceph_auth_destroy(struct ceph_auth_client *ac) -{ - dout("auth_destroy %p\n", ac); - if (ac->ops) - ac->ops->destroy(ac); - kfree(ac); -} - -/* - * Reset occurs when reconnecting to the monitor. - */ -void ceph_auth_reset(struct ceph_auth_client *ac) -{ - dout("auth_reset %p\n", ac); - if (ac->ops && !ac->negotiating) - ac->ops->reset(ac); - ac->negotiating = true; -} - -int ceph_entity_name_encode(const char *name, void **p, void *end) -{ - int len = strlen(name); - - if (*p + 2*sizeof(u32) + len > end) - return -ERANGE; - ceph_encode_32(p, CEPH_ENTITY_TYPE_CLIENT); - ceph_encode_32(p, len); - ceph_encode_copy(p, name, len); - return 0; -} - -/* - * Initiate protocol negotiation with monitor. Include entity name - * and list supported protocols. - */ -int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len) -{ - struct ceph_mon_request_header *monhdr = buf; - void *p = monhdr + 1, *end = buf + len, *lenp; - int i, num; - int ret; - - dout("auth_build_hello\n"); - monhdr->have_version = 0; - monhdr->session_mon = cpu_to_le16(-1); - monhdr->session_mon_tid = 0; - - ceph_encode_32(&p, 0); /* no protocol, yet */ - - lenp = p; - p += sizeof(u32); - - ceph_decode_need(&p, end, 1 + sizeof(u32), bad); - ceph_encode_8(&p, 1); - num = ARRAY_SIZE(supported_protocols); - ceph_encode_32(&p, num); - ceph_decode_need(&p, end, num * sizeof(u32), bad); - for (i = 0; i < num; i++) - ceph_encode_32(&p, supported_protocols[i]); - - ret = ceph_entity_name_encode(ac->name, &p, end); - if (ret < 0) - return ret; - ceph_decode_need(&p, end, sizeof(u64), bad); - ceph_encode_64(&p, ac->global_id); - - ceph_encode_32(&lenp, p - lenp - sizeof(u32)); - return p - buf; - -bad: - return -ERANGE; -} - -static int ceph_build_auth_request(struct ceph_auth_client *ac, - void *msg_buf, size_t msg_len) -{ - struct ceph_mon_request_header *monhdr = msg_buf; - void *p = monhdr + 1; - void *end = msg_buf + msg_len; - int ret; - - monhdr->have_version = 0; - monhdr->session_mon = cpu_to_le16(-1); - monhdr->session_mon_tid = 0; - - ceph_encode_32(&p, ac->protocol); - - ret = ac->ops->build_request(ac, p + sizeof(u32), end); - if (ret < 0) { - pr_err("error %d building auth method %s request\n", ret, - ac->ops->name); - return ret; - } - dout(" built request %d bytes\n", ret); - ceph_encode_32(&p, ret); - return p + ret - msg_buf; -} - -/* - * Handle auth message from monitor. - */ -int ceph_handle_auth_reply(struct ceph_auth_client *ac, - void *buf, size_t len, - void *reply_buf, size_t reply_len) -{ - void *p = buf; - void *end = buf + len; - int protocol; - s32 result; - u64 global_id; - void *payload, *payload_end; - int payload_len; - char *result_msg; - int result_msg_len; - int ret = -EINVAL; - - dout("handle_auth_reply %p %p\n", p, end); - ceph_decode_need(&p, end, sizeof(u32) * 3 + sizeof(u64), bad); - protocol = ceph_decode_32(&p); - result = ceph_decode_32(&p); - global_id = ceph_decode_64(&p); - payload_len = ceph_decode_32(&p); - payload = p; - p += payload_len; - ceph_decode_need(&p, end, sizeof(u32), bad); - result_msg_len = ceph_decode_32(&p); - result_msg = p; - p += result_msg_len; - if (p != end) - goto bad; - - dout(" result %d '%.*s' gid %llu len %d\n", result, result_msg_len, - result_msg, global_id, payload_len); - - payload_end = payload + payload_len; - - if (global_id && ac->global_id != global_id) { - dout(" set global_id %lld -> %lld\n", ac->global_id, global_id); - ac->global_id = global_id; - } - - if (ac->negotiating) { - /* server does not support our protocols? */ - if (!protocol && result < 0) { - ret = result; - goto out; - } - /* set up (new) protocol handler? */ - if (ac->protocol && ac->protocol != protocol) { - ac->ops->destroy(ac); - ac->protocol = 0; - ac->ops = NULL; - } - if (ac->protocol != protocol) { - ret = ceph_auth_init_protocol(ac, protocol); - if (ret) { - pr_err("error %d on auth protocol %d init\n", - ret, protocol); - goto out; - } - } - - ac->negotiating = false; - } - - ret = ac->ops->handle_reply(ac, result, payload, payload_end); - if (ret == -EAGAIN) { - return ceph_build_auth_request(ac, reply_buf, reply_len); - } else if (ret) { - pr_err("auth method '%s' error %d\n", ac->ops->name, ret); - return ret; - } - return 0; - -bad: - pr_err("failed to decode auth msg\n"); -out: - return ret; -} - -int ceph_build_auth(struct ceph_auth_client *ac, - void *msg_buf, size_t msg_len) -{ |