1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2000 Stelias Computing, Inc.
5 * Copyright (C) 2000 Red Hat, Inc.
6 * Copyright (C) 2000 Tacitus Systems
7 * Copyright (C) 2000 Peter J. Braam
9 * This file is part of InterMezzo, http://www.inter-mezzo.org.
11 * InterMezzo is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * InterMezzo is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with InterMezzo; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <asm/bitops.h>
28 #include <asm/uaccess.h>
29 #include <asm/system.h>
30 #include <linux/smp_lock.h>
32 #include <linux/errno.h>
34 #include <linux/ext2_fs.h>
35 #include <linux/slab.h>
36 #include <linux/vmalloc.h>
37 #include <linux/sched.h>
38 #include <linux/stat.h>
39 #include <linux/string.h>
40 #include <linux/locks.h>
41 #include <linux/blkdev.h>
42 #include <linux/init.h>
43 #define __NO_VERSION__
44 #include <linux/module.h>
46 #include <linux/intermezzo_fs.h>
47 #include <linux/intermezzo_psdev.h>
49 static inline void presto_relock_sem(struct inode *dir)
51 /* the lock from sys_mkdir / lookup_create */
53 /* the rest is done by the do_{create,mkdir, ...} */
56 static inline void presto_relock_other(struct inode *dir)
63 static inline void presto_fulllock(struct inode *dir)
65 /* the lock from sys_mkdir / lookup_create */
72 static inline void presto_unlock(struct inode *dir)
77 /* the lock from sys_mkdir / lookup_create */
83 * these are initialized in super.c
85 extern int presto_permission(struct inode *inode, int mask);
86 static int izo_authorized_uid = 0;
88 int izo_dentry_is_ilookup(struct dentry *dentry, ino_t *id,
89 unsigned int *generation)
95 /* prefix is 7 characters: '...ino:' */
96 if ( dentry->d_name.len < 7 || dentry->d_name.len > 64 ||
97 memcmp(dentry->d_name.name, PRESTO_ILOOKUP_MAGIC, 7) != 0 ) {
102 memcpy(tmpname, dentry->d_name.name + 7, dentry->d_name.len - 7);
103 *(tmpname + dentry->d_name.len - 7) = '\0';
105 /* name is of the form ...ino:<inode number>:<generation> */
106 *id = simple_strtoul(tmpname, &next, 16);
107 if ( *next == PRESTO_ILOOKUP_SEP ) {
108 *generation = simple_strtoul(next + 1, 0, 16);
109 CDEBUG(D_INODE, "ino string: %s, Id = %lx (%lu), "
110 "generation %x (%d)\n",
111 tmpname, *id, *id, *generation, *generation);
120 struct dentry *presto_tmpfs_ilookup(struct inode *dir,
121 struct dentry *dentry,
123 unsigned int generation)
129 inline int presto_can_ilookup(void)
131 return (current->euid == izo_authorized_uid ||
132 capable(CAP_DAC_READ_SEARCH));
135 struct dentry *presto_iget_ilookup(struct inode *dir,
136 struct dentry *dentry,
138 unsigned int generation)
145 if ( !presto_can_ilookup() ) {
146 CERROR("ilookup denied: euid %u, authorized_uid %u\n",
147 current->euid, izo_authorized_uid);
148 return ERR_PTR(-EPERM);
151 inode = iget(dir->i_sb, ino);
153 CERROR("fatal: NULL inode ino %lu\n", ino);
156 if (is_bad_inode(inode) || inode->i_nlink == 0) {
157 CERROR("fatal: bad inode ino %lu, links %d\n", ino, inode->i_nlink);
160 if (inode->i_generation != generation) {
161 CERROR("fatal: bad generation %u (want %u)\n",
162 inode->i_generation, generation);
166 d_instantiate(dentry, inode);
167 dentry->d_flags |= DCACHE_NFSD_DISCONNECTED; /* NFS hack */
175 return ERR_PTR(error);
178 struct dentry *presto_add_ilookup_dentry(struct dentry *parent,
181 struct inode *inode = real->d_inode;
185 struct dentry *inodir;
186 struct presto_dentry_data *dd;
188 inodir = lookup_one_len("..iopen..", parent, strlen("..iopen.."));
189 if (!inodir || IS_ERR(inodir) || !inodir->d_inode ) {
190 CERROR("%s: bad ..iopen.. lookup\n", __FUNCTION__);
193 inodir->d_inode->i_op = &presto_dir_iops;
195 snprintf(ptr, 32, "...ino:%lx:%x", inode->i_ino, inode->i_generation);
197 de = lookup_one_len(ptr, inodir, strlen(ptr));
198 if (!de || IS_ERR(de)) {
199 CERROR("%s: bad ...ino lookup %ld\n",
200 __FUNCTION__, PTR_ERR(de));
205 dd = presto_d2d(real);
213 if (de->d_inode != inode ) {
214 CERROR("XX de->d_inode %ld, inode %ld\n",
215 de->d_inode->i_ino, inode->i_ino);
218 if (dd->dd_inodentry) {
219 CERROR("inodentry exists %ld \n", inode->i_ino);
230 atomic_inc(&inode->i_count);
231 de->d_op = &presto_dentry_ops;
234 CERROR("DD: no ops dentry %p, dd %p\n", de, dd);
235 dd->dd_inodentry = de;
243 struct dentry *presto_lookup(struct inode * dir, struct dentry *dentry)
247 struct presto_cache *cache;
250 unsigned int generation;
251 struct inode_operations *iops;
255 cache = presto_get_cache(dir);
257 CERROR("InterMezzo BUG: no cache in presto_lookup "
258 "(dir ino: %ld)!\n", dir->i_ino);
262 minor = presto_c2m(cache);
264 iops = filter_c2cdiops(cache->cache_filter);
265 if (!iops || !iops->lookup) {
266 CERROR("InterMezzo BUG: filesystem has no lookup\n");
272 CDEBUG(D_CACHE, "dentry %p, dir ino: %ld, name: %*s, islento: %d\n",
273 dentry, dir->i_ino, dentry->d_name.len, dentry->d_name.name,
276 if (dentry->d_fsdata)
277 CERROR("DD -- BAD dentry %p has data\n", dentry);
279 dentry->d_fsdata = NULL;
281 if (ext2_check_for_iopen(dir, dentry))
285 if ( izo_dentry_is_ilookup(dentry, &ino, &generation) ) {
286 de = cache->cache_filter->o_trops->tr_ilookup
287 (dir, dentry, ino, generation);
290 de = iops->lookup(dir, dentry);
296 CERROR("dentry lookup error %ld\n", PTR_ERR(de));
300 /* some file systems have no read_inode: set methods here */
302 presto_set_ops(dentry->d_inode, cache->cache_filter);
304 filter_setup_dentry_ops(cache->cache_filter,
305 dentry->d_op, &presto_dentry_ops);
306 dentry->d_op = filter_c2udops(cache->cache_filter);
308 /* In lookup we will tolerate EROFS return codes from presto_set_dd
309 * to placate NFS. EROFS indicates that a fileset was not found but
310 * we should still be able to continue through a lookup.
311 * Anything else is a hard error and must be returned to VFS. */
313 rc = presto_set_dd(dentry);
314 if (rc && rc != -EROFS) {
315 CERROR("presto_set_dd failed (dir %ld, name %*s): %d\n",
316 dir->i_ino, dentry->d_name.len, dentry->d_name.name, rc);
324 static inline int presto_check_set_fsdata (struct dentry *de)
326 if (presto_d2d(de) == NULL) {
328 CERROR("dentry without fsdata: %p: %*s\n", de,
329 de->d_name.len, de->d_name.name);
332 return presto_set_dd (de);
338 int presto_setattr(struct dentry *de, struct iattr *iattr)
341 struct presto_cache *cache;
342 struct presto_file_set *fset;
343 struct lento_vfs_context info = { 0, 0, 0 };
347 error = presto_prep(de, &cache, &fset);
353 if (!iattr->ia_valid)
354 CDEBUG(D_INODE, "presto_setattr: iattr is not valid\n");
356 CDEBUG(D_INODE, "valid %#x, mode %#o, uid %u, gid %u, size %Lu, "
357 "atime %lu mtime %lu ctime %lu flags %d\n",
358 iattr->ia_valid, iattr->ia_mode, iattr->ia_uid, iattr->ia_gid,
359 iattr->ia_size, iattr->ia_atime, iattr->ia_mtime,
360 iattr->ia_ctime, iattr->ia_attr_flags);
362 if ( presto_get_permit(de->d_inode) < 0 ) {
367 if (!ISLENTO(presto_c2m(cache)))
368 info.flags = LENTO_FL_KML;
369 info.flags |= LENTO_FL_IGNORE_TIME;
370 error = presto_do_setattr(fset, de, iattr, &info);
371 presto_put_permit(de->d_inode);
376 * Now the meat: the fs operations that require journaling
379 * XXX: some of these need modifications for hierarchical filesets
382 int presto_prep(struct dentry *dentry, struct presto_cache **cache,
383 struct presto_file_set **fset)
387 /* NFS might pass us dentries which have not gone through lookup.
388 * Test and set d_fsdata for such dentries
390 rc = presto_check_set_fsdata (dentry);
393 *fset = presto_fset(dentry);
394 if ( *fset == NULL ) {
395 CERROR("No file set for dentry at %p: %*s\n", dentry,
396 dentry->d_name.len, dentry->d_name.name);
400 *cache = (*fset)->fset_cache;
401 if ( *cache == NULL ) {
402 CERROR("PRESTO: BAD, BAD: cannot find cache\n");
406 CDEBUG(D_PIOCTL, "---> cache flags %x, fset flags %x\n",
407 (*cache)->cache_flags, (*fset)->fset_flags);
408 if( presto_is_read_only(*fset) ) {
409 CERROR("PRESTO: cannot modify read-only fileset, minor %d.\n",
416 static int presto_create(struct inode * dir, struct dentry * dentry, int mode)
419 struct presto_cache *cache;
420 struct dentry *parent = dentry->d_parent;
421 struct lento_vfs_context info;
422 struct presto_file_set *fset;
425 error = presto_check_set_fsdata(dentry);
431 error = presto_prep(dentry->d_parent, &cache, &fset);
438 /* Does blocking and non-blocking behavious need to be
439 checked for. Without blocking (return 1), the permit
440 was acquired without reintegration
442 if ( presto_get_permit(dir) < 0 ) {
444 presto_fulllock(dir);
448 presto_relock_sem(dir);
449 parent = dentry->d_parent;
450 memset(&info, 0, sizeof(info));
451 if (!ISLENTO(presto_c2m(cache)))
452 info.flags = LENTO_FL_KML;
453 info.flags |= LENTO_FL_IGNORE_TIME;
454 error = presto_do_create(fset, parent, dentry, mode, &info);
456 presto_relock_other(dir);
457 presto_put_permit(dir);
462 static int presto_link(struct dentry *old_dentry, struct inode *dir,
463 struct dentry *new_dentry)
466 struct presto_cache *cache, *new_cache;
467 struct presto_file_set *fset, *new_fset;
468 struct dentry *parent = new_dentry->d_parent;
469 struct lento_vfs_context info;
472 error = presto_prep(old_dentry, &cache, &fset);
478 error = presto_check_set_fsdata(new_dentry);
484 error = presto_prep(new_dentry->d_parent, &new_cache, &new_fset);
490 if (fset != new_fset) {
496 if ( presto_get_permit(old_dentry->d_inode) < 0 ) {
498 presto_fulllock(dir);
502 if ( presto_get_permit(dir) < 0 ) {
504 presto_fulllock(dir);
508 presto_relock_sem(dir);
509 parent = new_dentry->d_parent;
511 memset(&info, 0, sizeof(info));
512 if (!ISLENTO(presto_c2m(cache)))
513 info.flags = LENTO_FL_KML;
514 info.flags |= LENTO_FL_IGNORE_TIME;
515 error = presto_do_link(fset, old_dentry, parent,
519 /* XXX for links this is not right */
520 if (cache->cache_filter->o_trops->tr_add_ilookup ) {
522 d = cache->cache_filter->o_trops->tr_add_ilookup
523 (dir->i_sb->s_root, new_dentry, 1);
527 presto_relock_other(dir);
528 presto_put_permit(dir);
529 presto_put_permit(old_dentry->d_inode);
533 static int presto_mkdir(struct inode * dir, struct dentry * dentry, int mode)
536 struct presto_file_set *fset;
537 struct presto_cache *cache;
538 struct dentry *parent = dentry->d_parent;
539 struct lento_vfs_context info;
543 error = presto_check_set_fsdata(dentry);
549 error = presto_prep(dentry->d_parent, &cache, &fset);
557 if ( presto_get_permit(dir) < 0 ) {
559 presto_fulllock(dir);
563 memset(&info, 0, sizeof(info));
564 if (!ISLENTO(presto_c2m(cache)))
565 info.flags = LENTO_FL_KML;
566 info.flags |= LENTO_FL_IGNORE_TIME;
568 presto_relock_sem(dir);
569 parent = dentry->d_parent;
570 error = presto_do_mkdir(fset, parent, dentry, mode, &info);
571 presto_relock_other(dir);
572 presto_put_permit(dir);
578 static int presto_symlink(struct inode *dir, struct dentry *dentry,
582 struct presto_cache *cache;
583 struct presto_file_set *fset;
584 struct dentry *parent = dentry->d_parent;
585 struct lento_vfs_context info;
588 error = presto_check_set_fsdata(dentry);
594 error = presto_prep(dentry->d_parent, &cache, &fset);
601 if ( presto_get_permit(dir) < 0 ) {
603 presto_fulllock(dir);
607 presto_relock_sem(dir);
608 parent = dentry->d_parent;
609 memset(&info, 0, sizeof(info));
610 if (!ISLENTO(presto_c2m(cache)))
611 info.flags = LENTO_FL_KML;
612 info.flags |= LENTO_FL_IGNORE_TIME;
613 error = presto_do_symlink(fset, parent, dentry, name, &info);
614 presto_relock_other(dir);
615 presto_put_permit(dir);
619 int presto_unlink(struct inode *dir, struct dentry *dentry)
622 struct presto_cache *cache;
623 struct presto_file_set *fset;
624 struct dentry *parent = dentry->d_parent;
625 struct lento_vfs_context info;
628 error = presto_check_set_fsdata(dentry);
634 error = presto_prep(dentry->d_parent, &cache, &fset);
641 if ( presto_get_permit(dir) < 0 ) {
643 presto_fulllock(dir);
647 presto_relock_sem(dir);
648 parent = dentry->d_parent;
649 memset(&info, 0, sizeof(info));
650 if (!ISLENTO(presto_c2m(cache)))
651 info.flags = LENTO_FL_KML;
652 info.flags |= LENTO_FL_IGNORE_TIME;
654 error = presto_do_unlink(fset, parent, dentry, &info);
656 presto_relock_other(dir);
657 presto_put_permit(dir);
661 static int presto_rmdir(struct inode *dir, struct dentry *dentry)
664 struct presto_cache *cache;
665 struct presto_file_set *fset;
666 struct dentry *parent = dentry->d_parent;
667 struct lento_vfs_context info;
670 CDEBUG(D_FILE, "prepping presto\n");
671 error = presto_check_set_fsdata(dentry);
678 error = presto_prep(dentry->d_parent, &cache, &fset);
684 CDEBUG(D_FILE, "unlocking\n");
685 /* We need to dget() before the dput in double_unlock, to ensure we
686 * still have dentry references. double_lock doesn't do dget for us.
689 if (d_unhashed(dentry))
691 double_up(&dir->i_zombie, &dentry->d_inode->i_zombie);
692 double_up(&dir->i_sem, &dentry->d_inode->i_sem);
694 CDEBUG(D_FILE, "getting permit\n");
695 if ( presto_get_permit(parent->d_inode) < 0 ) {
697 double_down(&dir->i_sem, &dentry->d_inode->i_sem);
698 double_down(&dir->i_zombie, &dentry->d_inode->i_zombie);
703 CDEBUG(D_FILE, "locking\n");
705 double_down(&dir->i_sem, &dentry->d_inode->i_sem);
706 parent = dentry->d_parent;
707 memset(&info, 0, sizeof(info));
708 if (!ISLENTO(presto_c2m(cache)))
709 info.flags = LENTO_FL_KML;
710 info.flags |= LENTO_FL_IGNORE_TIME;
711 error = presto_do_rmdir(fset, parent, dentry, &info);
712 presto_put_permit(parent->d_inode);
718 static int presto_mknod(struct inode * dir, struct dentry * dentry, int mode, int rdev)
721 struct presto_cache *cache;
722 struct presto_file_set *fset;
723 struct dentry *parent = dentry->d_parent;
724 struct lento_vfs_context info;
727 error = presto_check_set_fsdata(dentry);
733 error = presto_prep(dentry->d_parent, &cache, &fset);
740 if ( presto_get_permit(dir) < 0 ) {
742 presto_fulllock(dir);
746 presto_relock_sem(dir);
747 parent = dentry->d_parent;
748 memset(&info, 0, sizeof(info));
749 if (!ISLENTO(presto_c2m(cache)))
750 info.flags = LENTO_FL_KML;
751 info.flags |= LENTO_FL_IGNORE_TIME;
752 error = presto_do_mknod(fset, parent, dentry, mode, rdev, &info);
753 presto_relock_other(dir);
754 presto_put_permit(dir);
759 inline void presto_triple_unlock(struct inode *old_dir, struct inode *new_dir,
760 struct dentry *old_dentry,
761 struct dentry *new_dentry, int triple)
763 /* rename_dir case */
764 if (S_ISDIR(old_dentry->d_inode->i_mode)) {
766 triple_up(&old_dir->i_zombie,
768 &new_dentry->d_inode->i_zombie);
770 double_up(&old_dir->i_zombie,
773 up(&old_dir->i_sb->s_vfs_rename_sem);
774 } else /* this case is rename_other */
775 double_up(&old_dir->i_zombie, &new_dir->i_zombie);
776 /* done by do_rename */
778 double_up(&old_dir->i_sem, &new_dir->i_sem);
781 inline void presto_triple_fulllock(struct inode *old_dir,
782 struct inode *new_dir,
783 struct dentry *old_dentry,
784 struct dentry *new_dentry, int triple)
786 /* done by do_rename */
787 double_down(&old_dir->i_sem, &new_dir->i_sem);
789 /* rename_dir case */
790 if (S_ISDIR(old_dentry->d_inode->i_mode)) {
791 down(&old_dir->i_sb->s_vfs_rename_sem);
793 triple_down(&old_dir->i_zombie,
795 &new_dentry->d_inode->i_zombie);
797 double_down(&old_dir->i_zombie,
800 } else /* this case is rename_other */
801 double_down(&old_dir->i_zombie, &new_dir->i_zombie);
804 inline void presto_triple_relock_sem(struct inode *old_dir,
805 struct inode *new_dir,
806 struct dentry *old_dentry,
807 struct dentry *new_dentry, int triple)
809 /* done by do_rename */
810 double_down(&old_dir->i_sem, &new_dir->i_sem);
814 inline void presto_triple_relock_other(struct inode *old_dir,
815 struct inode *new_dir,
816 struct dentry *old_dentry,
817 struct dentry *new_dentry, int triple)
819 /* rename_dir case */
820 if (S_ISDIR(old_dentry->d_inode->i_mode)) {
821 down(&old_dir->i_sb->s_vfs_rename_sem);
823 triple_down(&old_dir->i_zombie,
825 &new_dentry->d_inode->i_zombie);
827 double_down(&old_dir->i_zombie,
830 } else /* this case is rename_other */
831 double_down(&old_dir->i_zombie, &new_dir->i_zombie);
835 // XXX this can be optimized: renamtes across filesets only require
836 // multiple KML records, but can locally be executed normally.
837 int presto_rename(struct inode *old_dir, struct dentry *old_dentry,
838 struct inode *new_dir, struct dentry *new_dentry)
841 struct presto_cache *cache, *new_cache;
842 struct presto_file_set *fset, *new_fset;
843 struct lento_vfs_context info;
844 struct dentry *old_parent = old_dentry->d_parent;
845 struct dentry *new_parent = new_dentry->d_parent;
849 error = presto_prep(old_dentry, &cache, &fset);
854 error = presto_prep(new_parent, &new_cache, &new_fset);
860 if ( fset != new_fset ) {
865 /* We need to do dget before the dput in double_unlock, to ensure we
866 * still have dentry references. double_lock doesn't do dget for us.
869 triple = (S_ISDIR(old_dentry->d_inode->i_mode) && new_dentry->d_inode)?
872 presto_triple_unlock(old_dir, new_dir, old_dentry, new_dentry, triple);
874 if ( presto_get_permit(old_dir) < 0 ) {
876 presto_triple_fulllock(old_dir, new_dir, old_dentry, new_dentry, triple);
879 if ( presto_get_permit(new_dir) < 0 ) {
881 presto_triple_fulllock(old_dir, new_dir, old_dentry, new_dentry, triple);
885 presto_triple_relock_sem(old_dir, new_dir, old_dentry, new_dentry, triple);
886 memset(&info, 0, sizeof(info));
887 if (!ISLENTO(presto_c2m(cache)))
888 info.flags = LENTO_FL_KML;
889 info.flags |= LENTO_FL_IGNORE_TIME;
890 error = do_rename(fset, old_parent, old_dentry, new_parent,
892 presto_triple_relock_other(old_dir, new_dir, old_dentry, new_dentry, triple);
894 presto_put_permit(new_dir);
895 presto_put_permit(old_dir);
899 /* basically this allows the ilookup processes access to all files for
900 * reading, while not making ilookup totally insecure. This could all
901 * go away if we could set the CAP_DAC_READ_SEARCH capability for the client.
903 /* If posix acls are available, the underlying cache fs will export the
904 * appropriate permission function. Thus we do not worry here about ACLs
907 int presto_permission(struct inode *inode, int mask)
909 unsigned short mode = inode->i_mode;
910 struct presto_cache *cache;
914 if ( presto_can_ilookup() && !(mask & S_IWOTH)) {
915 CDEBUG(D_CACHE, "ilookup on %ld OK\n", inode->i_ino);
920 cache = presto_get_cache(inode);
923 /* we only override the file/dir permission operations */
924 struct inode_operations *fiops = filter_c2cfiops(cache->cache_filter);
925 struct inode_operations *diops = filter_c2cdiops(cache->cache_filter);
927 if ( S_ISREG(mode) && fiops && fiops->permission ) {
929 return fiops->permission(inode, mask);
931 if ( S_ISDIR(mode) && diops && diops->permission ) {
933 return diops->permission(inode, mask);
937 /* The cache filesystem doesn't have its own permission function,
938 * but we don't want to duplicate the VFS code here. In order
939 * to avoid looping from permission calling this function again,
940 * we temporarily override the permission operation while we call
941 * the VFS permission function.
943 inode->i_op->permission = NULL;
944 rc = permission(inode, mask);
945 inode->i_op->permission = &presto_permission;
952 int presto_ioctl(struct inode *inode, struct file *file,
953 unsigned int cmd, unsigned long arg)
956 struct izo_ioctl_data *data = NULL;
957 struct presto_dentry_data *dd;
962 /* Try the filesystem's ioctl first, and return if it succeeded. */
963 dd = presto_d2d(file->f_dentry);
964 if (dd && dd->dd_fset) {
965 int (*cache_ioctl)(struct inode *, struct file *, unsigned int, unsigned long ) = filter_c2cdfops(dd->dd_fset->fset_cache->cache_filter)->ioctl;
968 rc = cache_ioctl(inode, file, cmd, arg);
975 if (current->euid != 0 && current->euid != izo_authorized_uid) {
980 memset(buf, 0, sizeof(buf));
982 if (izo_ioctl_getdata(buf, buf + 1024, (void *)arg)) {
983 CERROR("intermezzo ioctl: data error\n");
986 data = (struct izo_ioctl_data *)buf;
989 case IZO_IOC_REINTKML: {
992 rc = kml_reint_rec(file, data);
995 cperr = copy_to_user((char *)arg, data, sizeof(*data));
997 CERROR("WARNING: cperr %d\n", cperr);
1003 case IZO_IOC_GET_RCVD: {
1004 struct izo_rcvd_rec rec;
1005 struct presto_file_set *fset;
1008 fset = presto_fset(file->f_dentry);
1013 rc = izo_rcvd_get(&rec, fset, data->ioc_uuid);
1020 return copy_to_user((char *)arg, &rec, sizeof(rec))? -EFAULT : 0;
1023 case IZO_IOC_REPSTATUS: {
1024 __u64 client_kmlsize;
1025 struct izo_rcvd_rec *lr_client;
1026 struct izo_rcvd_rec rec;
1027 struct presto_file_set *fset;
1031 fset = presto_fset(file->f_dentry);
1036 minor = presto_f2m(fset);
1038 client_kmlsize = data->ioc_kmlsize;
1039 lr_client = (struct izo_rcvd_rec *) data->ioc_pbuf1;
1041 rc = izo_repstatus(fset, client_kmlsize,
1049 return copy_to_user((char *)arg, &rec, sizeof(rec))? -EFAULT : 0;
1052 case IZO_IOC_GET_CHANNEL: {
1053 struct presto_file_set *fset;
1055 fset = presto_fset(file->f_dentry);
1061 data->ioc_dev = fset->fset_cache->cache_psdev->uc_minor;
1062 CDEBUG(D_PSDEV, "CHANNEL %d\n", data->ioc_dev);
1064 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1067 case IZO_IOC_SET_IOCTL_UID:
1068 izo_authorized_uid = data->ioc_uid;
1072 case IZO_IOC_SET_PID:
1073 rc = izo_psdev_setpid(data->ioc_dev);
1077 case IZO_IOC_SET_CHANNEL:
1078 rc = izo_psdev_setchannel(file, data->ioc_dev);
1082 case IZO_IOC_GET_KML_SIZE: {
1083 struct presto_file_set *fset;
1086 fset = presto_fset(file->f_dentry);
1092 kmlsize = presto_kml_offset(fset) + fset->fset_kml_logical_off;
1095 return copy_to_user((char *)arg, &kmlsize, sizeof(kmlsize))?-EFAULT : 0;
1098 case IZO_IOC_PURGE_FILE_DATA: {
1099 struct presto_file_set *fset;
1101 fset = presto_fset(file->f_dentry);
1107 rc = izo_purge_file(fset, data->ioc_inlbuf1);
1112 case IZO_IOC_GET_FILEID: {
1113 rc = izo_get_fileid(file, data);
1117 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1120 case IZO_IOC_SET_FILEID: {
1121 rc = izo_set_fileid(file, data);
1125 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1128 case IZO_IOC_ADJUST_LML: {
1129 struct lento_vfs_context *info;
1130 info = (struct lento_vfs_context *)data->ioc_inlbuf1;
1131 rc = presto_adjust_lml(file, info);
1136 case IZO_IOC_CONNECT: {
1137 struct presto_file_set *fset;
1140 fset = presto_fset(file->f_dentry);
1145 minor = presto_f2m(fset);
1147 rc = izo_upc_connect(minor, data->ioc_ino,
1148 data->ioc_generation, data->ioc_uuid,
1154 case IZO_IOC_GO_FETCH_KML: {
1155 struct presto_file_set *fset;
1158 fset = presto_fset(file->f_dentry);
1163 minor = presto_f2m(fset);
1165 rc = izo_upc_go_fetch_kml(minor, fset->fset_name,
1166 data->ioc_uuid, data->ioc_kmlsize);
1171 case IZO_IOC_REVOKE_PERMIT:
1172 if (data->ioc_flags)
1173 rc = izo_revoke_permit(file->f_dentry, data->ioc_uuid);
1175 rc = izo_revoke_permit(file->f_dentry, NULL);
1179 case IZO_IOC_CLEAR_FSET:
1180 rc = izo_clear_fsetroot(file->f_dentry);
1184 case IZO_IOC_CLEAR_ALL_FSETS: {
1185 struct presto_file_set *fset;
1187 fset = presto_fset(file->f_dentry);
1193 rc = izo_clear_all_fsetroots(fset->fset_cache);
1198 case IZO_IOC_SET_FSET:
1200 * Mark this dentry as being a fileset root.
1202 rc = presto_set_fsetroot_from_ioc(file->f_dentry,
1209 case IZO_IOC_MARK: {
1210 int res = 0; /* resulting flags - returned to user */
1213 CDEBUG(D_DOWNCALL, "mark inode: %ld, and: %x, or: %x, what %d\n",
1214 file->f_dentry->d_inode->i_ino, data->ioc_and_flag,
1215 data->ioc_or_flag, data->ioc_mark_what);
1217 switch (data->ioc_mark_what) {
1219 error = izo_mark_dentry(file->f_dentry,
1221 data->ioc_or_flag, &res);
1224 error = izo_mark_fset(file->f_dentry,
1226 data->ioc_or_flag, &res);
1229 error = izo_mark_cache(file->f_dentry,
1231 data->ioc_or_flag, &res);
1235 data->ioc_and_flag = 0xffffffff;
1236 data->ioc_or_flag = 0;
1237 error = izo_mark_dentry(file->f_dentry,
1239 data->ioc_or_flag, &res);
1242 error = izo_mark_fset(file->f_dentry,
1244 data->ioc_or_flag, &fflags);
1247 error = izo_mark_cache(file->f_dentry,
1254 data->ioc_and_flag = fflags;
1255 data->ioc_or_flag = cflags;
1266 data->ioc_mark_what = res;
1267 CDEBUG(D_DOWNCALL, "mark inode: %ld, and: %x, or: %x, what %x\n",
1268 file->f_dentry->d_inode->i_ino, data->ioc_and_flag,
1269 data->ioc_or_flag, data->ioc_mark_what);
1272 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1275 case IZO_IOC_CLIENT_MAKE_BRANCH: {
1276 struct presto_file_set *fset;
1279 fset = presto_fset(file->f_dentry);
1284 minor = presto_f2m(fset);
1286 rc = izo_upc_client_make_branch(minor, fset->fset_name,
1293 case IZO_IOC_SERVER_MAKE_BRANCH: {
1294 struct presto_file_set *fset;
1297 fset = presto_fset(file->f_dentry);
1302 minor = presto_f2m(fset);
1304 izo_upc_server_make_branch(minor, data->ioc_inlbuf1);
1308 case IZO_IOC_SET_KMLSIZE: {
1309 struct presto_file_set *fset;
1311 struct izo_rcvd_rec rec;
1313 fset = presto_fset(file->f_dentry);
1318 minor = presto_f2m(fset);
1320 rc = izo_upc_set_kmlsize(minor, fset->fset_name, data->ioc_uuid,
1328 rc = izo_rcvd_get(&rec, fset, data->ioc_uuid);
1329 if (rc == -EINVAL) {
1330 /* We don't know anything about this uuid yet; no
1332 memset(&rec, 0, sizeof(rec));
1333 } else if (rc <= 0) {
1334 CERROR("InterMezzo: error reading last_rcvd: %d\n", rc);
1338 rec.lr_remote_offset = data->ioc_kmlsize;
1339 rc = izo_rcvd_write(fset, &rec);
1341 CERROR("InterMezzo: error writing last_rcvd: %d\n", rc);
1348 case IZO_IOC_BRANCH_UNDO: {
1349 struct presto_file_set *fset;
1352 fset = presto_fset(file->f_dentry);
1357 minor = presto_f2m(fset);
1359 rc = izo_upc_branch_undo(minor, fset->fset_name,
1364 case IZO_IOC_BRANCH_REDO: {
1365 struct presto_file_set *fset;
1368 fset = presto_fset(file->f_dentry);
1373 minor = presto_f2m(fset);
1375 rc = izo_upc_branch_redo(minor, fset->fset_name,
1394 struct file_operations presto_dir_fops = {
1395 .ioctl = presto_ioctl
1398 struct inode_operations presto_dir_iops = {
1399 .create = presto_create,
1400 .lookup = presto_lookup,
1401 .link = presto_link,
1402 .unlink = presto_unlink,
1403 .symlink = presto_symlink,
1404 .mkdir = presto_mkdir,
1405 .rmdir = presto_rmdir,
1406 .mknod = presto_mknod,
1407 .rename = presto_rename,
1408 .permission = presto_permission,
1409 .setattr = presto_setattr,
1410 #ifdef CONFIG_FS_EXT_ATTR
1411 .set_ext_attr = presto_set_ext_attr,