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);
303 /* dentry->d_op is now hooked in dcache.c:presto_set_dd */
305 /* In lookup we will tolerate EROFS return codes from presto_set_dd
306 * to placate NFS. EROFS indicates that a fileset was not found but
307 * we should still be able to continue through a lookup.
308 * Anything else is a hard error and must be returned to VFS. */
310 rc = presto_set_dd(dentry);
311 if (rc && rc != -EROFS) {
312 CERROR("presto_set_dd failed (dir %ld, name %*s): %d\n",
313 dir->i_ino, dentry->d_name.len, dentry->d_name.name, rc);
321 static inline int presto_check_set_fsdata (struct dentry *de)
323 if (presto_d2d(de) == NULL) {
325 CERROR("dentry without fsdata: %p: %*s\n", de,
326 de->d_name.len, de->d_name.name);
329 return presto_set_dd (de);
335 int presto_setattr(struct dentry *de, struct iattr *iattr)
338 struct presto_cache *cache;
339 struct presto_file_set *fset;
340 struct lento_vfs_context info = { 0, 0, 0 };
344 error = presto_prep(de, &cache, &fset);
350 if (!iattr->ia_valid)
351 CDEBUG(D_INODE, "presto_setattr: iattr is not valid\n");
353 CDEBUG(D_INODE, "valid %#x, mode %#o, uid %u, gid %u, size %Lu, "
354 "atime %lu mtime %lu ctime %lu flags %d\n",
355 iattr->ia_valid, iattr->ia_mode, iattr->ia_uid, iattr->ia_gid,
356 iattr->ia_size, iattr->ia_atime, iattr->ia_mtime,
357 iattr->ia_ctime, iattr->ia_attr_flags);
359 if ( presto_get_permit(de->d_inode) < 0 ) {
364 if (!ISLENTO(presto_c2m(cache)))
365 info.flags = LENTO_FL_KML;
366 info.flags |= LENTO_FL_IGNORE_TIME;
367 error = presto_do_setattr(fset, de, iattr, &info);
368 presto_put_permit(de->d_inode);
373 * Now the meat: the fs operations that require journaling
376 * XXX: some of these need modifications for hierarchical filesets
379 int presto_prep(struct dentry *dentry, struct presto_cache **cache,
380 struct presto_file_set **fset)
384 /* NFS might pass us dentries which have not gone through lookup.
385 * Test and set d_fsdata for such dentries
387 rc = presto_check_set_fsdata (dentry);
390 *fset = presto_fset(dentry);
391 if ( *fset == NULL ) {
392 CERROR("No file set for dentry at %p: %*s\n", dentry,
393 dentry->d_name.len, dentry->d_name.name);
397 *cache = (*fset)->fset_cache;
398 if ( *cache == NULL ) {
399 CERROR("PRESTO: BAD, BAD: cannot find cache\n");
403 CDEBUG(D_PIOCTL, "---> cache flags %x, fset flags %x\n",
404 (*cache)->cache_flags, (*fset)->fset_flags);
405 if( presto_is_read_only(*fset) ) {
406 CERROR("PRESTO: cannot modify read-only fileset, minor %d.\n",
413 static int presto_create(struct inode * dir, struct dentry * dentry, int mode)
416 struct presto_cache *cache;
417 struct dentry *parent = dentry->d_parent;
418 struct lento_vfs_context info;
419 struct presto_file_set *fset;
422 error = presto_check_set_fsdata(dentry);
428 error = presto_prep(dentry->d_parent, &cache, &fset);
435 /* Does blocking and non-blocking behavious need to be
436 checked for. Without blocking (return 1), the permit
437 was acquired without reintegration
439 if ( presto_get_permit(dir) < 0 ) {
441 presto_fulllock(dir);
445 presto_relock_sem(dir);
446 parent = dentry->d_parent;
447 memset(&info, 0, sizeof(info));
448 if (!ISLENTO(presto_c2m(cache)))
449 info.flags = LENTO_FL_KML;
450 info.flags |= LENTO_FL_IGNORE_TIME;
451 error = presto_do_create(fset, parent, dentry, mode, &info);
453 presto_relock_other(dir);
454 presto_put_permit(dir);
459 static int presto_link(struct dentry *old_dentry, struct inode *dir,
460 struct dentry *new_dentry)
463 struct presto_cache *cache, *new_cache;
464 struct presto_file_set *fset, *new_fset;
465 struct dentry *parent = new_dentry->d_parent;
466 struct lento_vfs_context info;
469 error = presto_prep(old_dentry, &cache, &fset);
475 error = presto_check_set_fsdata(new_dentry);
481 error = presto_prep(new_dentry->d_parent, &new_cache, &new_fset);
487 if (fset != new_fset) {
493 if ( presto_get_permit(old_dentry->d_inode) < 0 ) {
495 presto_fulllock(dir);
499 if ( presto_get_permit(dir) < 0 ) {
501 presto_fulllock(dir);
505 presto_relock_sem(dir);
506 parent = new_dentry->d_parent;
508 memset(&info, 0, sizeof(info));
509 if (!ISLENTO(presto_c2m(cache)))
510 info.flags = LENTO_FL_KML;
511 info.flags |= LENTO_FL_IGNORE_TIME;
512 error = presto_do_link(fset, old_dentry, parent,
516 /* XXX for links this is not right */
517 if (cache->cache_filter->o_trops->tr_add_ilookup ) {
519 d = cache->cache_filter->o_trops->tr_add_ilookup
520 (dir->i_sb->s_root, new_dentry, 1);
524 presto_relock_other(dir);
525 presto_put_permit(dir);
526 presto_put_permit(old_dentry->d_inode);
530 static int presto_mkdir(struct inode * dir, struct dentry * dentry, int mode)
533 struct presto_file_set *fset;
534 struct presto_cache *cache;
535 struct dentry *parent = dentry->d_parent;
536 struct lento_vfs_context info;
540 error = presto_check_set_fsdata(dentry);
546 error = presto_prep(dentry->d_parent, &cache, &fset);
554 if ( presto_get_permit(dir) < 0 ) {
556 presto_fulllock(dir);
560 memset(&info, 0, sizeof(info));
561 if (!ISLENTO(presto_c2m(cache)))
562 info.flags = LENTO_FL_KML;
563 info.flags |= LENTO_FL_IGNORE_TIME;
565 presto_relock_sem(dir);
566 parent = dentry->d_parent;
567 error = presto_do_mkdir(fset, parent, dentry, mode, &info);
568 presto_relock_other(dir);
569 presto_put_permit(dir);
575 static int presto_symlink(struct inode *dir, struct dentry *dentry,
579 struct presto_cache *cache;
580 struct presto_file_set *fset;
581 struct dentry *parent = dentry->d_parent;
582 struct lento_vfs_context info;
585 error = presto_check_set_fsdata(dentry);
591 error = presto_prep(dentry->d_parent, &cache, &fset);
598 if ( presto_get_permit(dir) < 0 ) {
600 presto_fulllock(dir);
604 presto_relock_sem(dir);
605 parent = dentry->d_parent;
606 memset(&info, 0, sizeof(info));
607 if (!ISLENTO(presto_c2m(cache)))
608 info.flags = LENTO_FL_KML;
609 info.flags |= LENTO_FL_IGNORE_TIME;
610 error = presto_do_symlink(fset, parent, dentry, name, &info);
611 presto_relock_other(dir);
612 presto_put_permit(dir);
616 int presto_unlink(struct inode *dir, struct dentry *dentry)
619 struct presto_cache *cache;
620 struct presto_file_set *fset;
621 struct dentry *parent = dentry->d_parent;
622 struct lento_vfs_context info;
625 error = presto_check_set_fsdata(dentry);
631 error = presto_prep(dentry->d_parent, &cache, &fset);
638 if ( presto_get_permit(dir) < 0 ) {
640 presto_fulllock(dir);
644 presto_relock_sem(dir);
645 parent = dentry->d_parent;
646 memset(&info, 0, sizeof(info));
647 if (!ISLENTO(presto_c2m(cache)))
648 info.flags = LENTO_FL_KML;
649 info.flags |= LENTO_FL_IGNORE_TIME;
651 error = presto_do_unlink(fset, parent, dentry, &info);
653 presto_relock_other(dir);
654 presto_put_permit(dir);
658 static int presto_rmdir(struct inode *dir, struct dentry *dentry)
661 struct presto_cache *cache;
662 struct presto_file_set *fset;
663 struct dentry *parent = dentry->d_parent;
664 struct lento_vfs_context info;
667 CDEBUG(D_FILE, "prepping presto\n");
668 error = presto_check_set_fsdata(dentry);
675 error = presto_prep(dentry->d_parent, &cache, &fset);
681 CDEBUG(D_FILE, "unlocking\n");
682 /* We need to dget() before the dput in double_unlock, to ensure we
683 * still have dentry references. double_lock doesn't do dget for us.
686 if (d_unhashed(dentry))
688 double_up(&dir->i_zombie, &dentry->d_inode->i_zombie);
689 double_up(&dir->i_sem, &dentry->d_inode->i_sem);
691 CDEBUG(D_FILE, "getting permit\n");
692 if ( presto_get_permit(parent->d_inode) < 0 ) {
694 double_down(&dir->i_sem, &dentry->d_inode->i_sem);
695 double_down(&dir->i_zombie, &dentry->d_inode->i_zombie);
700 CDEBUG(D_FILE, "locking\n");
702 double_down(&dir->i_sem, &dentry->d_inode->i_sem);
703 parent = dentry->d_parent;
704 memset(&info, 0, sizeof(info));
705 if (!ISLENTO(presto_c2m(cache)))
706 info.flags = LENTO_FL_KML;
707 info.flags |= LENTO_FL_IGNORE_TIME;
708 error = presto_do_rmdir(fset, parent, dentry, &info);
709 presto_put_permit(parent->d_inode);
715 static int presto_mknod(struct inode * dir, struct dentry * dentry, int mode, int rdev)
718 struct presto_cache *cache;
719 struct presto_file_set *fset;
720 struct dentry *parent = dentry->d_parent;
721 struct lento_vfs_context info;
724 error = presto_check_set_fsdata(dentry);
730 error = presto_prep(dentry->d_parent, &cache, &fset);
737 if ( presto_get_permit(dir) < 0 ) {
739 presto_fulllock(dir);
743 presto_relock_sem(dir);
744 parent = dentry->d_parent;
745 memset(&info, 0, sizeof(info));
746 if (!ISLENTO(presto_c2m(cache)))
747 info.flags = LENTO_FL_KML;
748 info.flags |= LENTO_FL_IGNORE_TIME;
749 error = presto_do_mknod(fset, parent, dentry, mode, rdev, &info);
750 presto_relock_other(dir);
751 presto_put_permit(dir);
756 inline void presto_triple_unlock(struct inode *old_dir, struct inode *new_dir,
757 struct dentry *old_dentry,
758 struct dentry *new_dentry, int triple)
760 /* rename_dir case */
761 if (S_ISDIR(old_dentry->d_inode->i_mode)) {
763 triple_up(&old_dir->i_zombie,
765 &new_dentry->d_inode->i_zombie);
767 double_up(&old_dir->i_zombie,
770 up(&old_dir->i_sb->s_vfs_rename_sem);
771 } else /* this case is rename_other */
772 double_up(&old_dir->i_zombie, &new_dir->i_zombie);
773 /* done by do_rename */
775 double_up(&old_dir->i_sem, &new_dir->i_sem);
778 inline void presto_triple_fulllock(struct inode *old_dir,
779 struct inode *new_dir,
780 struct dentry *old_dentry,
781 struct dentry *new_dentry, int triple)
783 /* done by do_rename */
784 double_down(&old_dir->i_sem, &new_dir->i_sem);
786 /* rename_dir case */
787 if (S_ISDIR(old_dentry->d_inode->i_mode)) {
788 down(&old_dir->i_sb->s_vfs_rename_sem);
790 triple_down(&old_dir->i_zombie,
792 &new_dentry->d_inode->i_zombie);
794 double_down(&old_dir->i_zombie,
797 } else /* this case is rename_other */
798 double_down(&old_dir->i_zombie, &new_dir->i_zombie);
801 inline void presto_triple_relock_sem(struct inode *old_dir,
802 struct inode *new_dir,
803 struct dentry *old_dentry,
804 struct dentry *new_dentry, int triple)
806 /* done by do_rename */
807 double_down(&old_dir->i_sem, &new_dir->i_sem);
811 inline void presto_triple_relock_other(struct inode *old_dir,
812 struct inode *new_dir,
813 struct dentry *old_dentry,
814 struct dentry *new_dentry, int triple)
816 /* rename_dir case */
817 if (S_ISDIR(old_dentry->d_inode->i_mode)) {
818 down(&old_dir->i_sb->s_vfs_rename_sem);
820 triple_down(&old_dir->i_zombie,
822 &new_dentry->d_inode->i_zombie);
824 double_down(&old_dir->i_zombie,
827 } else /* this case is rename_other */
828 double_down(&old_dir->i_zombie, &new_dir->i_zombie);
832 // XXX this can be optimized: renamtes across filesets only require
833 // multiple KML records, but can locally be executed normally.
834 int presto_rename(struct inode *old_dir, struct dentry *old_dentry,
835 struct inode *new_dir, struct dentry *new_dentry)
838 struct presto_cache *cache, *new_cache;
839 struct presto_file_set *fset, *new_fset;
840 struct lento_vfs_context info;
841 struct dentry *old_parent = old_dentry->d_parent;
842 struct dentry *new_parent = new_dentry->d_parent;
846 error = presto_prep(old_dentry, &cache, &fset);
851 error = presto_prep(new_parent, &new_cache, &new_fset);
857 if ( fset != new_fset ) {
862 /* We need to do dget before the dput in double_unlock, to ensure we
863 * still have dentry references. double_lock doesn't do dget for us.
866 triple = (S_ISDIR(old_dentry->d_inode->i_mode) && new_dentry->d_inode)?
869 presto_triple_unlock(old_dir, new_dir, old_dentry, new_dentry, triple);
871 if ( presto_get_permit(old_dir) < 0 ) {
873 presto_triple_fulllock(old_dir, new_dir, old_dentry, new_dentry, triple);
876 if ( presto_get_permit(new_dir) < 0 ) {
878 presto_triple_fulllock(old_dir, new_dir, old_dentry, new_dentry, triple);
882 presto_triple_relock_sem(old_dir, new_dir, old_dentry, new_dentry, triple);
883 memset(&info, 0, sizeof(info));
884 if (!ISLENTO(presto_c2m(cache)))
885 info.flags = LENTO_FL_KML;
886 info.flags |= LENTO_FL_IGNORE_TIME;
887 error = do_rename(fset, old_parent, old_dentry, new_parent,
889 presto_triple_relock_other(old_dir, new_dir, old_dentry, new_dentry, triple);
891 presto_put_permit(new_dir);
892 presto_put_permit(old_dir);
896 /* basically this allows the ilookup processes access to all files for
897 * reading, while not making ilookup totally insecure. This could all
898 * go away if we could set the CAP_DAC_READ_SEARCH capability for the client.
900 /* If posix acls are available, the underlying cache fs will export the
901 * appropriate permission function. Thus we do not worry here about ACLs
904 int presto_permission(struct inode *inode, int mask)
906 unsigned short mode = inode->i_mode;
907 struct presto_cache *cache;
911 if ( presto_can_ilookup() && !(mask & S_IWOTH)) {
912 CDEBUG(D_CACHE, "ilookup on %ld OK\n", inode->i_ino);
917 cache = presto_get_cache(inode);
920 /* we only override the file/dir permission operations */
921 struct inode_operations *fiops = filter_c2cfiops(cache->cache_filter);
922 struct inode_operations *diops = filter_c2cdiops(cache->cache_filter);
924 if ( S_ISREG(mode) && fiops && fiops->permission ) {
926 return fiops->permission(inode, mask);
928 if ( S_ISDIR(mode) && diops && diops->permission ) {
930 return diops->permission(inode, mask);
934 /* The cache filesystem doesn't have its own permission function,
935 * but we don't want to duplicate the VFS code here. In order
936 * to avoid looping from permission calling this function again,
937 * we temporarily override the permission operation while we call
938 * the VFS permission function.
940 inode->i_op->permission = NULL;
941 rc = permission(inode, mask);
942 inode->i_op->permission = &presto_permission;
949 int presto_ioctl(struct inode *inode, struct file *file,
950 unsigned int cmd, unsigned long arg)
953 struct izo_ioctl_data *data = NULL;
954 struct presto_dentry_data *dd;
959 /* Try the filesystem's ioctl first, and return if it succeeded. */
960 dd = presto_d2d(file->f_dentry);
961 if (dd && dd->dd_fset) {
962 int (*cache_ioctl)(struct inode *, struct file *, unsigned int, unsigned long ) = filter_c2cdfops(dd->dd_fset->fset_cache->cache_filter)->ioctl;
965 rc = cache_ioctl(inode, file, cmd, arg);
972 if (current->euid != 0 && current->euid != izo_authorized_uid) {
977 memset(buf, 0, sizeof(buf));
979 if (izo_ioctl_getdata(buf, buf + 1024, (void *)arg)) {
980 CERROR("intermezzo ioctl: data error\n");
983 data = (struct izo_ioctl_data *)buf;
986 case IZO_IOC_REINTKML: {
989 rc = kml_reint_rec(file, data);
992 cperr = copy_to_user((char *)arg, data, sizeof(*data));
994 CERROR("WARNING: cperr %d\n", cperr);
1000 case IZO_IOC_GET_RCVD: {
1001 struct izo_rcvd_rec rec;
1002 struct presto_file_set *fset;
1005 fset = presto_fset(file->f_dentry);
1010 rc = izo_rcvd_get(&rec, fset, data->ioc_uuid);
1017 return copy_to_user((char *)arg, &rec, sizeof(rec))? -EFAULT : 0;
1020 case IZO_IOC_REPSTATUS: {
1021 __u64 client_kmlsize;
1022 struct izo_rcvd_rec *lr_client;
1023 struct izo_rcvd_rec rec;
1024 struct presto_file_set *fset;
1028 fset = presto_fset(file->f_dentry);
1033 minor = presto_f2m(fset);
1035 client_kmlsize = data->ioc_kmlsize;
1036 lr_client = (struct izo_rcvd_rec *) data->ioc_pbuf1;
1038 rc = izo_repstatus(fset, client_kmlsize,
1046 return copy_to_user((char *)arg, &rec, sizeof(rec))? -EFAULT : 0;
1049 case IZO_IOC_GET_CHANNEL: {
1050 struct presto_file_set *fset;
1052 fset = presto_fset(file->f_dentry);
1058 data->ioc_dev = fset->fset_cache->cache_psdev->uc_minor;
1059 CDEBUG(D_PSDEV, "CHANNEL %d\n", data->ioc_dev);
1061 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1064 case IZO_IOC_SET_IOCTL_UID:
1065 izo_authorized_uid = data->ioc_uid;
1069 case IZO_IOC_SET_PID:
1070 rc = izo_psdev_setpid(data->ioc_dev);
1074 case IZO_IOC_SET_CHANNEL:
1075 rc = izo_psdev_setchannel(file, data->ioc_dev);
1079 case IZO_IOC_GET_KML_SIZE: {
1080 struct presto_file_set *fset;
1083 fset = presto_fset(file->f_dentry);
1089 kmlsize = presto_kml_offset(fset) + fset->fset_kml_logical_off;
1092 return copy_to_user((char *)arg, &kmlsize, sizeof(kmlsize))?-EFAULT : 0;
1095 case IZO_IOC_PURGE_FILE_DATA: {
1096 struct presto_file_set *fset;
1098 fset = presto_fset(file->f_dentry);
1104 rc = izo_purge_file(fset, data->ioc_inlbuf1);
1109 case IZO_IOC_GET_FILEID: {
1110 rc = izo_get_fileid(file, data);
1114 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1117 case IZO_IOC_SET_FILEID: {
1118 rc = izo_set_fileid(file, data);
1122 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1125 case IZO_IOC_ADJUST_LML: {
1126 struct lento_vfs_context *info;
1127 info = (struct lento_vfs_context *)data->ioc_inlbuf1;
1128 rc = presto_adjust_lml(file, info);
1133 case IZO_IOC_CONNECT: {
1134 struct presto_file_set *fset;
1137 fset = presto_fset(file->f_dentry);
1142 minor = presto_f2m(fset);
1144 rc = izo_upc_connect(minor, data->ioc_ino,
1145 data->ioc_generation, data->ioc_uuid,
1151 case IZO_IOC_GO_FETCH_KML: {
1152 struct presto_file_set *fset;
1155 fset = presto_fset(file->f_dentry);
1160 minor = presto_f2m(fset);
1162 rc = izo_upc_go_fetch_kml(minor, fset->fset_name,
1163 data->ioc_uuid, data->ioc_kmlsize);
1168 case IZO_IOC_REVOKE_PERMIT:
1169 if (data->ioc_flags)
1170 rc = izo_revoke_permit(file->f_dentry, data->ioc_uuid);
1172 rc = izo_revoke_permit(file->f_dentry, NULL);
1176 case IZO_IOC_CLEAR_FSET:
1177 rc = izo_clear_fsetroot(file->f_dentry);
1181 case IZO_IOC_CLEAR_ALL_FSETS: {
1182 struct presto_file_set *fset;
1184 fset = presto_fset(file->f_dentry);
1190 rc = izo_clear_all_fsetroots(fset->fset_cache);
1195 case IZO_IOC_SET_FSET:
1197 * Mark this dentry as being a fileset root.
1199 rc = presto_set_fsetroot_from_ioc(file->f_dentry,
1206 case IZO_IOC_MARK: {
1207 int res = 0; /* resulting flags - returned to user */
1210 CDEBUG(D_DOWNCALL, "mark inode: %ld, and: %x, or: %x, what %d\n",
1211 file->f_dentry->d_inode->i_ino, data->ioc_and_flag,
1212 data->ioc_or_flag, data->ioc_mark_what);
1214 switch (data->ioc_mark_what) {
1216 error = izo_mark_dentry(file->f_dentry,
1218 data->ioc_or_flag, &res);
1221 error = izo_mark_fset(file->f_dentry,
1223 data->ioc_or_flag, &res);
1226 error = izo_mark_cache(file->f_dentry,
1228 data->ioc_or_flag, &res);
1232 data->ioc_and_flag = 0xffffffff;
1233 data->ioc_or_flag = 0;
1234 error = izo_mark_dentry(file->f_dentry,
1236 data->ioc_or_flag, &res);
1239 error = izo_mark_fset(file->f_dentry,
1241 data->ioc_or_flag, &fflags);
1244 error = izo_mark_cache(file->f_dentry,
1251 data->ioc_and_flag = fflags;
1252 data->ioc_or_flag = cflags;
1263 data->ioc_mark_what = res;
1264 CDEBUG(D_DOWNCALL, "mark inode: %ld, and: %x, or: %x, what %x\n",
1265 file->f_dentry->d_inode->i_ino, data->ioc_and_flag,
1266 data->ioc_or_flag, data->ioc_mark_what);
1269 return copy_to_user((char *)arg, data, sizeof(*data))? -EFAULT : 0;
1272 case IZO_IOC_CLIENT_MAKE_BRANCH: {
1273 struct presto_file_set *fset;
1276 fset = presto_fset(file->f_dentry);
1281 minor = presto_f2m(fset);
1283 rc = izo_upc_client_make_branch(minor, fset->fset_name,
1290 case IZO_IOC_SERVER_MAKE_BRANCH: {
1291 struct presto_file_set *fset;
1294 fset = presto_fset(file->f_dentry);
1299 minor = presto_f2m(fset);
1301 izo_upc_server_make_branch(minor, data->ioc_inlbuf1);
1305 case IZO_IOC_SET_KMLSIZE: {
1306 struct presto_file_set *fset;
1308 struct izo_rcvd_rec rec;
1310 fset = presto_fset(file->f_dentry);
1315 minor = presto_f2m(fset);
1317 rc = izo_upc_set_kmlsize(minor, fset->fset_name, data->ioc_uuid,
1325 rc = izo_rcvd_get(&rec, fset, data->ioc_uuid);
1326 if (rc == -EINVAL) {
1327 /* We don't know anything about this uuid yet; no
1329 memset(&rec, 0, sizeof(rec));
1330 } else if (rc <= 0) {
1331 CERROR("InterMezzo: error reading last_rcvd: %d\n", rc);
1335 rec.lr_remote_offset = data->ioc_kmlsize;
1336 rc = izo_rcvd_write(fset, &rec);
1338 CERROR("InterMezzo: error writing last_rcvd: %d\n", rc);
1345 case IZO_IOC_BRANCH_UNDO: {
1346 struct presto_file_set *fset;
1349 fset = presto_fset(file->f_dentry);
1354 minor = presto_f2m(fset);
1356 rc = izo_upc_branch_undo(minor, fset->fset_name,
1361 case IZO_IOC_BRANCH_REDO: {
1362 struct presto_file_set *fset;
1365 fset = presto_fset(file->f_dentry);
1370 minor = presto_f2m(fset);
1372 rc = izo_upc_branch_redo(minor, fset->fset_name,
1391 struct file_operations presto_dir_fops = {
1392 .ioctl = presto_ioctl
1395 struct inode_operations presto_dir_iops = {
1396 .create = presto_create,
1397 .lookup = presto_lookup,
1398 .link = presto_link,
1399 .unlink = presto_unlink,
1400 .symlink = presto_symlink,
1401 .mkdir = presto_mkdir,
1402 .rmdir = presto_rmdir,
1403 .mknod = presto_mknod,
1404 .rename = presto_rename,
1405 .permission = presto_permission,
1406 .setattr = presto_setattr,
1407 #ifdef CONFIG_FS_EXT_ATTR
1408 .set_ext_attr = presto_set_ext_attr,