intermezzo_fs.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:36k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  2.  * vim:expandtab:shiftwidth=8:tabstop=8:
  3.  *
  4.  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
  5.  *  Copyright (C) 2001 Tacitus Systems, Inc.
  6.  *  Copyright (C) 2000 Stelias Computing, Inc.
  7.  *  Copyright (C) 2000 Red Hat, Inc.
  8.  *  Copyright (C) 2000 TurboLinux, Inc.
  9.  *  Copyright (C) 2000 Los Alamos National Laboratory.
  10.  *
  11.  *   This file is part of InterMezzo, http://www.inter-mezzo.org.
  12.  *
  13.  *   InterMezzo is free software; you can redistribute it and/or
  14.  *   modify it under the terms of version 2 of the GNU General Public
  15.  *   License as published by the Free Software Foundation.
  16.  *
  17.  *   InterMezzo is distributed in the hope that it will be useful,
  18.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  *   GNU General Public License for more details.
  21.  *
  22.  *   You should have received a copy of the GNU General Public License
  23.  *   along with InterMezzo; if not, write to the Free Software
  24.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26. #ifndef __INTERMEZZO_FS_H_
  27. #define __INTERMEZZO_FS_H_ 1
  28. #include <linux/intermezzo_lib.h>
  29. #include <linux/intermezzo_idl.h>
  30. #ifdef __KERNEL__
  31. typedef __u8 uuid_t[16];
  32. #else
  33. # include <uuid/uuid.h>
  34. #endif
  35. struct lento_vfs_context {
  36.         __u64 kml_offset;
  37.         __u64 updated_time;
  38.         __u64 remote_ino;
  39.         __u64 remote_generation;
  40.         __u32 slot_offset;
  41.         __u32 recno;
  42.         __u32 flags;
  43.         uuid_t uuid;
  44.         struct presto_version remote_version;
  45. };
  46. static inline int izo_ioctl_is_invalid(struct izo_ioctl_data *data);
  47. #ifdef __KERNEL__
  48. # include <linux/smp.h>
  49. # include <linux/fsfilter.h>
  50. # include <linux/slab.h>
  51. # include <linux/vmalloc.h>
  52. # include <linux/smp_lock.h>
  53. /* fixups for fs.h */
  54. # ifndef fs_down
  55. #  define fs_down(sem) down(sem)
  56. # endif
  57. # ifndef fs_up
  58. #  define fs_up(sem) up(sem)
  59. # endif
  60. # define KML_IDLE                        0
  61. # define KML_DECODE                      1
  62. # define KML_OPTIMIZE                    2
  63. # define KML_REINT                       3
  64. # define KML_OPEN_REINT                  0x0100
  65. # define KML_REINT_BEGIN                 0x0200
  66. # define KML_BACKFETCH                   0x0400
  67. # define KML_REINT_END                   0x0800
  68. # define KML_CLOSE_REINT                 0x1000
  69. # define KML_REINT_MAXBUF                (64 * 1024)
  70. # define CACHE_CLIENT_RO       0x4
  71. # define CACHE_LENTO_RO        0x8
  72. /* global variables */
  73. extern int presto_debug;
  74. extern int presto_print_entry;
  75. extern long presto_kmemory;
  76. extern long presto_vmemory;
  77. # define PRESTO_DEBUG
  78. # ifdef PRESTO_DEBUG
  79. /* debugging masks */
  80. #  define D_SUPER       1
  81. #  define D_INODE       2
  82. #  define D_FILE        4
  83. #  define D_CACHE       8  /* cache debugging */
  84. #  define D_MALLOC     16  /* print malloc, de-alloc information */
  85. #  define D_JOURNAL    32
  86. #  define D_UPCALL     64  /* up and downcall debugging */
  87. #  define D_PSDEV     128
  88. #  define D_PIOCTL    256
  89. #  define D_SPECIAL   512
  90. #  define D_TIMING   1024
  91. #  define D_DOWNCALL 2048
  92. #  define D_KML      4096
  93. #  define D_FSDATA   8192
  94. #  define CDEBUG(mask, format, a...)                                    
  95.         do {                                                            
  96.                 if (presto_debug & mask) {                              
  97.                         printk("(%s:%s,l. %d %d): " format, __FILE__,   
  98.                                __FUNCTION__, __LINE__, current->pid     
  99.                                , ## a);                                 
  100.                 }                                                       
  101.         } while (0)
  102. #define CERROR(format, a...)                                            
  103. do {                                                                    
  104.         printk("(%s:%s,l. %d %d): " format, __FILE__, __FUNCTION__,     
  105.                __LINE__, current->pid , ## a);                          
  106. } while (0)
  107. #  define ENTRY                                                         
  108.         if (presto_print_entry)                                         
  109.                 printk("Process %d entered %sn", current->pid, __FUNCTION__)
  110. #  define EXIT                                                          
  111.         if (presto_print_entry)                                         
  112.                 printk("Process %d leaving %s at %dn", current->pid,   
  113.                        __FUNCTION__, __LINE__)
  114. #  define presto_kmem_inc(ptr, size) presto_kmemory += (size)
  115. #  define presto_kmem_dec(ptr, size) presto_kmemory -= (size)
  116. #  define presto_vmem_inc(ptr, size) presto_vmemory += (size)
  117. #  define presto_vmem_dec(ptr, size) presto_vmemory -= (size)
  118. # else /* !PRESTO_DEBUG */
  119. #  define CDEBUG(mask, format, a...) do {} while (0)
  120. #  define ENTRY do {} while (0)
  121. #  define EXIT do {} while (0)
  122. #  define presto_kmem_inc(ptr, size) do {} while (0)
  123. #  define presto_kmem_dec(ptr, size) do {} while (0)
  124. #  define presto_vmem_inc(ptr, size) do {} while (0)
  125. #  define presto_vmem_dec(ptr, size) do {} while (0)
  126. # endif /* PRESTO_DEBUG */
  127. struct run_ctxt {
  128.         struct vfsmount *pwdmnt;
  129.         struct dentry   *pwd;
  130.         struct vfsmount *rootmnt;
  131.         struct dentry   *root;
  132.         uid_t            fsuid;
  133.         gid_t            fsgid;
  134.         mm_segment_t     fs;
  135. int              ngroups;
  136. gid_t          groups[NGROUPS];
  137. };
  138. static inline void push_ctxt(struct run_ctxt *save, struct run_ctxt *new)
  139. {
  140.         int i;
  141.         save->fs = get_fs();
  142.         save->pwd = dget(current->fs->pwd);
  143.         save->pwdmnt = mntget(current->fs->pwdmnt);
  144.         save->fsgid = current->fsgid;
  145.         save->fsuid = current->fsuid;
  146.         save->root = current->fs->root;
  147.         save->rootmnt = current->fs->rootmnt;
  148.         save->ngroups = current->ngroups;
  149.         for (i = 0; i< current->ngroups; i++) 
  150.                 save->groups[i] = current->groups[i];
  151.         set_fs(new->fs);
  152.         lock_kernel();
  153.         set_fs_pwd(current->fs, new->pwdmnt, new->pwd);
  154.         if (new->root)
  155.                 set_fs_root(current->fs, new->rootmnt, new->root);
  156.         unlock_kernel();
  157.         current->fsuid = new->fsuid;
  158.         current->fsgid = new->fsgid;
  159.         if (new->ngroups > 0) {
  160.                 current->ngroups = new->ngroups;
  161.                 for (i = 0; i< new->ngroups; i++) 
  162.                         current->groups[i] = new->groups[i];
  163.         }
  164.         
  165. }
  166. static inline void pop_ctxt(struct run_ctxt *saved)
  167. {
  168.         int i;
  169.         set_fs(saved->fs);
  170.         lock_kernel();
  171.         set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
  172.         if (saved->root)
  173.                 set_fs_root(current->fs, saved->rootmnt, saved->root);
  174.         unlock_kernel();
  175.         current->fsuid = saved->fsuid;
  176.         current->fsgid = saved->fsgid;
  177.         current->ngroups = saved->ngroups;
  178.         for (i = 0; i< saved->ngroups; i++) 
  179.                 current->groups[i] = saved->groups[i];
  180.         mntput(saved->pwdmnt);
  181.         dput(saved->pwd);
  182. }
  183. static inline struct presto_dentry_data *presto_d2d(struct dentry *dentry)
  184. {
  185.         return (struct presto_dentry_data *)(dentry->d_fsdata);
  186. }
  187. struct presto_cache {
  188.         spinlock_t          cache_lock;
  189.         loff_t              cache_reserved;
  190.         struct  vfsmount   *cache_vfsmount;
  191.         struct super_block *cache_sb;
  192.         struct  dentry     *cache_root;
  193.         struct list_head    cache_chain; /* for the dev/cache hash */
  194.         int   cache_flags;
  195.         kdev_t cache_dev;            /* underlying block device */
  196.         char *cache_type;            /* filesystem type of cache */
  197.         struct filter_fs *cache_filter;
  198.         struct upc_channel *cache_psdev;  /* points to channel used */
  199.         struct list_head cache_channel_list; 
  200.         struct list_head cache_fset_list; /* filesets mounted in cache */
  201. };
  202. struct presto_log_fd {
  203.         rwlock_t         fd_lock;
  204.         loff_t           fd_offset;  /* offset where next record should go */
  205.         struct file    *fd_file;
  206.         int             fd_truncating;
  207.         unsigned int   fd_recno;   /* last recno written */
  208.         struct list_head  fd_reservations;
  209. };
  210. /* file sets */
  211. # define CHUNK_BITS  16
  212. struct presto_file_set {
  213.         struct list_head fset_list;
  214.         struct presto_log_fd fset_kml;
  215.         struct presto_log_fd fset_lml;
  216.         struct presto_log_fd fset_rcvd;
  217.         struct list_head *fset_clients;  /* cache of clients */
  218.         struct dentry *fset_dentry;
  219.         struct vfsmount *fset_mnt;
  220.         struct presto_cache *fset_cache;
  221.         unsigned int fset_lento_recno;  /* last recno mentioned to lento */
  222.         loff_t fset_lento_off;    /* last offset mentioned to lento */
  223.         loff_t fset_kml_logical_off; /* logical offset of kml file byte 0 */
  224.         char * fset_name;
  225.         int fset_flags;
  226.         int fset_chunkbits;
  227.         char *fset_reint_buf; /* temporary buffer holds kml during reint */
  228.         spinlock_t fset_permit_lock;
  229.         int fset_permit_count;
  230.         int fset_permit_upcall_count;
  231.         /* This queue is used both for processes waiting for the kernel to give
  232.          * up the permit as well as processes waiting for the kernel to be given
  233.          * the permit, depending on the state of FSET_HASPERMIT. */
  234.         wait_queue_head_t fset_permit_queue;
  235.         loff_t  fset_file_maxio;  /* writing more than this causes a close */
  236.         unsigned long int kml_truncate_size;
  237. };
  238. /* This is the default number of bytes written before a close is recorded*/
  239. #define FSET_DEFAULT_MAX_FILEIO (1024<<10)
  240. struct dentry *presto_tmpfs_ilookup(struct inode *dir, struct dentry *dentry, 
  241.                                     ino_t ino, unsigned int generation);
  242. struct dentry *presto_iget_ilookup(struct inode *dir, struct dentry *dentry, 
  243.                                     ino_t ino, unsigned int generation);
  244. struct dentry *presto_add_ilookup_dentry(struct dentry *parent,
  245.                                          struct dentry *real);
  246. struct journal_ops {
  247.         int (*tr_all_data)(struct inode *);
  248.         loff_t (*tr_avail)(struct presto_cache *fset, struct super_block *);
  249.         void *(*tr_start)(struct presto_file_set *, struct inode *, int op);
  250.         void (*tr_commit)(struct presto_file_set *, void *handle);
  251.         void (*tr_journal_data)(struct inode *);
  252.         struct dentry *(*tr_ilookup)(struct inode *dir, struct dentry *dentry, ino_t ino, unsigned int generation);
  253.         struct dentry *(*tr_add_ilookup)(struct dentry *parent, struct dentry *real);
  254. };
  255. extern struct journal_ops presto_ext2_journal_ops;
  256. extern struct journal_ops presto_ext3_journal_ops;
  257. extern struct journal_ops presto_tmpfs_journal_ops;
  258. extern struct journal_ops presto_xfs_journal_ops;
  259. extern struct journal_ops presto_reiserfs_journal_ops;
  260. extern struct journal_ops presto_obdfs_journal_ops;
  261. # define LENTO_FL_KML            0x0001
  262. # define LENTO_FL_EXPECT         0x0002
  263. # define LENTO_FL_VFSCHECK       0x0004
  264. # define LENTO_FL_JUSTLOG        0x0008
  265. # define LENTO_FL_WRITE_KML      0x0010
  266. # define LENTO_FL_CANCEL_LML     0x0020
  267. # define LENTO_FL_WRITE_EXPECT   0x0040
  268. # define LENTO_FL_IGNORE_TIME    0x0080
  269. # define LENTO_FL_TOUCH_PARENT   0x0100
  270. # define LENTO_FL_TOUCH_NEWOBJ   0x0200
  271. # define LENTO_FL_SET_DDFILEID   0x0400
  272. struct presto_cache *presto_get_cache(struct inode *inode);
  273. int presto_sprint_mounts(char *buf, int buflen, int minor);
  274. struct presto_file_set *presto_fset(struct dentry *de);
  275. int presto_journal(struct dentry *dentry, char *buf, size_t size);
  276. int presto_fwrite(struct file *file, const char *str, int len, loff_t *off);
  277. int presto_ispresto(struct inode *);
  278. /* super.c */
  279. extern struct file_system_type presto_fs_type;
  280. extern int init_intermezzo_fs(void);
  281. /* fileset.c */
  282. extern int izo_prepare_fileset(struct dentry *root, char *fsetname);
  283. char * izo_make_path(struct presto_file_set *fset, char *name);
  284. struct file *izo_fset_open(struct presto_file_set *fset, char *name, int flags, int mode);
  285. /* psdev.c */
  286. int izo_psdev_get_free_channel(void);
  287. int presto_psdev_init(void);
  288. int izo_psdev_setpid(int minor);
  289. extern void presto_psdev_cleanup(void);
  290. inline int presto_lento_up(int minor);
  291. int izo_psdev_setchannel(struct file *file, int fd);
  292. /* inode.c */
  293. extern struct super_operations presto_super_ops;
  294. void presto_set_ops(struct inode *inode, struct  filter_fs *filter);
  295. /* dcache.c */
  296. void presto_frob_dop(struct dentry *de);
  297. char *presto_path(struct dentry *dentry, struct dentry *root,
  298.                   char *buffer, int buflen);
  299. inline struct presto_dentry_data *izo_alloc_ddata(void);
  300. int presto_set_dd(struct dentry *);
  301. int presto_init_ddata_cache(void);
  302. void presto_cleanup_ddata_cache(void);
  303. extern struct dentry_operations presto_dentry_ops;
  304. /* dir.c */
  305. extern struct inode_operations presto_dir_iops;
  306. extern struct inode_operations presto_file_iops;
  307. extern struct inode_operations presto_sym_iops;
  308. extern struct file_operations presto_dir_fops;
  309. extern struct file_operations presto_file_fops;
  310. extern struct file_operations presto_sym_fops;
  311. int presto_setattr(struct dentry *de, struct iattr *iattr);
  312. int presto_settime(struct presto_file_set *fset, struct dentry *newobj,
  313.                    struct dentry *parent, struct dentry *target,
  314.                    struct lento_vfs_context *ctx, int valid);
  315. int presto_ioctl(struct inode *inode, struct file *file,
  316.                  unsigned int cmd, unsigned long arg);
  317. extern int presto_ilookup_uid;
  318. # define PRESTO_ILOOKUP_MAGIC "...ino:"
  319. # define PRESTO_ILOOKUP_SEP ':'
  320. int izo_dentry_is_ilookup(struct dentry *, ino_t *id, unsigned int *generation);
  321. struct dentry *presto_lookup(struct inode * dir, struct dentry *dentry);
  322. struct presto_dentry_data {
  323.         int dd_count; /* how mnay dentries are using this dentry */
  324.         struct presto_file_set *dd_fset;
  325.         struct dentry *dd_inodentry; 
  326.         loff_t dd_kml_offset;
  327.         int dd_flags;
  328.         __u64 remote_ino;
  329.         __u64 remote_generation;
  330. };
  331. struct presto_file_data {
  332.         int fd_do_lml;
  333.         loff_t fd_lml_offset;
  334.         size_t fd_bytes_written;
  335.         /* authorization related data of file at open time */
  336.         uid_t fd_uid;
  337.         gid_t fd_gid;
  338.         mode_t fd_mode;
  339.         /* identification data of calling process */
  340.         uid_t fd_fsuid;
  341.         gid_t fd_fsgid;
  342.         int fd_ngroups;
  343.         gid_t fd_groups[NGROUPS_MAX];
  344.         /* information how to complete the close operation */
  345.         struct lento_vfs_context fd_info;
  346.         struct presto_version fd_version;
  347. };
  348. /* presto.c and Lento::Downcall */
  349. int presto_walk(const char *name, struct nameidata *nd);
  350. int izo_clear_fsetroot(struct dentry *dentry);
  351. int izo_clear_all_fsetroots(struct presto_cache *cache);
  352. int presto_get_kmlsize(char *path, __u64 *size);
  353. int presto_get_lastrecno(char *path, off_t *size);
  354. int presto_set_fsetroot(struct dentry *dentry, char *fsetname,
  355.                        unsigned int flags);
  356. int presto_set_fsetroot_from_ioc(struct dentry *dentry, char *fsetname,
  357.                                  unsigned int flags);
  358. inline int presto_is_read_only(struct presto_file_set *);
  359. int presto_truncate_lml(struct presto_file_set *fset);
  360. int lento_write_lml(char *path,
  361.                      __u64 remote_ino,
  362.                      __u32 remote_generation,
  363.                      __u32 remote_version,
  364.                     struct presto_version *remote_file_version);
  365. int lento_complete_closes(char *path);
  366. inline int presto_f2m(struct presto_file_set *fset);
  367. int presto_prep(struct dentry *, struct presto_cache **,
  368.                        struct presto_file_set **);
  369. /* cache.c */
  370. extern struct presto_cache *presto_cache_init(void);
  371. extern inline void presto_cache_add(struct presto_cache *cache, kdev_t dev);
  372. extern inline void presto_cache_init_hash(void);
  373. struct presto_cache *presto_cache_find(kdev_t dev);
  374. #define PRESTO_REQLOW  (3 * 4096)
  375. #define PRESTO_REQHIGH (6 * 4096)
  376. void presto_release_space(struct presto_cache *cache, loff_t req);
  377. int presto_reserve_space(struct presto_cache *cache, loff_t req);
  378. #define PRESTO_DATA             0x00000002 /* cached data is valid */
  379. #define PRESTO_ATTR             0x00000004 /* attributes cached */
  380. #define PRESTO_DONT_JOURNAL     0x00000008 /* things like .intermezzo/ */
  381. struct presto_file_set *presto_path2fileset(const char *name);
  382. int izo_revoke_permit(struct dentry *, uuid_t uuid);
  383. int presto_chk(struct dentry *dentry, int flag);
  384. void presto_set(struct dentry *dentry, int flag);
  385. int presto_get_permit(struct inode *inode);
  386. int presto_put_permit(struct inode *inode);
  387. int presto_set_max_kml_size(const char *path, unsigned long max_size);
  388. int izo_mark_dentry(struct dentry *dentry, int and, int or, int *res);
  389. int izo_mark_cache(struct dentry *dentry, int and_bits, int or_bits, int *);
  390. int izo_mark_fset(struct dentry *dentry, int and_bits, int or_bits, int *);
  391. void presto_getversion(struct presto_version *pv, struct inode *inode);
  392. int presto_i2m(struct inode *inode);
  393. int presto_c2m(struct presto_cache *cache);
  394. /* file.c */
  395. int izo_purge_file(struct presto_file_set *fset, char *file);
  396. int presto_adjust_lml(struct file *file, struct lento_vfs_context *info);
  397. /* journal.c */
  398. struct rec_info {
  399.         loff_t offset;
  400.         int size;
  401.         int recno;
  402.         int is_kml;
  403. };
  404. void presto_trans_commit(struct presto_file_set *fset, void *handle);
  405. void *presto_trans_start(struct presto_file_set *fset, struct inode *inode,
  406.                          int op);
  407. int presto_fread(struct file *file, char *str, int len, loff_t *off);
  408. int presto_clear_lml_close(struct presto_file_set *fset,
  409.                            loff_t  lml_offset);
  410. int presto_complete_lml(struct presto_file_set *fset);
  411. int presto_read_kml_logical_offset(struct rec_info *recinfo,
  412.                                    struct presto_file_set *fset);
  413. int presto_write_kml_logical_offset(struct presto_file_set *fset);
  414. struct file *presto_copy_kml_tail(struct presto_file_set *fset,
  415.                                   unsigned long int start);
  416. int presto_finish_kml_truncate(struct presto_file_set *fset,
  417.                                unsigned long int offset);
  418. int izo_lookup_file(struct presto_file_set *fset, char *path,
  419.                     struct nameidata *nd);
  420. int izo_do_truncate(struct presto_file_set *fset, struct dentry *dentry,
  421.                     loff_t length,  loff_t size_check);
  422. int izo_log_close(struct presto_log_fd *logfd);
  423. struct file *izo_log_open(struct presto_file_set *fset, char *name, int flags);
  424. int izo_init_kml_file(struct presto_file_set *, struct presto_log_fd *);
  425. int izo_init_lml_file(struct presto_file_set *, struct presto_log_fd *);
  426. int izo_init_last_rcvd_file(struct presto_file_set *, struct presto_log_fd *);
  427. /* vfs.c */
  428. /* Extra data needed in the KML for rollback operations; this structure is
  429.  * passed around during the KML-writing process. */
  430. struct izo_rollback_data {
  431.         __u32 rb_mode;
  432.         __u32 rb_rdev;
  433.         __u64 rb_uid;
  434.         __u64 rb_gid;
  435. };
  436. int presto_write_last_rcvd(struct rec_info *recinfo,
  437.                            struct presto_file_set *fset,
  438.                            struct lento_vfs_context *info);
  439. void izo_get_rollback_data(struct inode *inode, struct izo_rollback_data *rb);
  440. int presto_do_close(struct presto_file_set *fset, struct file *file);
  441. int presto_do_setattr(struct presto_file_set *fset, struct dentry *dentry,
  442.                       struct iattr *iattr, struct lento_vfs_context *info);
  443. int presto_do_create(struct presto_file_set *fset, struct dentry *dir,
  444.                      struct dentry *dentry, int mode,
  445.                      struct lento_vfs_context *info);
  446. int presto_do_link(struct presto_file_set *fset, struct dentry *dir,
  447.                    struct dentry *old_dentry, struct dentry *new_dentry,
  448.                    struct lento_vfs_context *info);
  449. int presto_do_unlink(struct presto_file_set *fset, struct dentry *dir,
  450.                      struct dentry *dentry, struct lento_vfs_context *info);
  451. int presto_do_symlink(struct presto_file_set *fset, struct dentry *dir,
  452.                       struct dentry *dentry, const char *name,
  453.                       struct lento_vfs_context *info);
  454. int presto_do_mkdir(struct presto_file_set *fset, struct dentry *dir,
  455.                     struct dentry *dentry, int mode,
  456.                     struct lento_vfs_context *info);
  457. int presto_do_rmdir(struct presto_file_set *fset, struct dentry *dir,
  458.                     struct dentry *dentry, struct lento_vfs_context *info);
  459. int presto_do_mknod(struct presto_file_set *fset, struct dentry *dir,
  460.                     struct dentry *dentry, int mode, dev_t dev,
  461.                     struct lento_vfs_context *info);
  462. int do_rename(struct presto_file_set *fset, struct dentry *old_dir,
  463.               struct dentry *old_dentry, struct dentry *new_dir,
  464.               struct dentry *new_dentry, struct lento_vfs_context *info);
  465. int presto_do_statfs (struct presto_file_set *fset,
  466.                       struct statfs * buf);
  467. int lento_setattr(const char *name, struct iattr *iattr,
  468.                   struct lento_vfs_context *info);
  469. int lento_create(const char *name, int mode, struct lento_vfs_context *info);
  470. int lento_link(const char *oldname, const char *newname,
  471.                struct lento_vfs_context *info);
  472. int lento_unlink(const char *name, struct lento_vfs_context *info);
  473. int lento_symlink(const char *oldname,const char *newname,
  474.                   struct lento_vfs_context *info);
  475. int lento_mkdir(const char *name, int mode, struct lento_vfs_context *info);
  476. int lento_rmdir(const char *name, struct lento_vfs_context *info);
  477. int lento_mknod(const char *name, int mode, dev_t dev,
  478.                 struct lento_vfs_context *info);
  479. int lento_rename(const char *oldname, const char *newname,
  480.                  struct lento_vfs_context *info);
  481. int lento_iopen(const char *name, ino_t ino, unsigned int generation,int flags);
  482. /* journal.c */
  483. #define JOURNAL_PAGE_SZ  PAGE_SIZE
  484. __inline__ int presto_no_journal(struct presto_file_set *fset);
  485. int journal_fetch(int minor);
  486. int presto_log(struct presto_file_set *fset, struct rec_info *rec,
  487.                const char *buf, size_t size,
  488.                const char *string1, int len1, 
  489.                const char *string2, int len2,
  490.                const char *string3, int len3);
  491. int presto_get_fileid(int minor, struct presto_file_set *fset,
  492.                       struct dentry *dentry);
  493. int presto_journal_setattr(struct rec_info *rec, struct presto_file_set *fset,
  494.                            struct dentry *dentry, struct presto_version *old_ver,
  495.                            struct izo_rollback_data *, struct iattr *iattr);
  496. int presto_journal_create(struct rec_info *rec, struct presto_file_set *fset,
  497.                           struct dentry *dentry,
  498.                           struct presto_version *tgt_dir_ver,
  499.                           struct presto_version *new_file_ver, int mode);
  500. int presto_journal_link(struct rec_info *rec, struct presto_file_set *fset,
  501.                         struct dentry *src, struct dentry *tgt,
  502.                         struct presto_version *tgt_dir_ver,
  503.                         struct presto_version *new_link_ver);
  504. int presto_journal_unlink(struct rec_info *rec, struct presto_file_set *fset,
  505.                           struct dentry *dir,
  506.                           struct presto_version *tgt_dir_ver,
  507.                           struct presto_version *old_file_ver,
  508.                           struct izo_rollback_data *, struct dentry *dentry,
  509.                           char *old_target, int old_targetlen);
  510. int presto_journal_symlink(struct rec_info *rec, struct presto_file_set *fset,
  511.                            struct dentry *dentry, const char *target,
  512.                            struct presto_version *tgt_dir_ver,
  513.                            struct presto_version *new_link_ver);
  514. int presto_journal_mkdir(struct rec_info *rec, struct presto_file_set *fset,
  515.                          struct dentry *dentry,
  516.                          struct presto_version *tgt_dir_ver,
  517.                          struct presto_version *new_dir_ver, int mode);
  518. int presto_journal_rmdir(struct rec_info *rec, struct presto_file_set *fset,
  519.                          struct dentry *dentry,
  520.                          struct presto_version *tgt_dir_ver,
  521.                          struct presto_version *old_dir_ver,
  522.                          struct izo_rollback_data *, int len, const char *name);
  523. int presto_journal_mknod(struct rec_info *rec, struct presto_file_set *fset,
  524.                          struct dentry *dentry,
  525.                          struct presto_version *tgt_dir_ver,
  526.                          struct presto_version *new_node_ver, int mode,
  527.                          int dmajor, int dminor);
  528. int presto_journal_rename(struct rec_info *rec, struct presto_file_set *fset,
  529.                           struct dentry *src, struct dentry *tgt,
  530.                           struct presto_version *src_dir_ver,
  531.                           struct presto_version *tgt_dir_ver);
  532. int presto_journal_open(struct rec_info *, struct presto_file_set *,
  533.                         struct dentry *, struct presto_version *old_ver);
  534. int presto_journal_close(struct rec_info *rec, struct presto_file_set *,
  535.                          struct file *, struct dentry *,
  536.                          struct presto_version *old_file_ver,
  537.                          struct presto_version *new_file_ver);
  538. int presto_write_lml_close(struct rec_info *rec,
  539.                            struct presto_file_set *fset, 
  540.                            struct file *file,
  541.                            __u64 remote_ino,
  542.                            __u64 remote_generation,
  543.                            struct presto_version *remote_version,
  544.                            struct presto_version *new_file_ver);
  545. void presto_log_op(void *data, int len);
  546. loff_t presto_kml_offset(struct presto_file_set *fset);
  547. /* upcall.c */
  548. #define SYNCHRONOUS 0
  549. #define ASYNCHRONOUS 1
  550. /* asynchronous calls */
  551. int izo_upc_kml(int minor, __u64 offset, __u32 first_recno, __u64 length,
  552.                 __u32 last_recno, char *fsetname);
  553. int izo_upc_kml_truncate(int minor, __u64 length, __u32 last_recno,
  554.                          char *fsetname);
  555. int izo_upc_go_fetch_kml(int minor, char *fsetname, uuid_t uuid, __u64 kmlsize);
  556. int izo_upc_backfetch(int minor, char *path, char *fileset, 
  557.                       struct lento_vfs_context *);
  558. /* synchronous calls */
  559. int izo_upc_get_fileid(int minor, __u32 reclen, char *rec, 
  560.                        __u32 pathlen, char *path, char *fsetname);
  561. int izo_upc_permit(int minor, struct dentry *, __u32 pathlen, char *path,
  562.                    char *fset);
  563. int izo_upc_open(int minor, __u32 pathlen, char *path, char *fsetname, 
  564.                  struct lento_vfs_context *info);
  565. int izo_upc_connect(int minor, __u64 ip_address, __u64 port, __u8 uuid[16],
  566.                     int client_flag);
  567. int izo_upc_revoke_permit(int minor, char *fsetname, uuid_t uuid);
  568. int izo_upc_set_kmlsize(int minor, char *fsetname, uuid_t uuid, __u64 kmlsize);
  569. int izo_upc_client_make_branch(int minor, char *fsetname);
  570. int izo_upc_server_make_branch(int minor, char *fsetname);
  571. int izo_upc_branch_undo(int minor, char *fsetname, char *branchname);
  572. int izo_upc_branch_redo(int minor, char *fsetname, char *branchname);
  573. int izo_upc_repstatus(int minor,  char * fsetname, struct izo_rcvd_rec *lr_server);
  574. /* general mechanism */
  575. int izo_upc_upcall(int minor, int *size, struct izo_upcall_hdr *, int async);
  576. /* replicator.c */
  577. int izo_repstatus(struct presto_file_set *fset, __u64 client_kmlsize, 
  578.                   struct izo_rcvd_rec *lr_client, struct izo_rcvd_rec *lr_server);
  579. int izo_rep_cache_init(struct presto_file_set *);
  580. loff_t izo_rcvd_get(struct izo_rcvd_rec *, struct presto_file_set *, char *uuid);
  581. loff_t izo_rcvd_write(struct presto_file_set *, struct izo_rcvd_rec *);
  582. loff_t izo_rcvd_upd_remote(struct presto_file_set *fset, char * uuid,  __u64 remote_recno,
  583.                            __u64 remote_offset);
  584. /* sysctl.c */
  585. int init_intermezzo_sysctl(void);
  586. void cleanup_intermezzo_sysctl(void);
  587. /* ext_attr.c */
  588. /* We will be more tolerant than the default ea patch with attr name sizes and
  589.  * the size of value. If these come via VFS from the default ea patches, the
  590.  * corresponding character strings will be truncated anyway. During journalling- * we journal length for both name and value. See journal_set_ext_attr.
  591.  */
  592. #define PRESTO_EXT_ATTR_NAME_MAX 128
  593. #define PRESTO_EXT_ATTR_VALUE_MAX 8192
  594. #define PRESTO_ALLOC(ptr, size)                                         
  595. do {                                                                    
  596.         long s = (size);                                                
  597.         (ptr) = kmalloc(s, GFP_KERNEL);                                 
  598.         if ((ptr) == NULL)                                              
  599.                 CERROR("IZO: out of memory at %s:%d (trying to "        
  600.                        "allocate %ld)n", __FILE__, __LINE__, s);       
  601.         else {                                                          
  602.                 presto_kmem_inc((ptr), s);                              
  603.                 memset((ptr), 0, s);                                    
  604.         }                                                               
  605.         CDEBUG(D_MALLOC, "kmalloced: %ld at %p (tot %ld).n",           
  606.                s, (ptr), presto_kmemory);                               
  607. } while (0)
  608. #define PRESTO_FREE(ptr, size)                                          
  609. do {                                                                    
  610.         long s = (size);                                                
  611.         if ((ptr) == NULL) {                                            
  612.                 CERROR("IZO: free NULL pointer (%ld bytes) at "         
  613.                        "%s:%dn", s, __FILE__, __LINE__);               
  614.                 break;                                                  
  615.         }                                                               
  616.         kfree(ptr);                                                     
  617.         CDEBUG(D_MALLOC, "kfreed: %ld at %p (tot %ld).n",              
  618.                s, (ptr), presto_kmemory);                               
  619.         presto_kmem_dec((ptr), s);                                      
  620. } while (0)
  621. static inline int dentry_name_cmp(struct dentry *dentry, char *name)
  622. {
  623.         return (strlen(name) == dentry->d_name.len &&
  624.                 memcmp(name, dentry->d_name.name, dentry->d_name.len) == 0);
  625. }
  626. static inline char *strdup(char *str)
  627. {
  628.         char *tmp;
  629.         tmp = kmalloc(strlen(str) + 1, GFP_KERNEL);
  630.         if (tmp)
  631.                 memcpy(tmp, str, strlen(str) + 1);
  632.                
  633.         return tmp;
  634. }
  635. /* buffer MUST be at least the size of izo_ioctl_hdr */
  636. static inline int izo_ioctl_getdata(char *buf, char *end, void *arg)
  637. {
  638.         struct izo_ioctl_hdr *hdr;
  639.         struct izo_ioctl_data *data;
  640.         int err;
  641.         ENTRY;
  642.         hdr = (struct izo_ioctl_hdr *)buf;
  643.         data = (struct izo_ioctl_data *)buf;
  644.         err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
  645.         if ( err ) {
  646.                 EXIT;
  647.                 return err;
  648.         }
  649.         if (hdr->ioc_version != IZO_IOCTL_VERSION) {
  650.                 CERROR("IZO: version mismatch kernel vs applicationn");
  651.                 return -EINVAL;
  652.         }
  653.         if (hdr->ioc_len + buf >= end) {
  654.                 CERROR("IZO: user buffer exceeds kernel buffern");
  655.                 return -EINVAL;
  656.         }
  657.         if (hdr->ioc_len < sizeof(struct izo_ioctl_data)) {
  658.                 CERROR("IZO: user buffer too small for ioctln");
  659.                 return -EINVAL;
  660.         }
  661.         err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
  662.         if ( err ) {
  663.                 EXIT;
  664.                 return err;
  665.         }
  666.         if (izo_ioctl_is_invalid(data)) {
  667.                 CERROR("IZO: ioctl not correctly formattedn");
  668.                 return -EINVAL;
  669.         }
  670.         if (data->ioc_inllen1) {
  671.                 data->ioc_inlbuf1 = &data->ioc_bulk[0];
  672.         }
  673.         if (data->ioc_inllen2) {
  674.                 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
  675.                         size_round(data->ioc_inllen1);
  676.         }
  677.         EXIT;
  678.         return 0;
  679. }
  680. # define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
  681. # define free kfree
  682. # define malloc(a) kmalloc(a, GFP_KERNEL)
  683. # define printf printk
  684. int kml_reint_rec(struct file *dir, struct izo_ioctl_data *data);
  685. int izo_get_fileid(struct file *dir, struct izo_ioctl_data *data);
  686. int izo_set_fileid(struct file *dir, struct izo_ioctl_data *data);
  687. #else /* __KERNEL__ */
  688. # include <stdlib.h>
  689. # include <stdio.h>
  690. # include <sys/types.h>
  691. # include <sys/ioctl.h>
  692. # include <string.h>
  693. # define printk printf
  694. # ifndef CERROR
  695. #   define CERROR printf
  696. # endif
  697. # define kmalloc(a,b) malloc(a)
  698. void init_fsreintdata (void);
  699. int kml_fsreint(struct kml_rec *rec, char *basedir);
  700. int kml_iocreint(__u32 size, char *ptr, __u32 offset, int dird,
  701.                  uuid_t uuid, __u32 generate_kml);
  702. static inline int izo_ioctl_packlen(struct izo_ioctl_data *data);
  703. static inline void izo_ioctl_init(struct izo_ioctl_data *data)
  704. {
  705.         memset(data, 0, sizeof(*data));
  706.         data->ioc_len = sizeof(*data);
  707.         data->ioc_version = IZO_IOCTL_VERSION;
  708. }
  709. static inline int
  710. izo_ioctl_pack(struct izo_ioctl_data *data, char **pbuf, int max)
  711. {
  712.         char *ptr;
  713.         struct izo_ioctl_data *overlay;
  714.         data->ioc_len = izo_ioctl_packlen(data);
  715.         data->ioc_version = IZO_IOCTL_VERSION;
  716.         if (*pbuf && izo_ioctl_packlen(data) > max)
  717.                 return 1;
  718.         if (*pbuf == NULL)
  719.                 *pbuf = malloc(data->ioc_len);
  720.         if (*pbuf == NULL)
  721.                 return 1;
  722.         overlay = (struct izo_ioctl_data *)*pbuf;
  723.         memcpy(*pbuf, data, sizeof(*data));
  724.         ptr = overlay->ioc_bulk;
  725.         if (data->ioc_inlbuf1)
  726.                 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
  727.         if (data->ioc_inlbuf2)
  728.                 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
  729.         if (izo_ioctl_is_invalid(overlay))
  730.                 return 1;
  731.         return 0;
  732. }
  733. #endif /* __KERNEL__*/
  734. #define IZO_ERROR_NAME 1
  735. #define IZO_ERROR_UPDATE 2
  736. #define IZO_ERROR_DELETE 3
  737. #define IZO_ERROR_RENAME 4
  738. static inline char *izo_error(int err)
  739. {
  740. #ifndef __KERNEL__
  741.         if (err <= 0)
  742.                 return strerror(-err);
  743. #endif
  744.         switch (err) {
  745.         case IZO_ERROR_NAME:
  746.                 return "InterMezzo name/name conflict";
  747.         case IZO_ERROR_UPDATE:
  748.                 return "InterMezzo update/update conflict";
  749.         case IZO_ERROR_DELETE:
  750.                 return "InterMezzo update/delete conflict";
  751.         case IZO_ERROR_RENAME:
  752.                 return "InterMezzo rename/rename conflict";
  753.         }
  754.         return "Unknown InterMezzo error";
  755. }
  756. static inline int izo_ioctl_packlen(struct izo_ioctl_data *data)
  757. {
  758.         int len = sizeof(struct izo_ioctl_data);
  759.         len += size_round(data->ioc_inllen1);
  760.         len += size_round(data->ioc_inllen2);
  761.         return len;
  762. }
  763. static inline int izo_ioctl_is_invalid(struct izo_ioctl_data *data)
  764. {
  765.         if (data->ioc_len > (1<<30)) {
  766.                 CERROR("IZO ioctl: ioc_len larger than 1<<30n");
  767.                 return 1;
  768.         }
  769.         if (data->ioc_inllen1 > (1<<30)) {
  770.                 CERROR("IZO ioctl: ioc_inllen1 larger than 1<<30n");
  771.                 return 1;
  772.         }
  773.         if (data->ioc_inllen2 > (1<<30)) {
  774.                 CERROR("IZO ioctl: ioc_inllen2 larger than 1<<30n");
  775.                 return 1;
  776.         }
  777.         if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
  778.                 CERROR("IZO ioctl: inlbuf1 pointer but 0 lengthn");
  779.                 return 1;
  780.         }
  781.         if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
  782.                 CERROR("IZO ioctl: inlbuf2 pointer but 0 lengthn");
  783.                 return 1;
  784.         }
  785.         if (data->ioc_pbuf1 && !data->ioc_plen1) {
  786.                 CERROR("IZO ioctl: pbuf1 pointer but 0 lengthn");
  787.                 return 1;
  788.         }
  789.         if (data->ioc_pbuf2 && !data->ioc_plen2) {
  790.                 CERROR("IZO ioctl: pbuf2 pointer but 0 lengthn");
  791.                 return 1;
  792.         }
  793.         if (izo_ioctl_packlen(data) != data->ioc_len ) {
  794.                 CERROR("IZO ioctl: packlen exceeds ioc_lenn");
  795.                 return 1;
  796.         }
  797.         if (data->ioc_inllen1 &&
  798.             data->ioc_bulk[data->ioc_inllen1 - 1] != '') {
  799.                 CERROR("IZO ioctl: inlbuf1 not 0 terminatedn");
  800.                 return 1;
  801.         }
  802.         if (data->ioc_inllen2 &&
  803.             data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2
  804.                            - 1] != '') {
  805.                 CERROR("IZO ioctl: inlbuf2 not 0 terminatedn");
  806.                 return 1;
  807.         }
  808.         return 0;
  809. }
  810. /* kml_unpack.c */
  811. char *kml_print_rec(struct kml_rec *rec, int brief);
  812. int kml_unpack(struct kml_rec *rec, char **buf, char *end);
  813. #endif