13d14c5d2SYehuda Sadeh #ifndef _FS_CEPH_LIBCEPH_H 23d14c5d2SYehuda Sadeh #define _FS_CEPH_LIBCEPH_H 33d14c5d2SYehuda Sadeh 43d14c5d2SYehuda Sadeh #include "ceph_debug.h" 53d14c5d2SYehuda Sadeh 63d14c5d2SYehuda Sadeh #include <asm/unaligned.h> 73d14c5d2SYehuda Sadeh #include <linux/backing-dev.h> 83d14c5d2SYehuda Sadeh #include <linux/completion.h> 93d14c5d2SYehuda Sadeh #include <linux/exportfs.h> 103d14c5d2SYehuda Sadeh #include <linux/fs.h> 113d14c5d2SYehuda Sadeh #include <linux/mempool.h> 123d14c5d2SYehuda Sadeh #include <linux/pagemap.h> 133d14c5d2SYehuda Sadeh #include <linux/wait.h> 143d14c5d2SYehuda Sadeh #include <linux/writeback.h> 153d14c5d2SYehuda Sadeh #include <linux/slab.h> 163d14c5d2SYehuda Sadeh 173d14c5d2SYehuda Sadeh #include "types.h" 183d14c5d2SYehuda Sadeh #include "messenger.h" 193d14c5d2SYehuda Sadeh #include "msgpool.h" 203d14c5d2SYehuda Sadeh #include "mon_client.h" 213d14c5d2SYehuda Sadeh #include "osd_client.h" 223d14c5d2SYehuda Sadeh #include "ceph_fs.h" 233d14c5d2SYehuda Sadeh 243d14c5d2SYehuda Sadeh /* 253d14c5d2SYehuda Sadeh * Supported features 263d14c5d2SYehuda Sadeh */ 273d14c5d2SYehuda Sadeh #define CEPH_FEATURE_SUPPORTED_DEFAULT CEPH_FEATURE_NOSRCADDR 283d14c5d2SYehuda Sadeh #define CEPH_FEATURE_REQUIRED_DEFAULT CEPH_FEATURE_NOSRCADDR 293d14c5d2SYehuda Sadeh 303d14c5d2SYehuda Sadeh /* 313d14c5d2SYehuda Sadeh * mount options 323d14c5d2SYehuda Sadeh */ 333d14c5d2SYehuda Sadeh #define CEPH_OPT_FSID (1<<0) 343d14c5d2SYehuda Sadeh #define CEPH_OPT_NOSHARE (1<<1) /* don't share client with other sbs */ 353d14c5d2SYehuda Sadeh #define CEPH_OPT_MYIP (1<<2) /* specified my ip */ 363d14c5d2SYehuda Sadeh #define CEPH_OPT_NOCRC (1<<3) /* no data crc on writes */ 373d14c5d2SYehuda Sadeh 38497888cfSPhil Carmody #define CEPH_OPT_DEFAULT (0) 393d14c5d2SYehuda Sadeh 403d14c5d2SYehuda Sadeh #define ceph_set_opt(client, opt) \ 413d14c5d2SYehuda Sadeh (client)->options->flags |= CEPH_OPT_##opt; 423d14c5d2SYehuda Sadeh #define ceph_test_opt(client, opt) \ 433d14c5d2SYehuda Sadeh (!!((client)->options->flags & CEPH_OPT_##opt)) 443d14c5d2SYehuda Sadeh 453d14c5d2SYehuda Sadeh struct ceph_options { 463d14c5d2SYehuda Sadeh int flags; 473d14c5d2SYehuda Sadeh struct ceph_fsid fsid; 483d14c5d2SYehuda Sadeh struct ceph_entity_addr my_addr; 493d14c5d2SYehuda Sadeh int mount_timeout; 503d14c5d2SYehuda Sadeh int osd_idle_ttl; 513d14c5d2SYehuda Sadeh int osd_timeout; 523d14c5d2SYehuda Sadeh int osd_keepalive_timeout; 533d14c5d2SYehuda Sadeh 543d14c5d2SYehuda Sadeh /* 553d14c5d2SYehuda Sadeh * any type that can't be simply compared or doesn't need need 563d14c5d2SYehuda Sadeh * to be compared should go beyond this point, 573d14c5d2SYehuda Sadeh * ceph_compare_options() should be updated accordingly 583d14c5d2SYehuda Sadeh */ 593d14c5d2SYehuda Sadeh 603d14c5d2SYehuda Sadeh struct ceph_entity_addr *mon_addr; /* should be the first 613d14c5d2SYehuda Sadeh pointer type of args */ 623d14c5d2SYehuda Sadeh int num_mon; 633d14c5d2SYehuda Sadeh char *name; 648323c3aaSTommi Virtanen struct ceph_crypto_key *key; 653d14c5d2SYehuda Sadeh }; 663d14c5d2SYehuda Sadeh 673d14c5d2SYehuda Sadeh /* 683d14c5d2SYehuda Sadeh * defaults 693d14c5d2SYehuda Sadeh */ 703d14c5d2SYehuda Sadeh #define CEPH_MOUNT_TIMEOUT_DEFAULT 60 713d14c5d2SYehuda Sadeh #define CEPH_OSD_TIMEOUT_DEFAULT 60 /* seconds */ 723d14c5d2SYehuda Sadeh #define CEPH_OSD_KEEPALIVE_DEFAULT 5 733d14c5d2SYehuda Sadeh #define CEPH_OSD_IDLE_TTL_DEFAULT 60 743d14c5d2SYehuda Sadeh 753d14c5d2SYehuda Sadeh #define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024) 763d14c5d2SYehuda Sadeh #define CEPH_MSG_MAX_DATA_LEN (16*1024*1024) 773d14c5d2SYehuda Sadeh 783d14c5d2SYehuda Sadeh #define CEPH_AUTH_NAME_DEFAULT "guest" 793d14c5d2SYehuda Sadeh 803d14c5d2SYehuda Sadeh /* 813d14c5d2SYehuda Sadeh * Delay telling the MDS we no longer want caps, in case we reopen 823d14c5d2SYehuda Sadeh * the file. Delay a minimum amount of time, even if we send a cap 833d14c5d2SYehuda Sadeh * message for some other reason. Otherwise, take the oppotunity to 843d14c5d2SYehuda Sadeh * update the mds to avoid sending another message later. 853d14c5d2SYehuda Sadeh */ 863d14c5d2SYehuda Sadeh #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */ 873d14c5d2SYehuda Sadeh #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */ 883d14c5d2SYehuda Sadeh 893d14c5d2SYehuda Sadeh #define CEPH_CAP_RELEASE_SAFETY_DEFAULT (CEPH_CAPS_PER_RELEASE * 4) 903d14c5d2SYehuda Sadeh 913d14c5d2SYehuda Sadeh /* mount state */ 923d14c5d2SYehuda Sadeh enum { 933d14c5d2SYehuda Sadeh CEPH_MOUNT_MOUNTING, 943d14c5d2SYehuda Sadeh CEPH_MOUNT_MOUNTED, 953d14c5d2SYehuda Sadeh CEPH_MOUNT_UNMOUNTING, 963d14c5d2SYehuda Sadeh CEPH_MOUNT_UNMOUNTED, 973d14c5d2SYehuda Sadeh CEPH_MOUNT_SHUTDOWN, 983d14c5d2SYehuda Sadeh }; 993d14c5d2SYehuda Sadeh 1003d14c5d2SYehuda Sadeh /* 1013d14c5d2SYehuda Sadeh * subtract jiffies 1023d14c5d2SYehuda Sadeh */ 1033d14c5d2SYehuda Sadeh static inline unsigned long time_sub(unsigned long a, unsigned long b) 1043d14c5d2SYehuda Sadeh { 1053d14c5d2SYehuda Sadeh BUG_ON(time_after(b, a)); 1063d14c5d2SYehuda Sadeh return (long)a - (long)b; 1073d14c5d2SYehuda Sadeh } 1083d14c5d2SYehuda Sadeh 1093d14c5d2SYehuda Sadeh struct ceph_mds_client; 1103d14c5d2SYehuda Sadeh 1113d14c5d2SYehuda Sadeh /* 1123d14c5d2SYehuda Sadeh * per client state 1133d14c5d2SYehuda Sadeh * 1143d14c5d2SYehuda Sadeh * possibly shared by multiple mount points, if they are 1153d14c5d2SYehuda Sadeh * mounting the same ceph filesystem/cluster. 1163d14c5d2SYehuda Sadeh */ 1173d14c5d2SYehuda Sadeh struct ceph_client { 1183d14c5d2SYehuda Sadeh struct ceph_fsid fsid; 1193d14c5d2SYehuda Sadeh bool have_fsid; 1203d14c5d2SYehuda Sadeh 1213d14c5d2SYehuda Sadeh void *private; 1223d14c5d2SYehuda Sadeh 1233d14c5d2SYehuda Sadeh struct ceph_options *options; 1243d14c5d2SYehuda Sadeh 1253d14c5d2SYehuda Sadeh struct mutex mount_mutex; /* serialize mount attempts */ 1263d14c5d2SYehuda Sadeh wait_queue_head_t auth_wq; 1273d14c5d2SYehuda Sadeh int auth_err; 1283d14c5d2SYehuda Sadeh 1293d14c5d2SYehuda Sadeh int (*extra_mon_dispatch)(struct ceph_client *, struct ceph_msg *); 1303d14c5d2SYehuda Sadeh 1313d14c5d2SYehuda Sadeh u32 supported_features; 1323d14c5d2SYehuda Sadeh u32 required_features; 1333d14c5d2SYehuda Sadeh 1343d14c5d2SYehuda Sadeh struct ceph_messenger *msgr; /* messenger instance */ 1353d14c5d2SYehuda Sadeh struct ceph_mon_client monc; 1363d14c5d2SYehuda Sadeh struct ceph_osd_client osdc; 1373d14c5d2SYehuda Sadeh 1383d14c5d2SYehuda Sadeh #ifdef CONFIG_DEBUG_FS 1393d14c5d2SYehuda Sadeh struct dentry *debugfs_dir; 1403d14c5d2SYehuda Sadeh struct dentry *debugfs_monmap; 1413d14c5d2SYehuda Sadeh struct dentry *debugfs_osdmap; 1423d14c5d2SYehuda Sadeh #endif 1433d14c5d2SYehuda Sadeh }; 1443d14c5d2SYehuda Sadeh 1453d14c5d2SYehuda Sadeh 1463d14c5d2SYehuda Sadeh 1473d14c5d2SYehuda Sadeh /* 1483d14c5d2SYehuda Sadeh * snapshots 1493d14c5d2SYehuda Sadeh */ 1503d14c5d2SYehuda Sadeh 1513d14c5d2SYehuda Sadeh /* 1523d14c5d2SYehuda Sadeh * A "snap context" is the set of existing snapshots when we 1533d14c5d2SYehuda Sadeh * write data. It is used by the OSD to guide its COW behavior. 1543d14c5d2SYehuda Sadeh * 1553d14c5d2SYehuda Sadeh * The ceph_snap_context is refcounted, and attached to each dirty 1563d14c5d2SYehuda Sadeh * page, indicating which context the dirty data belonged when it was 1573d14c5d2SYehuda Sadeh * dirtied. 1583d14c5d2SYehuda Sadeh */ 1593d14c5d2SYehuda Sadeh struct ceph_snap_context { 1603d14c5d2SYehuda Sadeh atomic_t nref; 1613d14c5d2SYehuda Sadeh u64 seq; 1623d14c5d2SYehuda Sadeh int num_snaps; 1633d14c5d2SYehuda Sadeh u64 snaps[]; 1643d14c5d2SYehuda Sadeh }; 1653d14c5d2SYehuda Sadeh 1663d14c5d2SYehuda Sadeh static inline struct ceph_snap_context * 1673d14c5d2SYehuda Sadeh ceph_get_snap_context(struct ceph_snap_context *sc) 1683d14c5d2SYehuda Sadeh { 1693d14c5d2SYehuda Sadeh /* 1703d14c5d2SYehuda Sadeh printk("get_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref), 1713d14c5d2SYehuda Sadeh atomic_read(&sc->nref)+1); 1723d14c5d2SYehuda Sadeh */ 1733d14c5d2SYehuda Sadeh if (sc) 1743d14c5d2SYehuda Sadeh atomic_inc(&sc->nref); 1753d14c5d2SYehuda Sadeh return sc; 1763d14c5d2SYehuda Sadeh } 1773d14c5d2SYehuda Sadeh 1783d14c5d2SYehuda Sadeh static inline void ceph_put_snap_context(struct ceph_snap_context *sc) 1793d14c5d2SYehuda Sadeh { 1803d14c5d2SYehuda Sadeh if (!sc) 1813d14c5d2SYehuda Sadeh return; 1823d14c5d2SYehuda Sadeh /* 1833d14c5d2SYehuda Sadeh printk("put_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref), 1843d14c5d2SYehuda Sadeh atomic_read(&sc->nref)-1); 1853d14c5d2SYehuda Sadeh */ 1863d14c5d2SYehuda Sadeh if (atomic_dec_and_test(&sc->nref)) { 1873d14c5d2SYehuda Sadeh /*printk(" deleting snap_context %p\n", sc);*/ 1883d14c5d2SYehuda Sadeh kfree(sc); 1893d14c5d2SYehuda Sadeh } 1903d14c5d2SYehuda Sadeh } 1913d14c5d2SYehuda Sadeh 1923d14c5d2SYehuda Sadeh /* 1933d14c5d2SYehuda Sadeh * calculate the number of pages a given length and offset map onto, 1943d14c5d2SYehuda Sadeh * if we align the data. 1953d14c5d2SYehuda Sadeh */ 1963d14c5d2SYehuda Sadeh static inline int calc_pages_for(u64 off, u64 len) 1973d14c5d2SYehuda Sadeh { 1983d14c5d2SYehuda Sadeh return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) - 1993d14c5d2SYehuda Sadeh (off >> PAGE_CACHE_SHIFT); 2003d14c5d2SYehuda Sadeh } 2013d14c5d2SYehuda Sadeh 2023d14c5d2SYehuda Sadeh /* ceph_common.c */ 2033d14c5d2SYehuda Sadeh extern const char *ceph_msg_type_name(int type); 2043d14c5d2SYehuda Sadeh extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid); 2053d14c5d2SYehuda Sadeh extern struct kmem_cache *ceph_inode_cachep; 2063d14c5d2SYehuda Sadeh extern struct kmem_cache *ceph_cap_cachep; 2073d14c5d2SYehuda Sadeh extern struct kmem_cache *ceph_dentry_cachep; 2083d14c5d2SYehuda Sadeh extern struct kmem_cache *ceph_file_cachep; 2093d14c5d2SYehuda Sadeh 2103d14c5d2SYehuda Sadeh extern int ceph_parse_options(struct ceph_options **popt, char *options, 2113d14c5d2SYehuda Sadeh const char *dev_name, const char *dev_name_end, 2123d14c5d2SYehuda Sadeh int (*parse_extra_token)(char *c, void *private), 2133d14c5d2SYehuda Sadeh void *private); 2143d14c5d2SYehuda Sadeh extern void ceph_destroy_options(struct ceph_options *opt); 2153d14c5d2SYehuda Sadeh extern int ceph_compare_options(struct ceph_options *new_opt, 2163d14c5d2SYehuda Sadeh struct ceph_client *client); 2173d14c5d2SYehuda Sadeh extern struct ceph_client *ceph_create_client(struct ceph_options *opt, 218*6ab00d46SSage Weil void *private, 219*6ab00d46SSage Weil unsigned supported_features, 220*6ab00d46SSage Weil unsigned required_features); 2213d14c5d2SYehuda Sadeh extern u64 ceph_client_id(struct ceph_client *client); 2223d14c5d2SYehuda Sadeh extern void ceph_destroy_client(struct ceph_client *client); 2233d14c5d2SYehuda Sadeh extern int __ceph_open_session(struct ceph_client *client, 2243d14c5d2SYehuda Sadeh unsigned long started); 2253d14c5d2SYehuda Sadeh extern int ceph_open_session(struct ceph_client *client); 2263d14c5d2SYehuda Sadeh 2273d14c5d2SYehuda Sadeh /* pagevec.c */ 2283d14c5d2SYehuda Sadeh extern void ceph_release_page_vector(struct page **pages, int num_pages); 2293d14c5d2SYehuda Sadeh 2303d14c5d2SYehuda Sadeh extern struct page **ceph_get_direct_page_vector(const char __user *data, 231b6aa5901SHenry C Chang int num_pages, 232b6aa5901SHenry C Chang bool write_page); 233b6aa5901SHenry C Chang extern void ceph_put_page_vector(struct page **pages, int num_pages, 234b6aa5901SHenry C Chang bool dirty); 2353d14c5d2SYehuda Sadeh extern void ceph_release_page_vector(struct page **pages, int num_pages); 2363d14c5d2SYehuda Sadeh extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags); 2373d14c5d2SYehuda Sadeh extern int ceph_copy_user_to_page_vector(struct page **pages, 2383d14c5d2SYehuda Sadeh const char __user *data, 2393d14c5d2SYehuda Sadeh loff_t off, size_t len); 2403d14c5d2SYehuda Sadeh extern int ceph_copy_to_page_vector(struct page **pages, 2413d14c5d2SYehuda Sadeh const char *data, 2423d14c5d2SYehuda Sadeh loff_t off, size_t len); 2433d14c5d2SYehuda Sadeh extern int ceph_copy_from_page_vector(struct page **pages, 2443d14c5d2SYehuda Sadeh char *data, 2453d14c5d2SYehuda Sadeh loff_t off, size_t len); 2463d14c5d2SYehuda Sadeh extern int ceph_copy_page_vector_to_user(struct page **pages, char __user *data, 2473d14c5d2SYehuda Sadeh loff_t off, size_t len); 2483d14c5d2SYehuda Sadeh extern void ceph_zero_page_vector_range(int off, int len, struct page **pages); 2493d14c5d2SYehuda Sadeh 2503d14c5d2SYehuda Sadeh 2513d14c5d2SYehuda Sadeh #endif /* _FS_CEPH_SUPER_H */ 252