linux/include/linux/ceph/libceph.h
<<
>>
Prefs
   1#ifndef _FS_CEPH_LIBCEPH_H
   2#define _FS_CEPH_LIBCEPH_H
   3
   4#include <linux/ceph/ceph_debug.h>
   5
   6#include <asm/unaligned.h>
   7#include <linux/backing-dev.h>
   8#include <linux/completion.h>
   9#include <linux/exportfs.h>
  10#include <linux/bug.h>
  11#include <linux/fs.h>
  12#include <linux/mempool.h>
  13#include <linux/pagemap.h>
  14#include <linux/wait.h>
  15#include <linux/writeback.h>
  16#include <linux/slab.h>
  17
  18#include <linux/ceph/types.h>
  19#include <linux/ceph/messenger.h>
  20#include <linux/ceph/msgpool.h>
  21#include <linux/ceph/mon_client.h>
  22#include <linux/ceph/osd_client.h>
  23#include <linux/ceph/ceph_fs.h>
  24
  25/*
  26 * mount options
  27 */
  28#define CEPH_OPT_FSID             (1<<0)
  29#define CEPH_OPT_NOSHARE          (1<<1) /* don't share client with other sbs */
  30#define CEPH_OPT_MYIP             (1<<2) /* specified my ip */
  31#define CEPH_OPT_NOCRC            (1<<3) /* no data crc on writes */
  32
  33#define CEPH_OPT_DEFAULT   (0)
  34
  35#define ceph_set_opt(client, opt) \
  36        (client)->options->flags |= CEPH_OPT_##opt;
  37#define ceph_test_opt(client, opt) \
  38        (!!((client)->options->flags & CEPH_OPT_##opt))
  39
  40struct ceph_options {
  41        int flags;
  42        struct ceph_fsid fsid;
  43        struct ceph_entity_addr my_addr;
  44        int mount_timeout;
  45        int osd_idle_ttl;
  46        int osd_keepalive_timeout;
  47
  48        /*
  49         * any type that can't be simply compared or doesn't need need
  50         * to be compared should go beyond this point,
  51         * ceph_compare_options() should be updated accordingly
  52         */
  53
  54        struct ceph_entity_addr *mon_addr; /* should be the first
  55                                              pointer type of args */
  56        int num_mon;
  57        char *name;
  58        struct ceph_crypto_key *key;
  59};
  60
  61/*
  62 * defaults
  63 */
  64#define CEPH_MOUNT_TIMEOUT_DEFAULT  60
  65#define CEPH_OSD_KEEPALIVE_DEFAULT  5
  66#define CEPH_OSD_IDLE_TTL_DEFAULT    60
  67
  68#define CEPH_MSG_MAX_FRONT_LEN  (16*1024*1024)
  69#define CEPH_MSG_MAX_DATA_LEN   (16*1024*1024)
  70
  71#define CEPH_AUTH_NAME_DEFAULT   "guest"
  72
  73/*
  74 * Delay telling the MDS we no longer want caps, in case we reopen
  75 * the file.  Delay a minimum amount of time, even if we send a cap
  76 * message for some other reason.  Otherwise, take the oppotunity to
  77 * update the mds to avoid sending another message later.
  78 */
  79#define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT      5  /* cap release delay */
  80#define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT     60  /* cap release delay */
  81
  82#define CEPH_CAP_RELEASE_SAFETY_DEFAULT        (CEPH_CAPS_PER_RELEASE * 4)
  83
  84/* mount state */
  85enum {
  86        CEPH_MOUNT_MOUNTING,
  87        CEPH_MOUNT_MOUNTED,
  88        CEPH_MOUNT_UNMOUNTING,
  89        CEPH_MOUNT_UNMOUNTED,
  90        CEPH_MOUNT_SHUTDOWN,
  91};
  92
  93/*
  94 * subtract jiffies
  95 */
  96static inline unsigned long time_sub(unsigned long a, unsigned long b)
  97{
  98        BUG_ON(time_after(b, a));
  99        return (long)a - (long)b;
 100}
 101
 102struct ceph_mds_client;
 103
 104/*
 105 * per client state
 106 *
 107 * possibly shared by multiple mount points, if they are
 108 * mounting the same ceph filesystem/cluster.
 109 */
 110struct ceph_client {
 111        struct ceph_fsid fsid;
 112        bool have_fsid;
 113
 114        void *private;
 115
 116        struct ceph_options *options;
 117
 118        struct mutex mount_mutex;      /* serialize mount attempts */
 119        wait_queue_head_t auth_wq;
 120        int auth_err;
 121
 122        int (*extra_mon_dispatch)(struct ceph_client *, struct ceph_msg *);
 123
 124        u32 supported_features;
 125        u32 required_features;
 126
 127        struct ceph_messenger msgr;   /* messenger instance */
 128        struct ceph_mon_client monc;
 129        struct ceph_osd_client osdc;
 130
 131#ifdef CONFIG_DEBUG_FS
 132        struct dentry *debugfs_dir;
 133        struct dentry *debugfs_monmap;
 134        struct dentry *debugfs_osdmap;
 135#endif
 136};
 137
 138
 139
 140/*
 141 * snapshots
 142 */
 143
 144/*
 145 * A "snap context" is the set of existing snapshots when we
 146 * write data.  It is used by the OSD to guide its COW behavior.
 147 *
 148 * The ceph_snap_context is refcounted, and attached to each dirty
 149 * page, indicating which context the dirty data belonged when it was
 150 * dirtied.
 151 */
 152struct ceph_snap_context {
 153        atomic_t nref;
 154        u64 seq;
 155        u32 num_snaps;
 156        u64 snaps[];
 157};
 158
 159static inline struct ceph_snap_context *
 160ceph_get_snap_context(struct ceph_snap_context *sc)
 161{
 162        /*
 163        printk("get_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
 164               atomic_read(&sc->nref)+1);
 165        */
 166        if (sc)
 167                atomic_inc(&sc->nref);
 168        return sc;
 169}
 170
 171static inline void ceph_put_snap_context(struct ceph_snap_context *sc)
 172{
 173        if (!sc)
 174                return;
 175        /*
 176        printk("put_snap_context %p %d -> %d\n", sc, atomic_read(&sc->nref),
 177               atomic_read(&sc->nref)-1);
 178        */
 179        if (atomic_dec_and_test(&sc->nref)) {
 180                /*printk(" deleting snap_context %p\n", sc);*/
 181                kfree(sc);
 182        }
 183}
 184
 185/*
 186 * calculate the number of pages a given length and offset map onto,
 187 * if we align the data.
 188 */
 189static inline int calc_pages_for(u64 off, u64 len)
 190{
 191        return ((off+len+PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT) -
 192                (off >> PAGE_CACHE_SHIFT);
 193}
 194
 195/* ceph_common.c */
 196extern const char *ceph_msg_type_name(int type);
 197extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
 198extern struct kmem_cache *ceph_inode_cachep;
 199extern struct kmem_cache *ceph_cap_cachep;
 200extern struct kmem_cache *ceph_dentry_cachep;
 201extern struct kmem_cache *ceph_file_cachep;
 202
 203extern struct ceph_options *ceph_parse_options(char *options,
 204                              const char *dev_name, const char *dev_name_end,
 205                              int (*parse_extra_token)(char *c, void *private),
 206                              void *private);
 207extern void ceph_destroy_options(struct ceph_options *opt);
 208extern int ceph_compare_options(struct ceph_options *new_opt,
 209                                struct ceph_client *client);
 210extern struct ceph_client *ceph_create_client(struct ceph_options *opt,
 211                                              void *private,
 212                                              unsigned supported_features,
 213                                              unsigned required_features);
 214extern u64 ceph_client_id(struct ceph_client *client);
 215extern void ceph_destroy_client(struct ceph_client *client);
 216extern int __ceph_open_session(struct ceph_client *client,
 217                               unsigned long started);
 218extern int ceph_open_session(struct ceph_client *client);
 219
 220/* pagevec.c */
 221extern void ceph_release_page_vector(struct page **pages, int num_pages);
 222
 223extern struct page **ceph_get_direct_page_vector(const char __user *data,
 224                                                 int num_pages,
 225                                                 bool write_page);
 226extern void ceph_put_page_vector(struct page **pages, int num_pages,
 227                                 bool dirty);
 228extern void ceph_release_page_vector(struct page **pages, int num_pages);
 229extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
 230extern int ceph_copy_user_to_page_vector(struct page **pages,
 231                                         const char __user *data,
 232                                         loff_t off, size_t len);
 233extern int ceph_copy_to_page_vector(struct page **pages,
 234                                    const char *data,
 235                                    loff_t off, size_t len);
 236extern int ceph_copy_from_page_vector(struct page **pages,
 237                                    char *data,
 238                                    loff_t off, size_t len);
 239extern int ceph_copy_page_vector_to_user(struct page **pages, char __user *data,
 240                                    loff_t off, size_t len);
 241extern void ceph_zero_page_vector_range(int off, int len, struct page **pages);
 242
 243
 244#endif /* _FS_CEPH_SUPER_H */
 245