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 "intermezzo_lib.h"
31 #include "intermezzo_idl.h"
35 typedef __u8 uuid_t[16];
37 # include <uuid/uuid.h>
40 struct lento_vfs_context {
42 struct timespec updated_time;
44 __u64 remote_generation;
49 struct presto_version remote_version;
53 # include <linux/smp.h>
54 # include <linux/fsfilter.h>
55 # include <linux/mount.h>
56 # include <linux/slab.h>
57 # include <linux/vmalloc.h>
58 # include <linux/smp_lock.h>
62 # define fs_down(sem) down(sem)
66 # define fs_up(sem) up(sem)
71 # define KML_OPTIMIZE 2
74 # define KML_OPEN_REINT 0x0100
75 # define KML_REINT_BEGIN 0x0200
76 # define KML_BACKFETCH 0x0400
77 # define KML_REINT_END 0x0800
78 # define KML_CLOSE_REINT 0x1000
79 # define KML_REINT_MAXBUF (64 * 1024)
81 # define CACHE_CLIENT_RO 0x4
82 # define CACHE_LENTO_RO 0x8
84 /* global variables */
85 extern int presto_debug;
86 extern int presto_print_entry;
87 extern long presto_kmemory;
88 extern long presto_vmemory;
96 # define D_CACHE 8 /* cache debugging */
97 # define D_MALLOC 16 /* print malloc, de-alloc information */
99 # define D_UPCALL 64 /* up and downcall debugging */
101 # define D_PIOCTL 256
102 # define D_SPECIAL 512
103 # define D_TIMING 1024
104 # define D_DOWNCALL 2048
106 # define D_FSDATA 8192
108 # define CDEBUG(mask, format, a...) \
110 if (presto_debug & mask) { \
111 printk("(%s:%s,l. %d %d): " format, __FILE__, \
112 __FUNCTION__, __LINE__, current->pid \
117 #define CERROR(format, a...) \
119 printk("(%s:%s,l. %d %d): " format, __FILE__, __FUNCTION__, \
120 __LINE__, current->pid , ## a); \
124 if (presto_print_entry) \
125 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
128 if (presto_print_entry) \
129 printk("Process %d leaving %s at %d\n", current->pid, \
130 __FUNCTION__, __LINE__)
132 # define presto_kmem_inc(ptr, size) presto_kmemory += (size)
133 # define presto_kmem_dec(ptr, size) presto_kmemory -= (size)
134 # define presto_vmem_inc(ptr, size) presto_vmemory += (size)
135 # define presto_vmem_dec(ptr, size) presto_vmemory -= (size)
136 # else /* !PRESTO_DEBUG */
137 # define CDEBUG(mask, format, a...) do {} while (0)
138 # define ENTRY do {} while (0)
139 # define EXIT do {} while (0)
140 # define presto_kmem_inc(ptr, size) do {} while (0)
141 # define presto_kmem_dec(ptr, size) do {} while (0)
142 # define presto_vmem_inc(ptr, size) do {} while (0)
143 # define presto_vmem_dec(ptr, size) do {} while (0)
144 # endif /* PRESTO_DEBUG */
148 struct vfsmount *pwdmnt;
150 struct vfsmount *rootmnt;
155 struct group_info * group_info;
157 gid_t groups[NGROUPS];*/
161 static inline void push_ctxt(struct run_ctxt *save, struct run_ctxt *new)
164 save->pwd = dget(current->fs->pwd);
165 save->pwdmnt = mntget(current->fs->pwdmnt);
166 save->fsgid = current->fsgid;
167 save->fsuid = current->fsuid;
168 save->root = current->fs->root;
169 save->rootmnt = current->fs->rootmnt;
170 save->group_info = current->group_info;
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];
188 current->group_info = new->group_info;
192 static inline void pop_ctxt(struct run_ctxt *saved)
196 set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
198 set_fs_root(current->fs, saved->rootmnt, saved->root);
200 current->fsuid = saved->fsuid;
201 current->fsgid = saved->fsgid;
202 current->group_info = saved->group_info;
204 current->ngroups = saved->ngroups;
205 for (i = 0; i< saved->ngroups; i++)
206 current->groups[i] = saved->groups[i];
208 mntput(saved->pwdmnt);
212 static inline struct presto_dentry_data *presto_d2d(struct dentry *dentry)
214 return (struct presto_dentry_data *)(dentry->d_fsdata);
217 struct presto_cache {
218 spinlock_t cache_lock;
219 loff_t cache_reserved;
220 struct vfsmount *cache_vfsmount;
221 struct super_block *cache_sb;
222 struct dentry *cache_root;
223 struct list_head cache_chain; /* for the dev/cache hash */
227 char *cache_type; /* filesystem type of cache */
228 struct filter_fs *cache_filter;
230 struct upc_channel *cache_psdev; /* points to channel used */
231 struct list_head cache_channel_list;
232 struct list_head cache_fset_list; /* filesets mounted in cache */
235 struct presto_log_fd {
237 loff_t fd_offset; /* offset where next record should go */
238 struct file *fd_file;
240 unsigned int fd_recno; /* last recno written */
241 struct list_head fd_reservations;
245 # define CHUNK_BITS 16
247 struct presto_file_set {
248 struct list_head fset_list;
249 struct presto_log_fd fset_kml;
250 struct presto_log_fd fset_lml;
251 struct presto_log_fd fset_rcvd;
252 struct list_head *fset_clients; /* cache of clients */
253 struct dentry *fset_dentry;
254 struct vfsmount *fset_mnt;
255 struct presto_cache *fset_cache;
257 unsigned int fset_lento_recno; /* last recno mentioned to lento */
258 loff_t fset_lento_off; /* last offset mentioned to lento */
259 loff_t fset_kml_logical_off; /* logical offset of kml file byte 0 */
264 char *fset_reint_buf; /* temporary buffer holds kml during reint */
266 spinlock_t fset_permit_lock;
267 int fset_permit_count;
268 int fset_permit_upcall_count;
269 /* This queue is used both for processes waiting for the kernel to give
270 * up the permit as well as processes waiting for the kernel to be given
271 * the permit, depending on the state of FSET_HASPERMIT. */
272 wait_queue_head_t fset_permit_queue;
274 loff_t fset_file_maxio; /* writing more than this causes a close */
275 unsigned long int kml_truncate_size;
278 /* This is the default number of bytes written before a close is recorded*/
279 #define FSET_DEFAULT_MAX_FILEIO (1024<<10)
281 struct dentry *presto_tmpfs_ilookup(struct inode *dir, struct dentry *dentry,
282 ino_t ino, unsigned int generation);
283 struct dentry *presto_iget_ilookup(struct inode *dir, struct dentry *dentry,
284 ino_t ino, unsigned int generation);
285 struct dentry *presto_add_ilookup_dentry(struct dentry *parent,
286 struct dentry *real);
289 int (*tr_all_data)(struct inode *);
290 loff_t (*tr_avail)(struct presto_cache *fset, struct super_block *);
291 void *(*tr_start)(struct presto_file_set *, struct inode *, int op);
292 void (*tr_commit)(struct presto_file_set *, void *handle);
293 void (*tr_journal_data)(struct inode *);
294 struct dentry *(*tr_ilookup)(struct inode *dir, struct dentry *dentry, ino_t ino, unsigned int generation);
295 struct dentry *(*tr_add_ilookup)(struct dentry *parent, struct dentry *real);
298 extern struct journal_ops presto_ext2_journal_ops;
299 extern struct journal_ops presto_ext3_journal_ops;
300 extern struct journal_ops presto_tmpfs_journal_ops;
301 extern struct journal_ops presto_xfs_journal_ops;
302 extern struct journal_ops presto_reiserfs_journal_ops;
303 extern struct journal_ops presto_obdfs_journal_ops;
305 # define LENTO_FL_KML 0x0001
306 # define LENTO_FL_EXPECT 0x0002
307 # define LENTO_FL_VFSCHECK 0x0004
308 # define LENTO_FL_JUSTLOG 0x0008
309 # define LENTO_FL_WRITE_KML 0x0010
310 # define LENTO_FL_CANCEL_LML 0x0020
311 # define LENTO_FL_WRITE_EXPECT 0x0040
312 # define LENTO_FL_IGNORE_TIME 0x0080
313 # define LENTO_FL_TOUCH_PARENT 0x0100
314 # define LENTO_FL_TOUCH_NEWOBJ 0x0200
315 # define LENTO_FL_SET_DDFILEID 0x0400
317 struct presto_cache *presto_get_cache(struct inode *inode);
318 int presto_sprint_mounts(char *buf, int buflen, int minor);
319 struct presto_file_set *presto_fset(struct dentry *de);
320 int presto_journal(struct dentry *dentry, char *buf, size_t size);
321 int presto_fwrite(struct file *file, const char *str, int len, loff_t *off);
322 int presto_ispresto(struct inode *);
325 extern struct file_system_type presto_fs_type;
326 extern int init_intermezzo_fs(void);
329 extern int izo_prepare_fileset(struct dentry *root, char *fsetname);
330 char * izo_make_path(struct presto_file_set *fset, char *name);
331 struct file *izo_fset_open(struct presto_file_set *fset, char *name, int flags, int mode);
334 int izo_psdev_get_free_channel(void);
335 int presto_psdev_init(void);
336 int izo_psdev_setpid(int minor);
337 extern void presto_psdev_cleanup(void);
338 int presto_lento_up(int minor);
339 int izo_psdev_setchannel(struct file *file, int fd);
342 extern struct super_operations presto_super_ops;
343 void presto_set_ops(struct inode *inode, struct filter_fs *filter);
346 void presto_frob_dop(struct dentry *de);
347 char *presto_path(struct dentry *dentry, struct dentry *root,
348 char *buffer, int buflen);
349 struct presto_dentry_data *izo_alloc_ddata(void);
350 int presto_set_dd(struct dentry *);
351 int presto_init_ddata_cache(void);
352 void presto_cleanup_ddata_cache(void);
353 extern struct dentry_operations presto_dentry_ops;
356 extern struct inode_operations presto_dir_iops;
357 extern struct inode_operations presto_file_iops;
358 extern struct inode_operations presto_sym_iops;
359 extern struct file_operations presto_dir_fops;
360 extern struct file_operations presto_file_fops;
361 extern struct file_operations presto_sym_fops;
362 int presto_setattr(struct dentry *de, struct iattr *iattr);
363 int presto_settime(struct presto_file_set *fset, struct dentry *newobj,
364 struct dentry *parent, struct dentry *target,
365 struct lento_vfs_context *ctx, int valid);
366 int presto_ioctl(struct inode *inode, struct file *file,
367 unsigned int cmd, unsigned long arg);
369 extern int presto_ilookup_uid;
370 # define PRESTO_ILOOKUP_MAGIC "...ino:"
371 # define PRESTO_ILOOKUP_SEP ':'
372 int izo_dentry_is_ilookup(struct dentry *, ino_t *id, unsigned int *generation);
373 struct dentry *presto_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd);
375 struct presto_dentry_data {
376 int dd_count; /* how mnay dentries are using this dentry */
377 struct presto_file_set *dd_fset;
378 struct dentry *dd_inodentry;
379 loff_t dd_kml_offset;
382 __u64 remote_generation;
385 struct presto_file_data {
387 loff_t fd_lml_offset;
388 size_t fd_bytes_written;
389 /* authorization related data of file at open time */
393 /* identification data of calling process */
397 gid_t fd_groups[NGROUPS_SMALL];
398 /* information how to complete the close operation */
399 struct lento_vfs_context fd_info;
400 struct presto_version fd_version;
403 /* presto.c and Lento::Downcall */
405 int presto_walk(const char *name, struct nameidata *nd);
406 int izo_clear_fsetroot(struct dentry *dentry);
407 int izo_clear_all_fsetroots(struct presto_cache *cache);
408 int presto_get_kmlsize(char *path, __u64 *size);
409 int presto_get_lastrecno(char *path, off_t *size);
410 int presto_set_fsetroot(struct dentry *dentry, char *fsetname,
412 int presto_set_fsetroot_from_ioc(struct dentry *dentry, char *fsetname,
414 int presto_is_read_only(struct presto_file_set *);
415 int presto_truncate_lml(struct presto_file_set *fset);
416 int lento_write_lml(char *path,
418 __u32 remote_generation,
419 __u32 remote_version,
420 struct presto_version *remote_file_version);
421 int lento_complete_closes(char *path);
422 int presto_f2m(struct presto_file_set *fset);
423 int presto_prep(struct dentry *, struct presto_cache **,
424 struct presto_file_set **);
426 extern struct presto_cache *presto_cache_init(void);
427 extern void presto_cache_add(struct presto_cache *cache);
428 extern void presto_cache_init_hash(void);
430 struct presto_cache *presto_cache_find(struct super_block *sb);
432 #define PRESTO_REQLOW (3 * 4096)
433 #define PRESTO_REQHIGH (6 * 4096)
434 void presto_release_space(struct presto_cache *cache, loff_t req);
435 int presto_reserve_space(struct presto_cache *cache, loff_t req);
437 #define PRESTO_DATA 0x00000002 /* cached data is valid */
438 #define PRESTO_ATTR 0x00000004 /* attributes cached */
439 #define PRESTO_DONT_JOURNAL 0x00000008 /* things like .intermezzo/ */
441 struct presto_file_set *presto_path2fileset(const char *name);
442 int izo_revoke_permit(struct dentry *, uuid_t uuid);
443 int presto_chk(struct dentry *dentry, int flag);
444 void presto_set(struct dentry *dentry, int flag);
445 int presto_get_permit(struct inode *inode);
446 int presto_put_permit(struct inode *inode);
447 int presto_set_max_kml_size(const char *path, unsigned long max_size);
448 int izo_mark_dentry(struct dentry *dentry, int and, int or, int *res);
449 int izo_mark_cache(struct dentry *dentry, int and_bits, int or_bits, int *);
450 int izo_mark_fset(struct dentry *dentry, int and_bits, int or_bits, int *);
451 void presto_getversion(struct presto_version *pv, struct inode *inode);
452 int presto_i2m(struct inode *inode);
453 int presto_c2m(struct presto_cache *cache);
457 int izo_purge_file(struct presto_file_set *fset, char *file);
458 int presto_adjust_lml(struct file *file, struct lento_vfs_context *info);
468 void presto_trans_commit(struct presto_file_set *fset, void *handle);
469 void *presto_trans_start(struct presto_file_set *fset, struct inode *inode,
471 int presto_fread(struct file *file, char *str, int len, loff_t *off);
472 int presto_clear_lml_close(struct presto_file_set *fset,
474 int presto_complete_lml(struct presto_file_set *fset);
475 int presto_read_kml_logical_offset(struct rec_info *recinfo,
476 struct presto_file_set *fset);
477 int presto_write_kml_logical_offset(struct presto_file_set *fset);
478 struct file *presto_copy_kml_tail(struct presto_file_set *fset,
479 unsigned long int start);
480 int presto_finish_kml_truncate(struct presto_file_set *fset,
481 unsigned long int offset);
482 int izo_lookup_file(struct presto_file_set *fset, char *path,
483 struct nameidata *nd);
484 int izo_do_truncate(struct presto_file_set *fset, struct dentry *dentry,
485 loff_t length, loff_t size_check);
486 int izo_log_close(struct presto_log_fd *logfd);
487 struct file *izo_log_open(struct presto_file_set *fset, char *name, int flags);
488 int izo_init_kml_file(struct presto_file_set *, struct presto_log_fd *);
489 int izo_init_lml_file(struct presto_file_set *, struct presto_log_fd *);
490 int izo_init_last_rcvd_file(struct presto_file_set *, struct presto_log_fd *);
494 /* Extra data needed in the KML for rollback operations; this structure is
495 * passed around during the KML-writing process. */
496 struct izo_rollback_data {
503 int presto_write_last_rcvd(struct rec_info *recinfo,
504 struct presto_file_set *fset,
505 struct lento_vfs_context *info);
506 void izo_get_rollback_data(struct inode *inode, struct izo_rollback_data *rb);
507 int presto_do_close(struct presto_file_set *fset, struct file *file);
508 int presto_do_setattr(struct presto_file_set *fset, struct dentry *dentry,
509 struct iattr *iattr, struct lento_vfs_context *info);
510 int presto_do_create(struct presto_file_set *fset, struct dentry *dir,
511 struct dentry *dentry, int mode,
512 struct lento_vfs_context *info);
513 int presto_do_link(struct presto_file_set *fset, struct dentry *dir,
514 struct dentry *old_dentry, struct dentry *new_dentry,
515 struct lento_vfs_context *info);
516 int presto_do_unlink(struct presto_file_set *fset, struct dentry *dir,
517 struct dentry *dentry, struct lento_vfs_context *info);
518 int presto_do_symlink(struct presto_file_set *fset, struct dentry *dir,
519 struct dentry *dentry, const char *name,
520 struct lento_vfs_context *info);
521 int presto_do_mkdir(struct presto_file_set *fset, struct dentry *dir,
522 struct dentry *dentry, int mode,
523 struct lento_vfs_context *info);
524 int presto_do_rmdir(struct presto_file_set *fset, struct dentry *dir,
525 struct dentry *dentry, struct lento_vfs_context *info);
526 int presto_do_mknod(struct presto_file_set *fset, struct dentry *dir,
527 struct dentry *dentry, int mode, dev_t dev,
528 struct lento_vfs_context *info);
529 int do_rename(struct presto_file_set *fset, struct dentry *old_dir,
530 struct dentry *old_dentry, struct dentry *new_dir,
531 struct dentry *new_dentry, struct lento_vfs_context *info);
532 int presto_do_statfs (struct presto_file_set *fset,
533 struct kstatfs * buf);
535 int lento_setattr(const char *name, struct iattr *iattr,
536 struct lento_vfs_context *info);
537 int lento_create(const char *name, int mode, struct lento_vfs_context *info);
538 int lento_link(const char *oldname, const char *newname,
539 struct lento_vfs_context *info);
540 int lento_unlink(const char *name, struct lento_vfs_context *info);
541 int lento_symlink(const char *oldname,const char *newname,
542 struct lento_vfs_context *info);
543 int lento_mkdir(const char *name, int mode, struct lento_vfs_context *info);
544 int lento_rmdir(const char *name, struct lento_vfs_context *info);
545 int lento_mknod(const char *name, int mode, dev_t dev,
546 struct lento_vfs_context *info);
547 int lento_rename(const char *oldname, const char *newname,
548 struct lento_vfs_context *info);
549 int lento_iopen(const char *name, ino_t ino, unsigned int generation,int flags);
553 #define JOURNAL_PAGE_SZ PAGE_SIZE
555 int presto_no_journal(struct presto_file_set *fset);
556 int journal_fetch(int minor);
557 int presto_log(struct presto_file_set *fset, struct rec_info *rec,
558 const char *buf, size_t size,
559 const char *string1, int len1,
560 const char *string2, int len2,
561 const char *string3, int len3);
562 int presto_get_fileid(int minor, struct presto_file_set *fset,
563 struct dentry *dentry);
564 int presto_journal_setattr(struct rec_info *rec, struct presto_file_set *fset,
565 struct dentry *dentry, struct presto_version *old_ver,
566 struct izo_rollback_data *, struct iattr *iattr);
567 int presto_journal_create(struct rec_info *rec, struct presto_file_set *fset,
568 struct dentry *dentry,
569 struct presto_version *tgt_dir_ver,
570 struct presto_version *new_file_ver, int mode);
571 int presto_journal_link(struct rec_info *rec, struct presto_file_set *fset,
572 struct dentry *src, struct dentry *tgt,
573 struct presto_version *tgt_dir_ver,
574 struct presto_version *new_link_ver);
575 int presto_journal_unlink(struct rec_info *rec, struct presto_file_set *fset,
577 struct presto_version *tgt_dir_ver,
578 struct presto_version *old_file_ver,
579 struct izo_rollback_data *, struct dentry *dentry,
580 char *old_target, int old_targetlen);
581 int presto_journal_symlink(struct rec_info *rec, struct presto_file_set *fset,
582 struct dentry *dentry, const char *target,
583 struct presto_version *tgt_dir_ver,
584 struct presto_version *new_link_ver);
585 int presto_journal_mkdir(struct rec_info *rec, struct presto_file_set *fset,
586 struct dentry *dentry,
587 struct presto_version *tgt_dir_ver,
588 struct presto_version *new_dir_ver, int mode);
589 int presto_journal_rmdir(struct rec_info *rec, struct presto_file_set *fset,
590 struct dentry *dentry,
591 struct presto_version *tgt_dir_ver,
592 struct presto_version *old_dir_ver,
593 struct izo_rollback_data *, int len, const char *name);
594 int presto_journal_mknod(struct rec_info *rec, struct presto_file_set *fset,
595 struct dentry *dentry,
596 struct presto_version *tgt_dir_ver,
597 struct presto_version *new_node_ver, int mode,
598 int dmajor, int dminor);
599 int presto_journal_rename(struct rec_info *rec, struct presto_file_set *fset,
600 struct dentry *src, struct dentry *tgt,
601 struct presto_version *src_dir_ver,
602 struct presto_version *tgt_dir_ver);
603 int presto_journal_open(struct rec_info *, struct presto_file_set *,
604 struct dentry *, struct presto_version *old_ver);
605 int presto_journal_close(struct rec_info *rec, struct presto_file_set *,
606 struct presto_file_data *, struct dentry *,
607 struct presto_version *old_file_ver,
608 struct presto_version *new_file_ver);
609 int presto_write_lml_close(struct rec_info *rec,
610 struct presto_file_set *fset,
613 __u64 remote_generation,
614 struct presto_version *remote_version,
615 struct presto_version *new_file_ver);
616 void presto_log_op(void *data, int len);
617 loff_t presto_kml_offset(struct presto_file_set *fset);
620 #define SYNCHRONOUS 0
621 #define ASYNCHRONOUS 1
622 /* asynchronous calls */
623 int izo_upc_kml(int minor, __u64 offset, __u32 first_recno, __u64 length,
624 __u32 last_recno, char *fsetname);
625 int izo_upc_kml_truncate(int minor, __u64 length, __u32 last_recno,
627 int izo_upc_go_fetch_kml(int minor, char *fsetname, uuid_t uuid, __u64 kmlsize);
628 int izo_upc_backfetch(int minor, char *path, char *fileset,
629 struct lento_vfs_context *);
631 /* synchronous calls */
632 int izo_upc_get_fileid(int minor, __u32 reclen, char *rec,
633 __u32 pathlen, char *path, char *fsetname);
634 int izo_upc_permit(int minor, struct dentry *, __u32 pathlen, char *path,
636 int izo_upc_open(int minor, __u32 pathlen, char *path, char *fsetname,
637 struct lento_vfs_context *info);
638 int izo_upc_connect(int minor, __u64 ip_address, __u64 port, __u8 uuid[16],
640 int izo_upc_revoke_permit(int minor, char *fsetname, uuid_t uuid);
641 int izo_upc_set_kmlsize(int minor, char *fsetname, uuid_t uuid, __u64 kmlsize);
642 int izo_upc_client_make_branch(int minor, char *fsetname);
643 int izo_upc_server_make_branch(int minor, char *fsetname);
644 int izo_upc_branch_undo(int minor, char *fsetname, char *branchname);
645 int izo_upc_branch_redo(int minor, char *fsetname, char *branchname);
646 int izo_upc_repstatus(int minor, char * fsetname, struct izo_rcvd_rec *lr_server);
648 /* general mechanism */
649 int izo_upc_upcall(int minor, int *size, struct izo_upcall_hdr *, int async);
652 int izo_repstatus(struct presto_file_set *fset, __u64 client_kmlsize,
653 struct izo_rcvd_rec *lr_client, struct izo_rcvd_rec *lr_server);
654 int izo_rep_cache_init(struct presto_file_set *);
655 loff_t izo_rcvd_get(struct izo_rcvd_rec *, struct presto_file_set *, char *uuid);
656 loff_t izo_rcvd_write(struct presto_file_set *, struct izo_rcvd_rec *);
657 loff_t izo_rcvd_upd_remote(struct presto_file_set *fset, char * uuid, __u64 remote_recno,
658 __u64 remote_offset);
660 int izo_ioctl_packlen(struct izo_ioctl_data *data);
663 int init_intermezzo_sysctl(void);
664 void cleanup_intermezzo_sysctl(void);
667 /* We will be more tolerant than the default ea patch with attr name sizes and
668 * the size of value. If these come via VFS from the default ea patches, the
669 * corresponding character strings will be truncated anyway. During journalling- * we journal length for both name and value. See journal_set_ext_attr.
671 #define PRESTO_EXT_ATTR_NAME_MAX 128
672 #define PRESTO_EXT_ATTR_VALUE_MAX 8192
674 #define PRESTO_ALLOC(ptr, size) \
677 (ptr) = kmalloc(s, GFP_KERNEL); \
679 CERROR("IZO: out of memory at %s:%d (trying to " \
680 "allocate %ld)\n", __FILE__, __LINE__, s); \
682 presto_kmem_inc((ptr), s); \
683 memset((ptr), 0, s); \
685 CDEBUG(D_MALLOC, "kmalloced: %ld at %p (tot %ld).\n", \
686 s, (ptr), presto_kmemory); \
689 #define PRESTO_FREE(ptr, size) \
692 if ((ptr) == NULL) { \
693 CERROR("IZO: free NULL pointer (%ld bytes) at " \
694 "%s:%d\n", s, __FILE__, __LINE__); \
698 CDEBUG(D_MALLOC, "kfreed: %ld at %p (tot %ld).\n", \
699 s, (ptr), presto_kmemory); \
700 presto_kmem_dec((ptr), s); \
703 static inline int dentry_name_cmp(struct dentry *dentry, char *name)
705 return (strlen(name) == dentry->d_name.len &&
706 memcmp(name, dentry->d_name.name, dentry->d_name.len) == 0);
709 static inline char *strdup(char *str)
712 tmp = kmalloc(strlen(str) + 1, GFP_KERNEL);
714 memcpy(tmp, str, strlen(str) + 1);
719 static inline int izo_ioctl_is_invalid(struct izo_ioctl_data *data)
721 if (data->ioc_len > (1<<30)) {
722 CERROR("IZO ioctl: ioc_len larger than 1<<30\n");
725 if (data->ioc_inllen1 > (1<<30)) {
726 CERROR("IZO ioctl: ioc_inllen1 larger than 1<<30\n");
729 if (data->ioc_inllen2 > (1<<30)) {
730 CERROR("IZO ioctl: ioc_inllen2 larger than 1<<30\n");
733 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
734 CERROR("IZO ioctl: inlbuf1 pointer but 0 length\n");
737 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
738 CERROR("IZO ioctl: inlbuf2 pointer but 0 length\n");
741 if (data->ioc_pbuf1 && !data->ioc_plen1) {
742 CERROR("IZO ioctl: pbuf1 pointer but 0 length\n");
745 if (data->ioc_pbuf2 && !data->ioc_plen2) {
746 CERROR("IZO ioctl: pbuf2 pointer but 0 length\n");
749 if (izo_ioctl_packlen(data) != data->ioc_len ) {
750 CERROR("IZO ioctl: packlen exceeds ioc_len\n");
753 if (data->ioc_inllen1 &&
754 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
755 CERROR("IZO ioctl: inlbuf1 not 0 terminated\n");
758 if (data->ioc_inllen2 &&
759 data->ioc_bulk[size_round(data->ioc_inllen1) + data->ioc_inllen2
761 CERROR("IZO ioctl: inlbuf2 not 0 terminated\n");
767 /* buffer MUST be at least the size of izo_ioctl_hdr */
768 static inline int izo_ioctl_getdata(char *buf, char *end, void *arg)
770 struct izo_ioctl_hdr *hdr;
771 struct izo_ioctl_data *data;
775 hdr = (struct izo_ioctl_hdr *)buf;
776 data = (struct izo_ioctl_data *)buf;
778 err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
784 if (hdr->ioc_version != IZO_IOCTL_VERSION) {
785 CERROR("IZO: version mismatch kernel vs application\n");
789 if (hdr->ioc_len + buf >= end) {
790 CERROR("IZO: user buffer exceeds kernel buffer\n");
794 if (hdr->ioc_len < sizeof(struct izo_ioctl_data)) {
795 CERROR("IZO: user buffer too small for ioctl\n");
799 err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
805 if (izo_ioctl_is_invalid(data)) {
806 CERROR("IZO: ioctl not correctly formatted\n");
810 if (data->ioc_inllen1) {
811 data->ioc_inlbuf1 = &data->ioc_bulk[0];
814 if (data->ioc_inllen2) {
815 data->ioc_inlbuf2 = &data->ioc_bulk[0] +
816 size_round(data->ioc_inllen1);
823 # define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
826 # define malloc(a) kmalloc(a, GFP_KERNEL)
827 # define printf printk
828 int kml_reint_rec(struct file *dir, struct izo_ioctl_data *data);
829 int izo_get_fileid(struct file *dir, struct izo_ioctl_data *data);
830 int izo_set_fileid(struct file *dir, struct izo_ioctl_data *data);
832 #else /* __KERNEL__ */
835 # include <sys/types.h>
836 # include <sys/ioctl.h>
839 # define printk printf
841 # define CERROR printf
843 # define kmalloc(a,b) malloc(a)
845 void init_fsreintdata (void);
846 int kml_fsreint(struct kml_rec *rec, char *basedir);
847 int kml_iocreint(__u32 size, char *ptr, __u32 offset, int dird,
848 uuid_t uuid, __u32 generate_kml);
850 static inline void izo_ioctl_init(struct izo_ioctl_data *data)
852 memset(data, 0, sizeof(*data));
853 data->ioc_len = sizeof(*data);
854 data->ioc_version = IZO_IOCTL_VERSION;
858 izo_ioctl_pack(struct izo_ioctl_data *data, char **pbuf, int max)
861 struct izo_ioctl_data *overlay;
862 data->ioc_len = izo_ioctl_packlen(data);
863 data->ioc_version = IZO_IOCTL_VERSION;
865 if (*pbuf && izo_ioctl_packlen(data) > max)
868 *pbuf = malloc(data->ioc_len);
871 overlay = (struct izo_ioctl_data *)*pbuf;
872 memcpy(*pbuf, data, sizeof(*data));
874 ptr = overlay->ioc_bulk;
875 if (data->ioc_inlbuf1)
876 LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr);
877 if (data->ioc_inlbuf2)
878 LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr);
879 if (izo_ioctl_is_invalid(overlay))
885 #endif /* __KERNEL__*/
887 #define IZO_ERROR_NAME 1
888 #define IZO_ERROR_UPDATE 2
889 #define IZO_ERROR_DELETE 3
890 #define IZO_ERROR_RENAME 4
892 static inline char *izo_error(int err)
896 return strerror(-err);
900 return "InterMezzo name/name conflict";
901 case IZO_ERROR_UPDATE:
902 return "InterMezzo update/update conflict";
903 case IZO_ERROR_DELETE:
904 return "InterMezzo update/delete conflict";
905 case IZO_ERROR_RENAME:
906 return "InterMezzo rename/rename conflict";
908 return "Unknown InterMezzo error";
912 char *kml_print_rec(struct kml_rec *rec, int brief);
913 int kml_unpack(struct kml_rec *rec, char **buf, char *end);
917 /* is_read_only() is replaced by bdev_read_only which takes struct
918 block_device *. Since this is only needed for debugging, it can be
921 #define is_read_only(dev) 0