1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
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.
11 * This file is part of InterMezzo, http://www.inter-mezzo.org.
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.
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.
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.
27 #ifndef __INTERMEZZO_FS_H_
28 #define __INTERMEZZO_FS_H_ 1
30 #include <linux/intermezzo_lib.h>
31 #include <linux/intermezzo_idl.h>
35 typedef __u8 uuid_t[16];
37 # include <uuid/uuid.h>
40 struct lento_vfs_context {
44 __u64 remote_generation;
49 struct presto_version remote_version;
52 static inline int izo_ioctl_is_invalid(struct izo_ioctl_data *data);
55 # include <linux/smp.h>
56 # include <linux/fsfilter.h>
57 # include <linux/slab.h>
58 # include <linux/vmalloc.h>
59 # include <linux/smp_lock.h>
63 # define fs_down(sem) down(sem)
67 # define fs_up(sem) up(sem)
72 # define KML_OPTIMIZE 2
75 # define KML_OPEN_REINT 0x0100
76 # define KML_REINT_BEGIN 0x0200
77 # define KML_BACKFETCH 0x0400
78 # define KML_REINT_END 0x0800
79 # define KML_CLOSE_REINT 0x1000
80 # define KML_REINT_MAXBUF (64 * 1024)
82 # define CACHE_CLIENT_RO 0x4
83 # define CACHE_LENTO_RO 0x8
85 /* global variables */
86 extern int presto_debug;
87 extern int presto_print_entry;
88 extern long presto_kmemory;
89 extern long presto_vmemory;
97 # define D_CACHE 8 /* cache debugging */
98 # define D_MALLOC 16 /* print malloc, de-alloc information */
100 # define D_UPCALL 64 /* up and downcall debugging */
102 # define D_PIOCTL 256
103 # define D_SPECIAL 512
104 # define D_TIMING 1024
105 # define D_DOWNCALL 2048
107 # define D_FSDATA 8192
109 # define CDEBUG(mask, format, a...) \
111 if (presto_debug & mask) { \
112 printk("(%s:%s,l. %d %d): " format, __FILE__, \
113 __FUNCTION__, __LINE__, current->pid \
118 #define CERROR(format, a...) \
120 printk("(%s:%s,l. %d %d): " format, __FILE__, __FUNCTION__, \
121 __LINE__, current->pid , ## a); \
125 if (presto_print_entry) \
126 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
129 if (presto_print_entry) \
130 printk("Process %d leaving %s at %d\n", current->pid, \
131 __FUNCTION__, __LINE__)
133 # define presto_kmem_inc(ptr, size) presto_kmemory += (size)
134 # define presto_kmem_dec(ptr, size) presto_kmemory -= (size)
135 # define presto_vmem_inc(ptr, size) presto_vmemory += (size)
136 # define presto_vmem_dec(ptr, size) presto_vmemory -= (size)
137 # else /* !PRESTO_DEBUG */
138 # define CDEBUG(mask, format, a...) do {} while (0)
139 # define ENTRY do {} while (0)
140 # define EXIT do {} while (0)
141 # define presto_kmem_inc(ptr, size) do {} while (0)
142 # define presto_kmem_dec(ptr, size) do {} while (0)
143 # define presto_vmem_inc(ptr, size) do {} while (0)
144 # define presto_vmem_dec(ptr, size) do {} while (0)
145 # endif /* PRESTO_DEBUG */
149 struct vfsmount *pwdmnt;
151 struct vfsmount *rootmnt;
157 gid_t groups[NGROUPS];
161 static inline void push_ctxt(struct run_ctxt *save, struct run_ctxt *new)
165 save->pwd = dget(current->fs->pwd);
166 save->pwdmnt = mntget(current->fs->pwdmnt);
167 save->fsgid = current->fsgid;
168 save->fsuid = current->fsuid;
169 save->root = current->fs->root;
170 save->rootmnt = current->fs->rootmnt;
171 save->ngroups = current->ngroups;
172 for (i = 0; i< current->ngroups; i++)
173 save->groups[i] = current->groups[i];
177 set_fs_pwd(current->fs, new->pwdmnt, new->pwd);
179 set_fs_root(current->fs, new->rootmnt, new->root);
181 current->fsuid = new->fsuid;
182 current->fsgid = new->fsgid;
183 if (new->ngroups > 0) {
184 current->ngroups = new->ngroups;
185 for (i = 0; i< new->ngroups; i++)
186 current->groups[i] = new->groups[i];
191 static inline void pop_ctxt(struct run_ctxt *saved)
197 set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
199 set_fs_root(current->fs, saved->rootmnt, saved->root);
201 current->fsuid = saved->fsuid;
202 current->fsgid = saved->fsgid;
203 current->ngroups = saved->ngroups;
204 for (i = 0; i< saved->ngroups; i++)
205 current->groups[i] = saved->groups[i];
207 mntput(saved->pwdmnt);
211 static inline struct presto_dentry_data *presto_d2d(struct dentry *dentry)
213 return (struct presto_dentry_data *)(dentry->d_fsdata);
216 struct presto_cache {
217 spinlock_t cache_lock;
218 loff_t cache_reserved;
219 struct vfsmount *cache_vfsmount;
220 struct super_block *cache_sb;
221 struct dentry *cache_root;
222 struct list_head cache_chain; /* for the dev/cache hash */
226 kdev_t cache_dev; /* underlying block device */
228 char *cache_type; /* filesystem type of cache */
229 struct filter_fs *cache_filter;
231 struct upc_channel *cache_psdev; /* points to channel used */
232 struct list_head cache_channel_list;
233 struct list_head cache_fset_list; /* filesets mounted in cache */
236 struct presto_log_fd {
238 loff_t fd_offset; /* offset where next record should go */
239 struct file *fd_file;
241 unsigned int fd_recno; /* last recno written */
242 struct list_head fd_reservations;
246 # define CHUNK_BITS 16
248 struct presto_file_set {
249 struct list_head fset_list;
250 struct presto_log_fd fset_kml;
251 struct presto_log_fd fset_lml;
252 struct presto_log_fd fset_rcvd;
253 struct list_head *fset_clients; /* cache of clients */
254 struct dentry *fset_dentry;
255 struct vfsmount *fset_mnt;
256 struct presto_cache *fset_cache;
258 unsigned int fset_lento_recno; /* last recno mentioned to lento */
259 loff_t fset_lento_off; /* last offset mentioned to lento */
260 loff_t fset_kml_logical_off; /* logical offset of kml file byte 0 */
265 char *fset_reint_buf; /* temporary buffer holds kml during reint */
267 spinlock_t fset_permit_lock;
268 int fset_permit_count;
269 int fset_permit_upcall_count;
270 /* This queue is used both for processes waiting for the kernel to give
271 * up the permit as well as processes waiting for the kernel to be given
272 * the permit, depending on the state of FSET_HASPERMIT. */
273 wait_queue_head_t fset_permit_queue;
275 loff_t fset_file_maxio; /* writing more than this causes a close */
276 unsigned long int kml_truncate_size;
279 /* This is the default number of bytes written before a close is recorded*/
280 #define FSET_DEFAULT_MAX_FILEIO (1024<<10)
282 struct dentry *presto_tmpfs_ilookup(struct inode *dir, struct dentry *dentry,
283 ino_t ino, unsigned int generation);
284 struct dentry *presto_iget_ilookup(struct inode *dir, struct dentry *dentry,
285 ino_t ino, unsigned int generation);
286 struct dentry *presto_add_ilookup_dentry(struct dentry *parent,
287 struct dentry *real);
290 int (*tr_all_data)(struct inode *);
291 loff_t (*tr_avail)(struct presto_cache *fset, struct super_block *);
292 void *(*tr_start)(struct presto_file_set *, struct inode *, int op);
293 void (*tr_commit)(struct presto_file_set *, void *handle);
294 void (*tr_journal_data)(struct inode *);
295 struct dentry *(*tr_ilookup)(struct inode *dir, struct dentry *dentry, ino_t ino, unsigned int generation);
296 struct dentry *(*tr_add_ilookup)(struct dentry *parent, struct dentry *real);
299 extern struct journal_ops presto_ext2_journal_ops;
300 extern struct journal_ops presto_ext3_journal_ops;
301 extern struct journal_ops presto_tmpfs_journal_ops;
302 extern struct journal_ops presto_xfs_journal_ops;
303 extern struct journal_ops presto_reiserfs_journal_ops;
304 extern struct journal_ops presto_obdfs_journal_ops;
306 # define LENTO_FL_KML 0x0001
307 # define LENTO_FL_EXPECT 0x0002
308 # define LENTO_FL_VFSCHECK 0x0004
309 # define LENTO_FL_JUSTLOG 0x0008
310 # define LENTO_FL_WRITE_KML 0x0010
311 # define LENTO_FL_CANCEL_LML 0x0020
312 # define LENTO_FL_WRITE_EXPECT 0x0040
313 # define LENTO_FL_IGNORE_TIME 0x0080
314 # define LENTO_FL_TOUCH_PARENT 0x0100
315 # define LENTO_FL_TOUCH_NEWOBJ 0x0200
316 # define LENTO_FL_SET_DDFILEID 0x0400
318 struct presto_cache *presto_get_cache(struct inode *inode);
319 int presto_sprint_mounts(char *buf, int buflen, int minor);
320 struct presto_file_set *presto_fset(struct dentry *de);
321 int presto_journal(struct dentry *dentry, char *buf, size_t size);
322 int presto_fwrite(struct file *file, const char *str, int len, loff_t *off);
323 int presto_ispresto(struct inode *);
326 extern struct file_system_type presto_fs_type;
327 extern int init_intermezzo_fs(void);
330 extern int izo_prepare_fileset(struct dentry *root, char *fsetname);
331 char * izo_make_path(struct presto_file_set *fset, char *name);
332 struct file *izo_fset_open(struct presto_file_set *fset, char *name, int flags, int mode);
335 int izo_psdev_get_free_channel(void);
336 int presto_psdev_init(void);
337 int izo_psdev_setpid(int minor);
338 extern void presto_psdev_cleanup(void);
339 inline int presto_lento_up(int minor);
340 int izo_psdev_setchannel(struct file *file, int fd);
343 extern struct super_operations presto_super_ops;
344 void presto_set_ops(struct inode *inode, struct filter_fs *filter);
347 void presto_frob_dop(struct dentry *de);
348 char *presto_path(struct dentry *dentry, struct dentry *root,
349 char *buffer, int buflen);
350 inline struct presto_dentry_data *izo_alloc_ddata(void);
351 int presto_set_dd(struct dentry *);
352 int presto_init_ddata_cache(void);
353 void presto_cleanup_ddata_cache(void);
354 extern struct dentry_operations presto_dentry_ops;
357 extern struct inode_operations presto_dir_iops;
358 extern struct inode_operations presto_file_iops;
359 extern struct inode_operations presto_sym_iops;
360 extern struct file_operations presto_dir_fops;
361 extern struct file_operations presto_file_fops;
362 extern struct file_operations presto_sym_fops;
363 int presto_setattr(struct dentry *de, struct iattr *iattr);
364 int presto_settime(struct presto_file_set *fset, struct dentry *newobj,
365 struct dentry *parent, struct dentry *target,
366 struct lento_vfs_context *ctx, int valid);
367 int presto_ioctl(struct inode *inode, struct file *file,
368 unsigned int cmd, unsigned long arg);
370 extern int presto_ilookup_uid;
371 # define PRESTO_ILOOKUP_MAGIC "...ino:"
372 # define PRESTO_ILOOKUP_SEP ':'
373 int izo_dentry_is_ilookup(struct dentry *, ino_t *id, unsigned int *generation);
374 struct dentry *presto_lookup(struct inode * dir, struct dentry *dentry);
376 struct presto_dentry_data {
377 int dd_count; /* how mnay dentries are using this dentry */
378 struct presto_file_set *dd_fset;
379 struct dentry *dd_inodentry;
380 loff_t dd_kml_offset;
383 __u64 remote_generation;
386 struct presto_file_data {
388 loff_t fd_lml_offset;
389 size_t fd_bytes_written;
390 /* authorization related data of file at open time */
394 /* identification data of calling process */
398 gid_t fd_groups[NGROUPS_MAX];
399 /* information how to complete the close operation */
400 struct lento_vfs_context fd_info;
401 struct presto_version fd_version;
404 /* presto.c and Lento::Downcall */
406 int presto_walk(const char *name, struct nameidata *nd);
407 int izo_clear_fsetroot(struct dentry *dentry);
408 int izo_clear_all_fsetroots(struct presto_cache *cache);
409 int presto_get_kmlsize(char *path, __u64 *size);
410 int presto_get_lastrecno(char *path, off_t *size);
411 int presto_set_fsetroot(struct dentry *dentry, char *fsetname,
413 int presto_set_fsetroot_from_ioc(struct dentry *dentry, char *fsetname,
415 inline int presto_is_read_only(struct presto_file_set *);
416 int presto_truncate_lml(struct presto_file_set *fset);
417 int lento_write_lml(char *path,
419 __u32 remote_generation,
420 __u32 remote_version,
421 struct presto_version *remote_file_version);
422 int lento_complete_closes(char *path);
423 inline int presto_f2m(struct presto_file_set *fset);
424 int presto_prep(struct dentry *, struct presto_cache **,
425 struct presto_file_set **);
427 extern struct presto_cache *presto_cache_init(void);
428 extern inline void presto_cache_add(struct presto_cache *cache, kdev_t dev);
429 extern inline void presto_cache_init_hash(void);
431 struct presto_cache *presto_cache_find(kdev_t dev);
433 #define PRESTO_REQLOW (3 * 4096)
434 #define PRESTO_REQHIGH (6 * 4096)
435 void presto_release_space(struct presto_cache *cache, loff_t req);
436 int presto_reserve_space(struct presto_cache *cache, loff_t req);
438 #define PRESTO_DATA 0x00000002 /* cached data is valid */
439 #define PRESTO_ATTR 0x00000004 /* attributes cached */
440 #define PRESTO_DONT_JOURNAL 0x00000008 /* things like .intermezzo/ */
442 struct presto_file_set *presto_path2fileset(const char *name);
443 int izo_revoke_permit(struct dentry *, uuid_t uuid);
444 int presto_chk(struct dentry *dentry, int flag);
445 void presto_set(struct dentry *dentry, int flag);
446 int presto_get_permit(struct inode *inode);
447 int presto_put_permit(struct inode *inode);
448 int presto_set_max_kml_size(const char *path, unsigned long max_size);
449 int izo_mark_dentry(struct dentry *dentry, int and, int or, int *res);
450 int izo_mark_cache(struct dentry *dentry, int and_bits, int or_bits, int *);
451 int izo_mark_fset(struct dentry *dentry, int and_bits, int or_bits, int *);
452 void presto_getversion(struct presto_version *pv, struct inode *inode);
453 int presto_i2m(struct inode *inode);
454 int presto_c2m(struct presto_cache *cache);
458 int izo_purge_file(struct presto_file_set *fset, char *file);
459 int presto_adjust_lml(struct file *file, struct lento_vfs_context *info);
469 void presto_trans_commit(struct presto_file_set *fset, void *handle);
470 void *presto_trans_start(struct presto_file_set *fset, struct inode *inode,
472 int presto_fread(struct file *file, char *str, int len, loff_t *off);
473 int presto_clear_lml_close(struct presto_file_set *fset,
475 int presto_complete_lml(struct presto_file_set *fset);
476 int presto_read_kml_logical_offset(struct rec_info *recinfo,
477 struct presto_file_set *fset);
478 int presto_write_kml_logical_offset(struct presto_file_set *fset);
479 struct file *presto_copy_kml_tail(struct presto_file_set *fset,
480 unsigned long int start);
481 int presto_finish_kml_truncate(struct presto_file_set *fset,
482 unsigned long int offset);
483 int izo_lookup_file(struct presto_file_set *fset, char *path,
484 struct nameidata *nd);
485 int izo_do_truncate(struct presto_file_set *fset, struct dentry *dentry,
486 loff_t length, loff_t size_check);
487 int izo_log_close(struct presto_log_fd *logfd);
488 struct file *izo_log_open(struct presto_file_set *fset, char *name, int flags);
489 int izo_init_kml_file(struct presto_file_set *, struct presto_log_fd *);
490 int izo_init_lml_file(struct presto_file_set *, struct presto_log_fd *);
491 int izo_init_last_rcvd_file(struct presto_file_set *, struct presto_log_fd *);
495 /* Extra data needed in the KML for rollback operations; this structure is
496 * passed around during the KML-writing process. */
497 struct izo_rollback_data {
504 int presto_write_last_rcvd(struct rec_info *recinfo,
505 struct presto_file_set *fset,
506 struct lento_vfs_context *info);
507 void izo_get_rollback_data(struct inode *inode, struct izo_rollback_data *rb);
508 int presto_do_close(struct presto_file_set *fset, struct file *file);
509 int presto_do_setattr(struct presto_file_set *fset, struct dentry *dentry,
510 struct iattr *iattr, struct lento_vfs_context *info);
511 int presto_do_create(struct presto_file_set *fset, struct dentry *dir,
512 struct dentry *dentry, int mode,
513 struct lento_vfs_context *info);
514 int presto_do_link(struct presto_file_set *fset, struct dentry *dir,
515 struct dentry *old_dentry, struct dentry *new_dentry,
516 struct lento_vfs_context *info);
517 int presto_do_unlink(struct presto_file_set *fset, struct dentry *dir,
518 struct dentry *dentry, struct lento_vfs_context *info);
519 int presto_do_symlink(struct presto_file_set *fset, struct dentry *dir,
520 struct dentry *dentry, const char *name,
521 struct lento_vfs_context *info);
522 int presto_do_mkdir(struct presto_file_set *fset, struct dentry *dir,
523 struct dentry *dentry, int mode,
524 struct lento_vfs_context *info);
525 int presto_do_rmdir(struct presto_file_set *fset, struct dentry *dir,
526 struct dentry *dentry, struct lento_vfs_context *info);
527 int presto_do_mknod(struct presto_file_set *fset, struct dentry *dir,
528 struct dentry *dentry, int mode, dev_t dev,
529 struct lento_vfs_context *info);
530 int do_rename(struct presto_file_set *fset, struct dentry *old_dir,
531 struct dentry *old_dentry, struct dentry *new_dir,
532 struct dentry *new_dentry, struct lento_vfs_context *info);
533 int presto_do_statfs (struct presto_file_set *fset,
534 struct statfs * buf);
536 int lento_setattr(const char *name, struct iattr *iattr,
537 struct lento_vfs_context *info);
538 int lento_create(const char *name, int mode, struct lento_vfs_context *info);
539 int lento_link(const char *oldname, const char *newname,
540 struct lento_vfs_context *info);
541 int lento_unlink(const char *name, struct lento_vfs_context *info);
542 int lento_symlink(const char *oldname,const char *newname,
543 struct lento_vfs_context *info);
544 int lento_mkdir(const char *name, int mode, struct lento_vfs_context *info);
545 int lento_rmdir(const char *name, struct lento_vfs_context *info);
546 int lento_mknod(const char *name, int mode, dev_t dev,
547 struct lento_vfs_context *info);
548 int lento_rename(const char *oldname, const char *newname,
549 struct lento_vfs_context *info);
550 int lento_iopen(const char *name, ino_t ino, unsigned int generation,int flags);
554 #define JOURNAL_PAGE_SZ PAGE_SIZE
556 __inline__ int presto_no_journal(struct presto_file_set *fset);
557 int journal_fetch(int minor);
558 int presto_log(struct presto_file_set *fset, struct rec_info *rec,
559 const char *buf, size_t size,
560 const char *string1, int len1,
561 const char *string2, int len2,
562 const char *string3, int len3);
563 int presto_get_fileid(int minor, struct presto_file_set *fset,
564 struct dentry *dentry);
565 int presto_journal_setattr(struct rec_info *rec, struct presto_file_set *fset,
566 struct dentry *dentry, struct presto_version *old_ver,
567 struct izo_rollback_data *, struct iattr *iattr);
568 int presto_journal_create(struct rec_info *rec, struct presto_file_set *fset,
569 struct dentry *dentry,
570 struct presto_version *tgt_dir_ver,
571 struct presto_version *new_file_ver, int mode);
572 int presto_journal_link(struct rec_info *rec, struct presto_file_set *fset,
573 struct dentry *src, struct dentry *tgt,
574 struct presto_version *tgt_dir_ver,
575 struct presto_version *new_link_ver);
576 int presto_journal_unlink(struct rec_info *rec, struct presto_file_set *fset,
578 struct presto_version *tgt_dir_ver,
579 struct presto_version *old_file_ver,
580 struct izo_rollback_data *, struct dentry *dentry,
581 char *old_target, int old_targetlen);
582 int presto_journal_symlink(struct rec_info *rec, struct presto_file_set *fset,
583 struct dentry *dentry, const char *target,
584 struct presto_version *tgt_dir_ver,
585 struct presto_version *new_link_ver);
586 int presto_journal_mkdir(struct rec_info *rec, struct presto_file_set *fset,
587 struct dentry *dentry,
588 struct presto_version *tgt_dir_ver,
589 struct presto_version *new_dir_ver, int mode);
590 int presto_journal_rmdir(struct rec_info *rec, struct presto_file_set *fset,
591 struct dentry *dentry,
592 struct presto_version *tgt_dir_ver,
593 struct presto_version *old_dir_ver,
594 struct izo_rollback_data *, int len, const char *name);
595 int presto_journal_mknod(struct rec_info *rec, struct presto_file_set *fset,
596 struct dentry *dentry,
597 struct presto_version *tgt_dir_ver,
598 struct presto_version *new_node_ver, int mode,
599 int dmajor, int dminor);
600 int presto_journal_rename(struct rec_info *rec, struct presto_file_set *fset,
601 struct dentry *src, struct dentry *tgt,
602 struct presto_version *src_dir_ver,
603 struct presto_version *tgt_dir_ver);
604 int presto_journal_open(struct rec_info *, struct presto_file_set *,
605 struct dentry *, struct presto_version *old_ver);
606 int presto_journal_close(struct rec_info *rec, struct presto_file_set *,
607 struct file *, struct dentry *,
608 struct presto_version *old_file_ver,
609 struct presto_version *new_file_ver);
610 int presto_write_lml_close(struct rec_info *rec,
611 struct presto_file_set *fset,
614 __u64 remote_generation,
615 struct presto_version *remote_version,
616 struct presto_version *new_file_ver);
617 void presto_log_op(void *data, int len);
618 loff_t presto_kml_offset(struct presto_file_set *fset);
621 #define SYNCHRONOUS 0
622 #define ASYNCHRONOUS 1
623 /* asynchronous calls */
624 int izo_upc_kml(int minor, __u64 offset, __u32 first_recno, __u64 length,
625 __u32 last_recno, char *fsetname);
626 int izo_upc_kml_truncate(int minor, __u64 length, __u32 last_recno,
628 int izo_upc_go_fetch_kml(int minor, char *fsetname, uuid_t uuid, __u64 kmlsize);
629 int izo_upc_backfetch(int minor, char *path, char *fileset,
630 struct lento_vfs_context *);
632 /* synchronous calls */
633 int izo_upc_get_fileid(int minor, __u32 reclen, char *rec,
634 __u32 pathlen, char *path, char *fsetname);
635 int izo_upc_permit(int minor, struct dentry *, __u32 pathlen, char *path,
637 int izo_upc_open(int minor, __u32 pathlen, char *path, char *fsetname,
638 struct lento_vfs_context *info);
639 int izo_upc_connect(int minor, __u64 ip_address, __u64 port, __u8 uuid[16],
641 int izo_upc_revoke_permit(int minor, char *fsetname, uuid_t uuid);
642 int izo_upc_set_kmlsize(int minor, char *fsetname, uuid_t uuid, __u64 kmlsize);
643 int izo_upc_client_make_branch(int minor, char *fsetname);
644 int izo_upc_server_make_branch(int minor, char *fsetname);
645 int izo_upc_branch_undo(int minor, char *fsetname, char *branchname);
646 int izo_upc_branch_redo(int minor, char *fsetname, char *branchname);
647 int izo_upc_repstatus(int minor, char * fsetname, struct izo_rcvd_rec *lr_server);
649 /* general mechanism */
650 int izo_upc_upcall(int minor, int *size, struct izo_upcall_hdr *, int async);
653 int izo_repstatus(struct presto_file_set *fset, __u64 client_kmlsize,
654 struct izo_rcvd_rec *lr_client, struct izo_rcvd_rec *lr_server);
655 int izo_rep_cache_init(struct presto_file_set *);
656 loff_t izo_rcvd_get(struct izo_rcvd_rec *, struct presto_file_set *, char *uuid);
657 loff_t izo_rcvd_write(struct presto_file_set *, struct izo_rcvd_rec *);
658 loff_t izo_rcvd_upd_remote(struct presto_file_set *fset, char * uuid, __u64 remote_recno,
659 __u64 remote_offset);
662 int init_intermezzo_sysctl(void);
663 void cleanup_intermezzo_sysctl(void);
666 /* We will be more tolerant than the default ea patch with attr name sizes and
667 * the size of value. If these come via VFS from the default ea patches, the
668 * corresponding character strings will be truncated anyway. During journalling- * we journal length for both name and value. See journal_set_ext_attr.
670 #define PRESTO_EXT_ATTR_NAME_MAX 128
671 #define PRESTO_EXT_ATTR_VALUE_MAX 8192
673 #define PRESTO_ALLOC(ptr, size) \
676 (ptr) = kmalloc(s, GFP_KERNEL); \
678 CERROR("IZO: out of memory at %s:%d (trying to " \
679 "allocate %ld)\n", __FILE__, __LINE__, s); \
681 presto_kmem_inc((ptr), s); \
682 memset((ptr), 0, s); \
684 CDEBUG(D_MALLOC, "kmalloced: %ld at %p (tot %ld).\n", \
685 s, (ptr), presto_kmemory); \
688 #define PRESTO_FREE(ptr, size) \
691 if ((ptr) == NULL) { \
692 CERROR("IZO: free NULL pointer (%ld bytes) at " \
693 "%s:%d\n", s, __FILE__, __LINE__); \
697 CDEBUG(D_MALLOC, "kfreed: %ld at %p (tot %ld).\n", \
698 s, (ptr), presto_kmemory); \
699 presto_kmem_dec((ptr), s); \
702 static inline int dentry_name_cmp(struct dentry *dentry, char *name)
704 return (strlen(name) == dentry->d_name.len &&
705 memcmp(name, dentry->d_name.name, dentry->d_name.len) == 0);
708 static inline char *strdup(char *str)
711 tmp = kmalloc(strlen(str) + 1, GFP_KERNEL);
713 memcpy(tmp, str, strlen(str) + 1);
718 /* buffer MUST be at least the size of izo_ioctl_hdr */
719 static inline int izo_ioctl_getdata(char *buf, char *end, void *arg)
721 struct izo_ioctl_hdr *hdr;
722 struct izo_ioctl_data *data;
726 hdr = (struct izo_ioctl_hdr *)buf;
727 data = (struct izo_ioctl_data *)buf;
729 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
735 if (hdr->ioc_version != IZO_IOCTL_VERSION) {
736 CERROR("IZO: version mismatch kernel vs application\n");
740 if (hdr->ioc_len + buf >= end) {
741 CERROR("IZO: user buffer exceeds kernel buffer\n");
745 if (hdr->ioc_len < sizeof(struct izo_ioctl_data)) {
746 CERROR("IZO: user buffer too small for ioctl\n");
750 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
756 if (izo_ioctl_is_invalid(data)) {
757 CERROR("IZO: ioctl not correctly formatted\n");
761 if (data->ioc_inllen1) {
762 data->ioc_inlbuf1 = &data->ioc_bulk[0];
765 if (data->ioc_inllen2) {
766 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
767 size_round(data->ioc_inllen1);
774 # define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
777 # define malloc(a) kmalloc(a, GFP_KERNEL)
778 # define printf printk
779 int kml_reint_rec(struct file *dir, struct izo_ioctl_data *data);
780 int izo_get_fileid(struct file *dir, struct izo_ioctl_data *data);
781 int izo_set_fileid(struct file *dir, struct izo_ioctl_data *data);
783 #else /* __KERNEL__ */
786 # include <sys/types.h>
787 # include <sys/ioctl.h>
790 # define printk printf
792 # define CERROR printf
794 # define kmalloc(a,b) malloc(a)
796 void init_fsreintdata (void);
797 int kml_fsreint(struct kml_rec *rec, char *basedir);
798 int kml_iocreint(__u32 size, char *ptr, __u32 offset, int dird,
799 uuid_t uuid, __u32 generate_kml);
801 static inline int izo_ioctl_packlen(struct izo_ioctl_data *data);
803 static inline void izo_ioctl_init(struct izo_ioctl_data *data)
805 memset(data, 0, sizeof(*data));
806 data->ioc_len = sizeof(*data);
807 data->ioc_version = IZO_IOCTL_VERSION;
811 izo_ioctl_pack(struct izo_ioctl_data *data, char **pbuf, int max)
814 struct izo_ioctl_data *overlay;
815 data->ioc_len = izo_ioctl_packlen(data);
816 data->ioc_version = IZO_IOCTL_VERSION;
818 if (*pbuf && izo_ioctl_packlen(data) > max)
821 *pbuf = malloc(data->ioc_len);
824 overlay = (struct izo_ioctl_data *)*pbuf;
825 memcpy(*pbuf, data, sizeof(*data));
827 ptr = overlay->ioc_bulk;
828 if (data->ioc_inlbuf1)
829 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
830 if (data->ioc_inlbuf2)
831 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
832 if (izo_ioctl_is_invalid(overlay))
838 #endif /* __KERNEL__*/
840 #define IZO_ERROR_NAME 1
841 #define IZO_ERROR_UPDATE 2
842 #define IZO_ERROR_DELETE 3
843 #define IZO_ERROR_RENAME 4
845 static inline char *izo_error(int err)
849 return strerror(-err);
853 return "InterMezzo name/name conflict";
854 case IZO_ERROR_UPDATE:
855 return "InterMezzo update/update conflict";
856 case IZO_ERROR_DELETE:
857 return "InterMezzo update/delete conflict";
858 case IZO_ERROR_RENAME:
859 return "InterMezzo rename/rename conflict";
861 return "Unknown InterMezzo error";
864 static inline int izo_ioctl_packlen(struct izo_ioctl_data *data)
866 int len = sizeof(struct izo_ioctl_data);
867 len += size_round(data->ioc_inllen1);
868 len += size_round(data->ioc_inllen2);
872 static inline int izo_ioctl_is_invalid(struct izo_ioctl_data *data)
874 if (data->ioc_len > (1<<30)) {
875 CERROR("IZO ioctl: ioc_len larger than 1<<30\n");
878 if (data->ioc_inllen1 > (1<<30)) {
879 CERROR("IZO ioctl: ioc_inllen1 larger than 1<<30\n");
882 if (data->ioc_inllen2 > (1<<30)) {
883 CERROR("IZO ioctl: ioc_inllen2 larger than 1<<30\n");
886 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
887 CERROR("IZO ioctl: inlbuf1 pointer but 0 length\n");
890 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
891 CERROR("IZO ioctl: inlbuf2 pointer but 0 length\n");
894 if (data->ioc_pbuf1 && !data->ioc_plen1) {
895 CERROR("IZO ioctl: pbuf1 pointer but 0 length\n");
898 if (data->ioc_pbuf2 && !data->ioc_plen2) {
899 CERROR("IZO ioctl: pbuf2 pointer but 0 length\n");
902 if (izo_ioctl_packlen(data) != data->ioc_len ) {
903 CERROR("IZO ioctl: packlen exceeds ioc_len\n");
906 if (data->ioc_inllen1 &&
907 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
908 CERROR("IZO ioctl: inlbuf1 not 0 terminated\n");
911 if (data->ioc_inllen2 &&
912 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2
914 CERROR("IZO ioctl: inlbuf2 not 0 terminated\n");
921 char *kml_print_rec(struct kml_rec *rec, int brief);
922 int kml_unpack(struct kml_rec *rec, char **buf, char *end);