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) 2000 Stelias Computing, Inc.
6 * Copyright (C) 2000 Red Hat, Inc.
8 * This file is part of InterMezzo, http://www.inter-mezzo.org.
10 * InterMezzo is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * InterMezzo is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with InterMezzo; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * This file implements kernel downcalls from lento.
27 * Author: Rob Simmonds <simmonds@stelias.com>
28 * Andreas Dilger <adilger@stelias.com>
29 * Copyright (C) 2000 Stelias Computing Inc
30 * Copyright (C) 2000 Red Hat Inc.
32 * Extended attribute support
33 * Copyright (C) 2001 Shirish H. Phatak, Tacit Networks, Inc.
35 * This code is based on code from namei.c in the linux file system;
36 * see copyright notice below.
39 /** namei.c copyright **/
44 * Copyright (C) 1991, 1992 Linus Torvalds
47 * Some corrections by tytso.
50 /* [Feb 1997 T. Schoebel-Theuer] Complete rewrite of the pathname
54 /** end of namei.c copyright **/
57 #include <linux/proc_fs.h>
58 #include <linux/smp_lock.h>
59 #include <linux/quotaops.h>
61 #include <asm/uaccess.h>
62 #include <asm/unaligned.h>
63 #include <asm/semaphore.h>
64 #include <asm/pgtable.h>
66 #include <linux/file.h>
68 #include <linux/namei.h>
69 #include <linux/blk.h>
71 #include <linux/intermezzo_fs.h>
72 #include <linux/intermezzo_psdev.h>
74 #ifdef CONFIG_FS_EXT_ATTR
75 # include <linux/ext_attr.h>
77 # if 0 /* was a broken check for Posix ACLs */
78 # include <linux/posix_acl.h>
82 extern struct inode_operations presto_sym_iops
;
84 /* Write the last_rcvd values to the last_rcvd file. We don't know what the
85 * UUID or last_ctime values are, so we have to read from the file first
87 * exported for branch_reinter in kml_reint.c*/
88 int presto_write_last_rcvd(struct rec_info
*recinfo
,
89 struct presto_file_set
*fset
,
90 struct lento_vfs_context
*info
)
93 struct izo_rcvd_rec rcvd_rec
;
97 memset(&rcvd_rec
, 0, sizeof(rcvd_rec
));
98 memcpy(rcvd_rec
.lr_uuid
, info
->uuid
, sizeof(rcvd_rec
.lr_uuid
));
99 rcvd_rec
.lr_remote_recno
= HTON__u64(info
->recno
);
100 rcvd_rec
.lr_remote_offset
= HTON__u64(info
->kml_offset
);
101 rcvd_rec
.lr_local_recno
= HTON__u64(recinfo
->recno
);
102 rcvd_rec
.lr_local_offset
= HTON__u64(recinfo
->offset
+ recinfo
->size
);
104 rc
= izo_rcvd_write(fset
, &rcvd_rec
);
106 /* izo_rcvd_write returns negative errors and non-negative
108 CERROR("InterMezzo: izo_rcvd_write failed: %d\n", rc
);
117 * It's inline, so penalty for filesystems that don't use sticky bit is
120 static inline int check_sticky(struct inode
*dir
, struct inode
*inode
)
122 if (!(dir
->i_mode
& S_ISVTX
))
124 if (inode
->i_uid
== current
->fsuid
)
126 if (dir
->i_uid
== current
->fsuid
)
128 return !capable(CAP_FOWNER
);
131 /* from linux/fs/namei.c */
132 static inline int may_delete(struct inode
*dir
,struct dentry
*victim
, int isdir
)
135 if (!victim
->d_inode
|| victim
->d_parent
->d_inode
!= dir
)
137 error
= permission(dir
,MAY_WRITE
| MAY_EXEC
);
142 if (check_sticky(dir
, victim
->d_inode
)||IS_APPEND(victim
->d_inode
)||
143 IS_IMMUTABLE(victim
->d_inode
))
146 if (!S_ISDIR(victim
->d_inode
->i_mode
))
150 } else if (S_ISDIR(victim
->d_inode
->i_mode
))
155 /* from linux/fs/namei.c */
156 static inline int may_create(struct inode
*dir
, struct dentry
*child
) {
161 return permission(dir
,MAY_WRITE
| MAY_EXEC
);
165 /* The loop_discard_io() function is available via a kernel patch to the
166 * loop block device. It "works" by accepting writes, but throwing them
167 * away, rather than trying to write them to disk. The old method worked
168 * by setting the underlying device read-only, but that has the problem
169 * that dirty buffers are kept in memory, and ext3 didn't like that at all.
171 #ifdef CONFIG_LOOP_DISCARD
172 #define BLKDEV_FAIL(dev,fail) loop_discard_io(dev,fail)
174 #define BLKDEV_FAIL(dev,fail) set_device_ro(dev, 1)
177 /* If a breakpoint has been set via /proc/sys/intermezzo/intermezzoX/errorval,
178 * that is the same as "value", the underlying device will "fail" now.
180 inline void presto_debug_fail_blkdev(struct presto_file_set
*fset
,
183 int minor
= presto_f2m(fset
);
184 int errorval
= izo_channels
[minor
].uc_errorval
;
185 kdev_t dev
= to_kdev_t(fset
->fset_dentry
->d_inode
->i_dev
);
187 if (errorval
&& errorval
== (long)value
&& !is_read_only(dev
)) {
188 CDEBUG(D_SUPER
, "setting device %s read only\n", kdevname(dev
));
190 izo_channels
[minor
].uc_errorval
= -kdev_val(dev
);
194 #define presto_debug_fail_blkdev(dev,value) do {} while (0)
198 static inline int presto_do_kml(struct lento_vfs_context
*info
,
199 struct dentry
*dentry
)
201 if ( ! (info
->flags
& LENTO_FL_KML
) )
203 if ( presto_chk(dentry
, PRESTO_DONT_JOURNAL
) )
208 static inline int presto_do_rcvd(struct lento_vfs_context
*info
,
209 struct dentry
*dentry
)
211 if ( ! (info
->flags
& LENTO_FL_EXPECT
) )
213 if ( presto_chk(dentry
, PRESTO_DONT_JOURNAL
) )
219 /* XXX fixme: this should not fail, all these dentries are in memory
220 when _we_ call this */
221 int presto_settime(struct presto_file_set
*fset
,
222 struct dentry
*newobj
,
223 struct dentry
*parent
,
224 struct dentry
*target
,
225 struct lento_vfs_context
*ctx
,
229 struct dentry
*dentry
;
231 struct inode_operations
*iops
;
235 if (ctx
->flags
& LENTO_FL_IGNORE_TIME
) {
240 iattr
.ia_ctime
= ctx
->updated_time
;
241 iattr
.ia_mtime
= ctx
->updated_time
;
242 iattr
.ia_valid
= valid
;
245 if (parent
&& ctx
->flags
& LENTO_FL_TOUCH_PARENT
) {
248 } else if (newobj
&& ctx
->flags
& LENTO_FL_TOUCH_NEWOBJ
) {
257 inode
= dentry
->d_inode
;
260 if (IS_RDONLY(inode
)) {
265 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
)) {
271 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
277 if (iops
->setattr
!= NULL
)
278 error
= iops
->setattr(dentry
, &iattr
);
281 inode_setattr(dentry
->d_inode
, &iattr
);
288 void izo_get_rollback_data(struct inode
*inode
, struct izo_rollback_data
*rb
)
290 rb
->rb_mode
= (__u32
)inode
->i_mode
;
291 rb
->rb_rdev
= (__u32
)kdev_t_to_nr(inode
->i_rdev
);
292 rb
->rb_uid
= (__u64
)inode
->i_uid
;
293 rb
->rb_gid
= (__u64
)inode
->i_gid
;
297 int presto_do_close(struct presto_file_set
*fset
, struct file
*file
)
302 struct inode
*inode
= file
->f_dentry
->d_inode
;
303 struct presto_file_data
*fdata
=
304 (struct presto_file_data
*)file
->private_data
;
307 presto_getversion(&fdata
->fd_info
.remote_version
, inode
);
309 rc
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
);
315 handle
= presto_trans_start(fset
, file
->f_dentry
->d_inode
,
317 if ( IS_ERR(handle
) ) {
318 CERROR("presto_release: no space for transaction\n");
322 if (fdata
->fd_info
.flags
& LENTO_FL_KML
)
323 rc
= presto_journal_close(&rec
, fset
, file
, file
->f_dentry
,
325 &fdata
->fd_info
.remote_version
);
327 CERROR("presto_close: cannot journal close\n");
331 if (fdata
->fd_info
.flags
& LENTO_FL_EXPECT
)
332 rc
= presto_write_last_rcvd(&rec
, fset
, &fdata
->fd_info
);
335 CERROR("presto_close: cannot journal last_rcvd\n");
338 presto_trans_commit(fset
, handle
);
340 /* cancel the LML record */
341 handle
= presto_trans_start(fset
, inode
, KML_OPCODE_WRITE
);
342 if ( IS_ERR(handle
) ) {
343 CERROR("presto_release: no space for clear\n");
347 rc
= presto_clear_lml_close(fset
, fdata
->fd_lml_offset
);
349 CERROR("presto_close: cannot journal close\n");
352 presto_truncate_lml(fset
);
355 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
356 presto_trans_commit(fset
, handle
);
361 int presto_do_setattr(struct presto_file_set
*fset
, struct dentry
*dentry
,
362 struct iattr
*iattr
, struct lento_vfs_context
*info
)
365 struct inode
*inode
= dentry
->d_inode
;
366 struct inode_operations
*iops
;
368 struct presto_version old_ver
, new_ver
;
369 struct izo_rollback_data rb
;
371 loff_t old_size
=inode
->i_size
;
375 if (IS_RDONLY(inode
)) {
380 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
)) {
385 presto_getversion(&old_ver
, dentry
->d_inode
);
386 izo_get_rollback_data(dentry
->d_inode
, &rb
);
388 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
390 error
= presto_reserve_space(fset
->fset_cache
, 2*PRESTO_REQHIGH
);
396 if (iattr
->ia_valid
& ATTR_SIZE
) {
397 if (izo_mark_dentry(dentry
, ~PRESTO_DATA
, 0, NULL
) != 0)
398 CERROR("izo_mark_dentry(inode %ld, ~PRESTO_DATA) "
399 "failed\n", dentry
->d_inode
->i_ino
);
400 handle
= presto_trans_start(fset
, dentry
->d_inode
,
403 handle
= presto_trans_start(fset
, dentry
->d_inode
,
407 if ( IS_ERR(handle
) ) {
408 CERROR("presto_do_setattr: no space for transaction\n");
409 presto_release_space(fset
->fset_cache
, 2*PRESTO_REQHIGH
);
413 if (dentry
->d_inode
&& iops
&& iops
->setattr
) {
414 error
= iops
->setattr(dentry
, iattr
);
416 error
= inode_change_ok(dentry
->d_inode
, iattr
);
418 inode_setattr(inode
, iattr
);
421 if (!error
&& (iattr
->ia_valid
& ATTR_SIZE
))
422 vmtruncate(inode
, iattr
->ia_size
);
429 presto_debug_fail_blkdev(fset
, KML_OPCODE_SETATTR
| 0x10);
431 if ( presto_do_kml(info
, dentry
) ) {
432 if ((iattr
->ia_valid
& ATTR_SIZE
) && (old_size
!= inode
->i_size
)) {
434 /* Journal a close whenever we see a potential truncate
435 * At the receiving end, lento should explicitly remove
436 * ATTR_SIZE from the list of valid attributes */
437 presto_getversion(&new_ver
, inode
);
438 file
.private_data
= NULL
;
439 file
.f_dentry
= dentry
;
440 error
= presto_journal_close(&rec
, fset
, &file
, dentry
,
445 error
= presto_journal_setattr(&rec
, fset
, dentry
,
446 &old_ver
, &rb
, iattr
);
449 presto_debug_fail_blkdev(fset
, KML_OPCODE_SETATTR
| 0x20);
450 if ( presto_do_rcvd(info
, dentry
) )
451 error
= presto_write_last_rcvd(&rec
, fset
, info
);
453 presto_debug_fail_blkdev(fset
, KML_OPCODE_SETATTR
| 0x30);
457 presto_release_space(fset
->fset_cache
, 2*PRESTO_REQHIGH
);
458 presto_trans_commit(fset
, handle
);
462 int lento_setattr(const char *name
, struct iattr
*iattr
,
463 struct lento_vfs_context
*info
)
466 struct dentry
*dentry
;
467 struct presto_file_set
*fset
;
469 #if 0 /* was a broken check for Posix ACLs */
470 int (*set_posix_acl
)(struct inode
*, int type
, posix_acl_t
*)=NULL
;
474 CDEBUG(D_PIOCTL
,"name %s, valid %#x, mode %#o, uid %d, gid %d, size %Ld\n",
475 name
, iattr
->ia_valid
, iattr
->ia_mode
, iattr
->ia_uid
,
476 iattr
->ia_gid
, iattr
->ia_size
);
477 CDEBUG(D_PIOCTL
, "atime %#lx, mtime %#lx, ctime %#lx, attr_flags %#x\n",
478 iattr
->ia_atime
, iattr
->ia_mtime
.tv_sec
, iattr
->ia_ctime
.tv_sec
,
479 iattr
->ia_attr_flags
);
480 CDEBUG(D_PIOCTL
, "offset %d, recno %d, flags %#x\n",
481 info
->slot_offset
, info
->recno
, info
->flags
);
484 error
= presto_walk(name
, &nd
);
491 fset
= presto_fset(dentry
);
494 CERROR("No fileset!\n");
499 /* NOTE: this prevents us from changing the filetype on setattr,
500 * as we normally only want to change permission bits.
501 * If this is not correct, then we need to fix the perl code
502 * to always send the file type OR'ed with the permission.
504 if (iattr
->ia_valid
& ATTR_MODE
) {
505 int set_mode
= iattr
->ia_mode
;
506 iattr
->ia_mode
= (iattr
->ia_mode
& S_IALLUGO
) |
507 (dentry
->d_inode
->i_mode
& ~S_IALLUGO
);
508 CDEBUG(D_PIOCTL
, "chmod: orig %#o, set %#o, result %#o\n",
509 dentry
->d_inode
->i_mode
, set_mode
, iattr
->ia_mode
);
510 #if 0 /* was a broken check for Posix ACLs */
511 /* ACl code interacts badly with setattr
512 * since it tries to modify the ACL using
513 * set_ext_attr which recurses back into presto.
514 * This only happens if ATTR_MODE is set.
515 * Here we are doing a "forced" mode set
516 * (initiated by lento), so we disable the
517 * set_posix_acl operation which
518 * prevents such recursion. -SHP
520 * This will probably still be required when native
521 * acl journalling is in place.
523 set_posix_acl
=dentry
->d_inode
->i_op
->set_posix_acl
;
524 dentry
->d_inode
->i_op
->set_posix_acl
=NULL
;
528 error
= presto_do_setattr(fset
, dentry
, iattr
, info
);
530 if (info
->flags
& LENTO_FL_SET_DDFILEID
) {
531 struct presto_dentry_data
*dd
= presto_d2d(dentry
);
533 dd
->remote_ino
= info
->remote_ino
;
534 dd
->remote_generation
= info
->remote_generation
;
538 #if 0 /* was a broken check for Posix ACLs */
539 /* restore the inode_operations if we changed them*/
540 if (iattr
->ia_valid
& ATTR_MODE
)
541 dentry
->d_inode
->i_op
->set_posix_acl
=set_posix_acl
;
553 int presto_do_create(struct presto_file_set
*fset
, struct dentry
*dir
,
554 struct dentry
*dentry
, int mode
,
555 struct lento_vfs_context
*info
)
559 struct presto_version tgt_dir_ver
, new_file_ver
;
560 struct inode_operations
*iops
;
567 // down(&dir->d_inode->i_zombie);
568 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
);
571 // up(&dir->d_inode->i_zombie);
575 error
= may_create(dir
->d_inode
, dentry
);
582 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
588 presto_getversion(&tgt_dir_ver
, dir
->d_inode
);
589 handle
= presto_trans_start(fset
, dir
->d_inode
, KML_OPCODE_CREATE
);
590 if ( IS_ERR(handle
) ) {
592 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
593 CERROR("presto_do_create: no space for transaction\n");
597 DQUOT_INIT(dir
->d_inode
);
599 error
= iops
->create(dir
->d_inode
, dentry
, mode
);
605 if (dentry
->d_inode
) {
606 struct presto_cache
*cache
= fset
->fset_cache
;
607 /* was this already done? */
608 presto_set_ops(dentry
->d_inode
, cache
->cache_filter
);
610 filter_setup_dentry_ops(cache
->cache_filter
,
613 dentry
->d_op
= filter_c2udops(cache
->cache_filter
);
615 /* if Lento creates this file, we won't have data */
616 if ( ISLENTO(presto_c2m(cache
)) ) {
617 presto_set(dentry
, PRESTO_ATTR
);
619 presto_set(dentry
, PRESTO_ATTR
| PRESTO_DATA
);
623 info
->flags
|= LENTO_FL_TOUCH_PARENT
;
624 error
= presto_settime(fset
, NULL
, dir
, dentry
,
625 info
, ATTR_CTIME
| ATTR_MTIME
);
631 presto_debug_fail_blkdev(fset
, KML_OPCODE_CREATE
| 0x10);
633 if ( presto_do_kml(info
, dentry
) ) {
634 presto_getversion(&new_file_ver
, dentry
->d_inode
);
635 error
= presto_journal_create(&rec
, fset
, dentry
, &tgt_dir_ver
,
637 dentry
->d_inode
->i_mode
);
640 presto_debug_fail_blkdev(fset
, KML_OPCODE_CREATE
| 0x20);
642 if ( presto_do_rcvd(info
, dentry
) )
643 error
= presto_write_last_rcvd(&rec
, fset
, info
);
645 presto_debug_fail_blkdev(fset
, KML_OPCODE_CREATE
| 0x30);
647 /* add inode dentry */
648 if (fset
->fset_cache
->cache_filter
->o_trops
->tr_add_ilookup
) {
650 d
= fset
->fset_cache
->cache_filter
->o_trops
->tr_add_ilookup
651 (dir
->d_inode
->i_sb
->s_root
, dentry
);
658 presto_trans_commit(fset
, handle
);
660 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
661 // up(&dir->d_inode->i_zombie);
666 static struct dentry
*lookup_create(struct nameidata
*nd
, int is_dir
)
668 struct dentry
*dentry
;
670 down(&nd
->dentry
->d_inode
->i_sem
);
671 dentry
= ERR_PTR(-EEXIST
);
672 if (nd
->last_type
!= LAST_NORM
)
674 dentry
= lookup_hash(&nd
->last
, nd
->dentry
);
677 if (!is_dir
&& nd
->last
.name
[nd
->last
.len
] && !dentry
->d_inode
)
682 dentry
= ERR_PTR(-ENOENT
);
687 int lento_create(const char *name
, int mode
, struct lento_vfs_context
*info
)
692 struct dentry
*dentry
;
693 struct presto_file_set
*fset
;
696 pathname
= getname(name
);
697 error
= PTR_ERR(pathname
);
698 if (IS_ERR(pathname
)) {
703 /* this looks up the parent */
704 error
= path_lookup(pathname
, LOOKUP_PARENT
, &nd
);
709 dentry
= lookup_create(&nd
, 0);
710 error
= PTR_ERR(dentry
);
711 if (IS_ERR(dentry
)) {
716 fset
= presto_fset(dentry
);
719 CERROR("No fileset!\n");
723 error
= presto_do_create(fset
, dentry
->d_parent
, dentry
, (mode
&S_IALLUGO
)|S_IFREG
,
731 up(&dentry
->d_parent
->d_inode
->i_sem
);
737 int presto_do_link(struct presto_file_set
*fset
, struct dentry
*old_dentry
,
738 struct dentry
*dir
, struct dentry
*new_dentry
,
739 struct lento_vfs_context
*info
)
744 struct inode_operations
*iops
;
745 struct presto_version tgt_dir_ver
;
746 struct presto_version new_link_ver
;
749 // down(&dir->d_inode->i_zombie);
750 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
);
753 // up(&dir->d_inode->i_zombie);
757 inode
= old_dentry
->d_inode
;
761 error
= may_create(dir
->d_inode
, new_dentry
);
766 if (dir
->d_inode
->i_dev
!= inode
->i_dev
)
770 * A link to an append-only or immutable file cannot be created.
773 if (IS_APPEND(inode
) || IS_IMMUTABLE(inode
)) {
778 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
785 presto_getversion(&tgt_dir_ver
, dir
->d_inode
);
786 handle
= presto_trans_start(fset
, dir
->d_inode
, KML_OPCODE_LINK
);
787 if ( IS_ERR(handle
) ) {
788 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
789 CERROR("presto_do_link: no space for transaction\n");
793 DQUOT_INIT(dir
->d_inode
);
795 error
= iops
->link(old_dentry
, dir
->d_inode
, new_dentry
);
802 /* link dd data to that of existing dentry */
803 old_dentry
->d_op
->d_release(new_dentry
);
804 if (!presto_d2d(old_dentry
))
806 presto_d2d(old_dentry
)->dd_count
++;
808 new_dentry
->d_fsdata
= presto_d2d(old_dentry
);
810 info
->flags
|= LENTO_FL_TOUCH_PARENT
;
811 error
= presto_settime(fset
, NULL
, dir
, new_dentry
,
818 presto_debug_fail_blkdev(fset
, KML_OPCODE_LINK
| 0x10);
819 presto_getversion(&new_link_ver
, new_dentry
->d_inode
);
820 if ( presto_do_kml(info
, old_dentry
) )
821 error
= presto_journal_link(&rec
, fset
, old_dentry
, new_dentry
,
822 &tgt_dir_ver
, &new_link_ver
);
824 presto_debug_fail_blkdev(fset
, KML_OPCODE_LINK
| 0x20);
825 if ( presto_do_rcvd(info
, old_dentry
) )
826 error
= presto_write_last_rcvd(&rec
, fset
, info
);
828 presto_debug_fail_blkdev(fset
, KML_OPCODE_LINK
| 0x30);
830 presto_trans_commit(fset
, handle
);
832 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
833 // up(&dir->d_inode->i_zombie);
838 int lento_link(const char * oldname
, const char * newname
,
839 struct lento_vfs_context
*info
)
843 struct presto_file_set
*fset
;
845 to
= getname(newname
);
848 struct dentry
*new_dentry
;
849 struct nameidata nd
, old_nd
;
851 error
= __user_walk(oldname
, 0, &old_nd
);
854 error
= path_lookup(to
, LOOKUP_PARENT
, &nd
);
858 if (old_nd
.mnt
!= nd
.mnt
)
860 new_dentry
= lookup_create(&nd
, 0);
861 error
= PTR_ERR(new_dentry
);
863 if (!IS_ERR(new_dentry
)) {
864 fset
= presto_fset(new_dentry
);
867 CERROR("No fileset!\n");
871 error
= presto_do_link(fset
, old_nd
.dentry
,
877 up(&nd
.dentry
->d_inode
->i_sem
);
880 path_release(&old_nd
);
887 int presto_do_unlink(struct presto_file_set
*fset
, struct dentry
*dir
,
888 struct dentry
*dentry
, struct lento_vfs_context
*info
)
891 struct inode_operations
*iops
;
892 struct presto_version tgt_dir_ver
, old_file_ver
;
893 struct izo_rollback_data rb
;
895 int do_kml
= 0, do_rcvd
= 0, linkno
= 0, error
, old_targetlen
= 0;
896 char *old_target
= NULL
;
899 // down(&dir->d_inode->i_zombie);
900 error
= may_delete(dir
->d_inode
, dentry
, 0);
903 // up(&dir->d_inode->i_zombie);
908 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
911 // up(&dir->d_inode->i_zombie);
915 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQLOW
);
918 // up(&dir->d_inode->i_zombie);
923 if (presto_d2d(dentry
)) {
924 struct presto_dentry_data
*dd
= presto_d2d(dentry
);
925 struct dentry
*de
= dd
->dd_inodentry
;
926 if (de
&& dentry
->d_inode
->i_nlink
== 1) {
928 dd
->dd_inodentry
= NULL
;
930 atomic_dec(&de
->d_inode
->i_count
);
936 presto_getversion(&tgt_dir_ver
, dir
->d_inode
);
937 presto_getversion(&old_file_ver
, dentry
->d_inode
);
938 izo_get_rollback_data(dentry
->d_inode
, &rb
);
939 handle
= presto_trans_start(fset
, dir
->d_inode
, KML_OPCODE_UNLINK
);
940 if ( IS_ERR(handle
) ) {
941 presto_release_space(fset
->fset_cache
, PRESTO_REQLOW
);
942 CERROR("ERROR: presto_do_unlink: no space for transaction. Tell Peter.\n");
943 // up(&dir->d_inode->i_zombie);
946 DQUOT_INIT(dir
->d_inode
);
947 if (d_mountpoint(dentry
))
951 linkno
= dentry
->d_inode
->i_nlink
;
956 if (S_ISLNK(dentry
->d_inode
->i_mode
)) {
958 struct inode_operations
*riops
;
959 riops
= filter_c2csiops(fset
->fset_cache
->cache_filter
);
961 PRESTO_ALLOC(old_target
, PATH_MAX
);
962 if (old_target
== NULL
) {
971 if (riops
->readlink
== NULL
)
972 CERROR("InterMezzo %s: no readlink iops.\n",
976 riops
->readlink(dentry
, old_target
,
978 if (old_targetlen
< 0) {
979 CERROR("InterMezzo: readlink failed: %ld\n",
980 PTR_ERR(old_target
));
981 PRESTO_FREE(old_target
, PATH_MAX
);
988 do_kml
= presto_do_kml(info
, dir
);
989 do_rcvd
= presto_do_rcvd(info
, dir
);
990 error
= iops
->unlink(dir
->d_inode
, dentry
);
997 /* FIXME: Combine this with the next call? */
998 error
= presto_settime(fset
, NULL
, NULL
, dentry
,
1007 error
= presto_settime(fset
, NULL
, NULL
, dir
,
1008 info
, ATTR_CTIME
| ATTR_MTIME
);
1014 // up(&dir->d_inode->i_zombie);
1020 presto_debug_fail_blkdev(fset
, KML_OPCODE_UNLINK
| 0x10);
1022 error
= presto_journal_unlink(&rec
, fset
, dir
, &tgt_dir_ver
,
1023 &old_file_ver
, &rb
, dentry
,
1024 old_target
, old_targetlen
);
1025 presto_debug_fail_blkdev(fset
, KML_OPCODE_UNLINK
| 0x20);
1027 error
= presto_write_last_rcvd(&rec
, fset
, info
);
1029 presto_debug_fail_blkdev(fset
, KML_OPCODE_UNLINK
| 0x30);
1032 presto_release_space(fset
->fset_cache
, PRESTO_REQLOW
);
1033 presto_trans_commit(fset
, handle
);
1034 if (old_target
!= NULL
)
1035 PRESTO_FREE(old_target
, PATH_MAX
);
1040 int lento_unlink(const char *pathname
, struct lento_vfs_context
*info
)
1044 struct dentry
*dentry
;
1045 struct nameidata nd
;
1046 struct presto_file_set
*fset
;
1050 name
= getname(pathname
);
1052 return PTR_ERR(name
);
1054 error
= path_lookup(name
, LOOKUP_PARENT
, &nd
);
1058 if (nd
.last_type
!= LAST_NORM
)
1060 down(&nd
.dentry
->d_inode
->i_sem
);
1061 dentry
= lookup_hash(&nd
.last
, nd
.dentry
);
1062 error
= PTR_ERR(dentry
);
1063 if (!IS_ERR(dentry
)) {
1064 fset
= presto_fset(dentry
);
1067 CERROR("No fileset!\n");
1071 /* Why not before? Because we want correct error value */
1072 if (nd
.last
.name
[nd
.last
.len
])
1074 error
= presto_do_unlink(fset
, nd
.dentry
, dentry
, info
);
1079 up(&nd
.dentry
->d_inode
->i_sem
);
1088 error
= !dentry
->d_inode
? -ENOENT
:
1089 S_ISDIR(dentry
->d_inode
->i_mode
) ? -EISDIR
: -ENOTDIR
;
1093 int presto_do_symlink(struct presto_file_set
*fset
, struct dentry
*dir
,
1094 struct dentry
*dentry
, const char *oldname
,
1095 struct lento_vfs_context
*info
)
1097 struct rec_info rec
;
1099 struct presto_version tgt_dir_ver
, new_link_ver
;
1100 struct inode_operations
*iops
;
1104 // down(&dir->d_inode->i_zombie);
1105 /* record + max path len + space to free */
1106 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
+ 4096);
1109 // up(&dir->d_inode->i_zombie);
1113 error
= may_create(dir
->d_inode
, dentry
);
1120 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
1121 if (!iops
->symlink
) {
1126 presto_getversion(&tgt_dir_ver
, dir
->d_inode
);
1127 handle
= presto_trans_start(fset
, dir
->d_inode
, KML_OPCODE_SYMLINK
);
1128 if ( IS_ERR(handle
) ) {
1129 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
+ 4096);
1130 CERROR("ERROR: presto_do_symlink: no space for transaction. Tell Peter.\n");
1132 // up(&dir->d_inode->i_zombie);
1135 DQUOT_INIT(dir
->d_inode
);
1137 error
= iops
->symlink(dir
->d_inode
, dentry
, oldname
);
1143 if (dentry
->d_inode
) {
1144 struct presto_cache
*cache
= fset
->fset_cache
;
1146 presto_set_ops(dentry
->d_inode
, cache
->cache_filter
);
1148 filter_setup_dentry_ops(cache
->cache_filter
, dentry
->d_op
,
1149 &presto_dentry_ops
);
1150 dentry
->d_op
= filter_c2udops(cache
->cache_filter
);
1151 /* XXX ? Cache state ? if Lento creates a symlink */
1152 if ( ISLENTO(presto_c2m(cache
)) ) {
1153 presto_set(dentry
, PRESTO_ATTR
);
1155 presto_set(dentry
, PRESTO_ATTR
| PRESTO_DATA
);
1159 info
->flags
|= LENTO_FL_TOUCH_PARENT
;
1160 error
= presto_settime(fset
, NULL
, dir
, dentry
,
1161 info
, ATTR_CTIME
| ATTR_MTIME
);
1167 presto_debug_fail_blkdev(fset
, KML_OPCODE_SYMLINK
| 0x10);
1168 presto_getversion(&new_link_ver
, dentry
->d_inode
);
1169 if ( presto_do_kml(info
, dentry
) )
1170 error
= presto_journal_symlink(&rec
, fset
, dentry
, oldname
,
1171 &tgt_dir_ver
, &new_link_ver
);
1173 presto_debug_fail_blkdev(fset
, KML_OPCODE_SYMLINK
| 0x20);
1174 if ( presto_do_rcvd(info
, dentry
) )
1175 error
= presto_write_last_rcvd(&rec
, fset
, info
);
1177 presto_debug_fail_blkdev(fset
, KML_OPCODE_SYMLINK
| 0x30);
1181 presto_trans_commit(fset
, handle
);
1183 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
+ 4096);
1184 // up(&dir->d_inode->i_zombie);
1188 int lento_symlink(const char *oldname
, const char *newname
,
1189 struct lento_vfs_context
*info
)
1194 struct dentry
*dentry
;
1195 struct presto_file_set
*fset
;
1196 struct nameidata nd
;
1200 from
= getname(oldname
);
1201 error
= PTR_ERR(from
);
1207 to
= getname(newname
);
1208 error
= PTR_ERR(to
);
1214 error
= path_lookup(to
, LOOKUP_PARENT
, &nd
);
1220 dentry
= lookup_create(&nd
, 0);
1221 error
= PTR_ERR(dentry
);
1222 if (IS_ERR(dentry
)) {
1228 fset
= presto_fset(dentry
);
1231 CERROR("No fileset!\n");
1236 error
= presto_do_symlink(fset
, nd
.dentry
,
1237 dentry
, oldname
, info
);
1241 up(&nd
.dentry
->d_inode
->i_sem
);
1252 int presto_do_mkdir(struct presto_file_set
*fset
, struct dentry
*dir
,
1253 struct dentry
*dentry
, int mode
,
1254 struct lento_vfs_context
*info
)
1256 struct rec_info rec
;
1258 struct presto_version tgt_dir_ver
, new_dir_ver
;
1262 // down(&dir->d_inode->i_zombie);
1264 /* one journal record + directory block + room for removals*/
1265 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
+ 4096);
1268 // up(&dir->d_inode->i_zombie);
1272 error
= may_create(dir
->d_inode
, dentry
);
1279 if (!filter_c2cdiops(fset
->fset_cache
->cache_filter
)->mkdir
) {
1285 presto_getversion(&tgt_dir_ver
, dir
->d_inode
);
1286 handle
= presto_trans_start(fset
, dir
->d_inode
, KML_OPCODE_MKDIR
);
1287 if ( IS_ERR(handle
) ) {
1288 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
+ 4096);
1289 CERROR("presto_do_mkdir: no space for transaction\n");
1293 DQUOT_INIT(dir
->d_inode
);
1294 mode
&= (S_IRWXUGO
|S_ISVTX
);
1296 error
= filter_c2cdiops(fset
->fset_cache
->cache_filter
)->mkdir(dir
->d_inode
, dentry
, mode
);
1302 if ( dentry
->d_inode
&& !error
) {
1303 struct presto_cache
*cache
= fset
->fset_cache
;
1305 presto_set_ops(dentry
->d_inode
, cache
->cache_filter
);
1307 filter_setup_dentry_ops(cache
->cache_filter
,
1309 &presto_dentry_ops
);
1310 dentry
->d_op
= filter_c2udops(cache
->cache_filter
);
1311 /* if Lento does this, we won't have data */
1312 if ( ISLENTO(presto_c2m(cache
)) ) {
1313 presto_set(dentry
, PRESTO_ATTR
);
1315 presto_set(dentry
, PRESTO_ATTR
| PRESTO_DATA
);
1319 info
->flags
|= LENTO_FL_TOUCH_PARENT
;
1320 error
= presto_settime(fset
, NULL
, dir
, dentry
,
1321 info
, ATTR_CTIME
| ATTR_MTIME
);
1327 presto_debug_fail_blkdev(fset
, KML_OPCODE_MKDIR
| 0x10);
1328 presto_getversion(&new_dir_ver
, dentry
->d_inode
);
1329 if ( presto_do_kml(info
, dir
) )
1330 error
= presto_journal_mkdir(&rec
, fset
, dentry
, &tgt_dir_ver
,
1332 dentry
->d_inode
->i_mode
);
1334 presto_debug_fail_blkdev(fset
, KML_OPCODE_MKDIR
| 0x20);
1335 if ( presto_do_rcvd(info
, dentry
) )
1336 error
= presto_write_last_rcvd(&rec
, fset
, info
);
1338 presto_debug_fail_blkdev(fset
, KML_OPCODE_MKDIR
| 0x30);
1342 presto_trans_commit(fset
, handle
);
1344 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
+ 4096);
1345 // up(&dir->d_inode->i_zombie);
1350 * Look out: this function may change a normal dentry
1351 * into a directory dentry (different size)..
1353 int lento_mkdir(const char *name
, int mode
, struct lento_vfs_context
*info
)
1357 struct dentry
*dentry
;
1358 struct presto_file_set
*fset
;
1359 struct nameidata nd
;
1362 CDEBUG(D_PIOCTL
, "name: %s, mode %o, offset %d, recno %d, flags %x\n",
1363 name
, mode
, info
->slot_offset
, info
->recno
, info
->flags
);
1364 pathname
= getname(name
);
1365 error
= PTR_ERR(pathname
);
1366 if (IS_ERR(pathname
)) {
1371 error
= path_lookup(pathname
, LOOKUP_PARENT
, &nd
);
1375 dentry
= lookup_create(&nd
, 1);
1376 error
= PTR_ERR(dentry
);
1377 if (!IS_ERR(dentry
)) {
1378 fset
= presto_fset(dentry
);
1381 CERROR("No fileset!\n");
1386 error
= presto_do_mkdir(fset
, nd
.dentry
, dentry
,
1387 mode
& S_IALLUGO
, info
);
1391 up(&nd
.dentry
->d_inode
->i_sem
);
1396 CDEBUG(D_PIOCTL
, "error: %d\n", error
);
1400 static void d_unhash(struct dentry
*dentry
)
1403 switch (atomic_read(&dentry
->d_count
)) {
1405 shrink_dcache_parent(dentry
);
1406 if (atomic_read(&dentry
->d_count
) != 2)
1413 int presto_do_rmdir(struct presto_file_set
*fset
, struct dentry
*dir
,
1414 struct dentry
*dentry
, struct lento_vfs_context
*info
)
1416 struct rec_info rec
;
1418 struct presto_version tgt_dir_ver
, old_dir_ver
;
1419 struct izo_rollback_data rb
;
1420 struct inode_operations
*iops
;
1422 int do_kml
, do_rcvd
;
1426 error
= may_delete(dir
->d_inode
, dentry
, 1);
1431 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
1437 size
= PRESTO_REQHIGH
- dentry
->d_inode
->i_size
;
1438 error
= presto_reserve_space(fset
->fset_cache
, size
);
1444 presto_getversion(&tgt_dir_ver
, dir
->d_inode
);
1445 presto_getversion(&old_dir_ver
, dentry
->d_inode
);
1446 izo_get_rollback_data(dentry
->d_inode
, &rb
);
1447 handle
= presto_trans_start(fset
, dir
->d_inode
, KML_OPCODE_RMDIR
);
1448 if ( IS_ERR(handle
) ) {
1449 presto_release_space(fset
->fset_cache
, size
);
1450 CERROR("ERROR: presto_do_rmdir: no space for transaction. Tell Peter.\n");
1454 DQUOT_INIT(dir
->d_inode
);
1456 do_kml
= presto_do_kml(info
, dir
);
1457 do_rcvd
= presto_do_rcvd(info
, dir
);
1459 // double_down(&dir->d_inode->i_zombie, &dentry->d_inode->i_zombie);
1461 if (IS_DEADDIR(dir
->d_inode
))
1463 else if (d_mountpoint(dentry
)) {
1464 CERROR("foo: d_mountpoint(dentry): ino %ld\n",
1465 dentry
->d_inode
->i_ino
);
1469 error
= iops
->rmdir(dir
->d_inode
, dentry
);
1472 dentry
->d_inode
->i_flags
|= S_DEAD
;
1473 error
= presto_settime(fset
, NULL
, NULL
, dir
, info
,
1474 ATTR_CTIME
| ATTR_MTIME
);
1477 // double_up(&dir->d_inode->i_zombie, &dentry->d_inode->i_zombie);
1482 presto_debug_fail_blkdev(fset
, KML_OPCODE_RMDIR
| 0x10);
1483 if ( !error
&& do_kml
)
1484 error
= presto_journal_rmdir(&rec
, fset
, dir
, &tgt_dir_ver
,
1487 dentry
->d_name
.name
);
1489 presto_debug_fail_blkdev(fset
, KML_OPCODE_RMDIR
| 0x20);
1490 if ( !error
&& do_rcvd
)
1491 error
= presto_write_last_rcvd(&rec
, fset
, info
);
1493 presto_debug_fail_blkdev(fset
, KML_OPCODE_RMDIR
| 0x30);
1496 presto_trans_commit(fset
, handle
);
1497 presto_release_space(fset
->fset_cache
, size
);
1501 int lento_rmdir(const char *pathname
, struct lento_vfs_context
*info
)
1505 struct dentry
*dentry
;
1506 struct presto_file_set
*fset
;
1507 struct nameidata nd
;
1510 name
= getname(pathname
);
1513 return PTR_ERR(name
);
1516 error
= path_lookup(name
, LOOKUP_PARENT
, &nd
);
1521 switch(nd
.last_type
) {
1532 down(&nd
.dentry
->d_inode
->i_sem
);
1533 dentry
= lookup_hash(&nd
.last
, nd
.dentry
);
1534 error
= PTR_ERR(dentry
);
1535 if (!IS_ERR(dentry
)) {
1536 fset
= presto_fset(dentry
);
1539 CERROR("No fileset!\n");
1543 error
= presto_do_rmdir(fset
, nd
.dentry
, dentry
, info
);
1547 up(&nd
.dentry
->d_inode
->i_sem
);
1556 int presto_do_mknod(struct presto_file_set
*fset
, struct dentry
*dir
,
1557 struct dentry
*dentry
, int mode
, dev_t dev
,
1558 struct lento_vfs_context
*info
)
1560 struct rec_info rec
;
1562 struct presto_version tgt_dir_ver
, new_node_ver
;
1563 struct inode_operations
*iops
;
1568 // down(&dir->d_inode->i_zombie);
1570 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
);
1573 // up(&dir->d_inode->i_zombie);
1577 if ((S_ISCHR(mode
) || S_ISBLK(mode
)) && !capable(CAP_MKNOD
)) {
1582 error
= may_create(dir
->d_inode
, dentry
);
1589 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
1595 DQUOT_INIT(dir
->d_inode
);
1599 presto_getversion(&tgt_dir_ver
, dir
->d_inode
);
1600 handle
= presto_trans_start(fset
, dir
->d_inode
, KML_OPCODE_MKNOD
);
1601 if ( IS_ERR(handle
) ) {
1602 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
1603 CERROR("presto_do_mknod: no space for transaction\n");
1607 error
= iops
->mknod(dir
->d_inode
, dentry
, mode
, dev
);
1612 if ( dentry
->d_inode
) {
1613 struct presto_cache
*cache
= fset
->fset_cache
;
1615 presto_set_ops(dentry
->d_inode
, cache
->cache_filter
);
1617 filter_setup_dentry_ops(cache
->cache_filter
, dentry
->d_op
,
1618 &presto_dentry_ops
);
1619 dentry
->d_op
= filter_c2udops(cache
->cache_filter
);
1621 /* if Lento does this, we won't have data */
1622 if ( ISLENTO(presto_c2m(cache
)) ) {
1623 presto_set(dentry
, PRESTO_ATTR
);
1625 presto_set(dentry
, PRESTO_ATTR
| PRESTO_DATA
);
1629 error
= presto_settime(fset
, NULL
, NULL
, dir
,
1634 error
= presto_settime(fset
, NULL
, NULL
, dentry
,
1635 info
, ATTR_CTIME
| ATTR_MTIME
);
1640 presto_debug_fail_blkdev(fset
, KML_OPCODE_MKNOD
| 0x10);
1641 presto_getversion(&new_node_ver
, dentry
->d_inode
);
1642 if ( presto_do_kml(info
, dentry
) )
1643 error
= presto_journal_mknod(&rec
, fset
, dentry
, &tgt_dir_ver
,
1645 dentry
->d_inode
->i_mode
,
1646 MAJOR(dev
), MINOR(dev
) );
1648 presto_debug_fail_blkdev(fset
, KML_OPCODE_MKNOD
| 0x20);
1649 if ( presto_do_rcvd(info
, dentry
) )
1650 error
= presto_write_last_rcvd(&rec
, fset
, info
);
1652 presto_debug_fail_blkdev(fset
, KML_OPCODE_MKNOD
| 0x30);
1655 presto_trans_commit(fset
, handle
);
1659 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
1660 // up(&dir->d_inode->i_zombie);
1664 int lento_mknod(const char *filename
, int mode
, dev_t dev
,
1665 struct lento_vfs_context
*info
)
1669 struct dentry
* dentry
;
1670 struct nameidata nd
;
1671 struct presto_file_set
*fset
;
1677 tmp
= getname(filename
);
1679 return PTR_ERR(tmp
);
1681 error
= path_lookup(tmp
, LOOKUP_PARENT
, &nd
);
1684 dentry
= lookup_create(&nd
, 0);
1685 error
= PTR_ERR(dentry
);
1686 if (!IS_ERR(dentry
)) {
1687 fset
= presto_fset(dentry
);
1690 CERROR("No fileset!\n");
1694 switch (mode
& S_IFMT
) {
1695 case 0: case S_IFREG
:
1696 error
= -EOPNOTSUPP
;
1698 case S_IFCHR
: case S_IFBLK
: case S_IFIFO
: case S_IFSOCK
:
1699 error
= presto_do_mknod(fset
, nd
.dentry
, dentry
,
1711 up(&nd
.dentry
->d_inode
->i_sem
);
1719 int do_rename(struct presto_file_set
*fset
,
1720 struct dentry
*old_parent
, struct dentry
*old_dentry
,
1721 struct dentry
*new_parent
, struct dentry
*new_dentry
,
1722 struct lento_vfs_context
*info
)
1724 struct rec_info rec
;
1726 struct inode_operations
*iops
;
1727 struct presto_version src_dir_ver
, tgt_dir_ver
;
1729 int new_inode_unlink
= 0;
1730 struct inode
*old_dir
= old_parent
->d_inode
;
1731 struct inode
*new_dir
= new_parent
->d_inode
;
1734 presto_getversion(&src_dir_ver
, old_dir
);
1735 presto_getversion(&tgt_dir_ver
, new_dir
);
1738 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
1739 if (!iops
|| !iops
->rename
) {
1744 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
);
1749 handle
= presto_trans_start(fset
, old_dir
, KML_OPCODE_RENAME
);
1750 if ( IS_ERR(handle
) ) {
1751 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
1752 CERROR("presto_do_rename: no space for transaction\n");
1755 if (new_dentry
->d_inode
&& new_dentry
->d_inode
->i_nlink
> 1) {
1757 new_inode_unlink
= 1;
1760 error
= iops
->rename(old_dir
, old_dentry
, new_dir
, new_dentry
);
1767 if (new_inode_unlink
) {
1768 error
= presto_settime(fset
, NULL
, NULL
, old_dentry
,
1776 info
->flags
|= LENTO_FL_TOUCH_PARENT
;
1777 error
= presto_settime(fset
, NULL
, new_parent
, old_parent
,
1778 info
, ATTR_CTIME
| ATTR_MTIME
);
1784 /* XXX make a distinction between cross file set
1785 * and intra file set renames here
1787 presto_debug_fail_blkdev(fset
, KML_OPCODE_RENAME
| 0x10);
1788 if ( presto_do_kml(info
, old_dentry
) )
1789 error
= presto_journal_rename(&rec
, fset
, old_dentry
,
1791 &src_dir_ver
, &tgt_dir_ver
);
1793 presto_debug_fail_blkdev(fset
, KML_OPCODE_RENAME
| 0x20);
1795 if ( presto_do_rcvd(info
, old_dentry
) )
1796 error
= presto_write_last_rcvd(&rec
, fset
, info
);
1798 presto_debug_fail_blkdev(fset
, KML_OPCODE_RENAME
| 0x30);
1801 presto_trans_commit(fset
, handle
);
1802 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
1807 int presto_rename_dir(struct presto_file_set
*fset
, struct dentry
*old_parent
,
1808 struct dentry
*old_dentry
, struct dentry
*new_parent
,
1809 struct dentry
*new_dentry
, struct lento_vfs_context
*info
)
1812 struct inode
*target
;
1813 struct inode
*old_dir
= old_parent
->d_inode
;
1814 struct inode
*new_dir
= new_parent
->d_inode
;
1816 if (old_dentry
->d_inode
== new_dentry
->d_inode
)
1819 error
= may_delete(old_dir
, old_dentry
, 1);
1823 if (new_dir
->i_dev
!= old_dir
->i_dev
)
1826 if (!new_dentry
->d_inode
)
1827 error
= may_create(new_dir
, new_dentry
);
1829 error
= may_delete(new_dir
, new_dentry
, 1);
1833 if (!old_dir
->i_op
|| !old_dir
->i_op
->rename
)
1837 * If we are going to change the parent - check write permissions,
1838 * we'll need to flip '..'.
1840 if (new_dir
!= old_dir
) {
1841 error
= permission(old_dentry
->d_inode
, MAY_WRITE
);
1846 DQUOT_INIT(old_dir
);
1847 DQUOT_INIT(new_dir
);
1848 down(&old_dir
->i_sb
->s_vfs_rename_sem
);
1850 if (is_subdir(new_dentry
, old_dentry
))
1852 target
= new_dentry
->d_inode
;
1853 if (target
) { /* Hastur! Hastur! Hastur! */
1854 // triple_down(&old_dir->i_zombie,
1855 // &new_dir->i_zombie,
1856 // &target->i_zombie);
1857 d_unhash(new_dentry
);
1859 // double_down(&old_dir->i_zombie,
1860 // &new_dir->i_zombie);
1861 if (IS_DEADDIR(old_dir
)||IS_DEADDIR(new_dir
))
1863 else if (d_mountpoint(old_dentry
)||d_mountpoint(new_dentry
))
1866 error
= do_rename(fset
, old_parent
, old_dentry
,
1867 new_parent
, new_dentry
, info
);
1870 target
->i_flags
|= S_DEAD
;
1871 // triple_up(&old_dir->i_zombie,
1872 // &new_dir->i_zombie,
1873 // &target->i_zombie);
1874 if (d_unhashed(new_dentry
))
1875 d_rehash(new_dentry
);
1878 // double_up(&old_dir->i_zombie,
1879 // &new_dir->i_zombie);
1882 d_move(old_dentry
,new_dentry
);
1884 up(&old_dir
->i_sb
->s_vfs_rename_sem
);
1889 int presto_rename_other(struct presto_file_set
*fset
, struct dentry
*old_parent
,
1890 struct dentry
*old_dentry
, struct dentry
*new_parent
,
1891 struct dentry
*new_dentry
, struct lento_vfs_context
*info
)
1893 struct inode
*old_dir
= old_parent
->d_inode
;
1894 struct inode
*new_dir
= new_parent
->d_inode
;
1897 if (old_dentry
->d_inode
== new_dentry
->d_inode
)
1900 error
= may_delete(old_dir
, old_dentry
, 0);
1904 if (new_dir
->i_dev
!= old_dir
->i_dev
)
1907 if (!new_dentry
->d_inode
)
1908 error
= may_create(new_dir
, new_dentry
);
1910 error
= may_delete(new_dir
, new_dentry
, 0);
1914 if (!old_dir
->i_op
|| !old_dir
->i_op
->rename
)
1917 DQUOT_INIT(old_dir
);
1918 DQUOT_INIT(new_dir
);
1919 // double_down(&old_dir->i_zombie, &new_dir->i_zombie);
1920 if (d_mountpoint(old_dentry
)||d_mountpoint(new_dentry
))
1923 error
= do_rename(fset
, old_parent
, old_dentry
,
1924 new_parent
, new_dentry
, info
);
1925 // double_up(&old_dir->i_zombie, &new_dir->i_zombie);
1928 /* The following d_move() should become unconditional */
1929 if (!(old_dir
->i_sb
->s_type
->fs_flags
& FS_ODD_RENAME
)) {
1930 d_move(old_dentry
, new_dentry
);
1935 int presto_do_rename(struct presto_file_set
*fset
,
1936 struct dentry
*old_parent
, struct dentry
*old_dentry
,
1937 struct dentry
*new_parent
, struct dentry
*new_dentry
,
1938 struct lento_vfs_context
*info
)
1940 if (S_ISDIR(old_dentry
->d_inode
->i_mode
))
1941 return presto_rename_dir(fset
, old_parent
,old_dentry
,new_parent
,
1944 return presto_rename_other(fset
, old_parent
, old_dentry
,
1945 new_parent
,new_dentry
, info
);
1949 int lento_do_rename(const char *oldname
, const char *newname
,
1950 struct lento_vfs_context
*info
)
1953 struct dentry
* old_dir
, * new_dir
;
1954 struct dentry
* old_dentry
, *new_dentry
;
1955 struct nameidata oldnd
, newnd
;
1956 struct presto_file_set
*fset
;
1960 error
= path_lookup(oldname
, LOOKUP_PARENT
, &oldnd
);
1964 error
= path_lookup(newname
, LOOKUP_PARENT
, &newnd
);
1969 if (oldnd
.mnt
!= newnd
.mnt
)
1972 old_dir
= oldnd
.dentry
;
1974 if (oldnd
.last_type
!= LAST_NORM
)
1977 new_dir
= newnd
.dentry
;
1978 if (newnd
.last_type
!= LAST_NORM
)
1981 lock_rename(new_dir
, old_dir
);
1983 old_dentry
= lookup_hash(&oldnd
.last
, old_dir
);
1984 error
= PTR_ERR(old_dentry
);
1985 if (IS_ERR(old_dentry
))
1987 /* source must exist */
1989 if (!old_dentry
->d_inode
)
1991 fset
= presto_fset(old_dentry
);
1994 CERROR("No fileset!\n");
1998 /* unless the source is a directory trailing slashes give -ENOTDIR */
1999 if (!S_ISDIR(old_dentry
->d_inode
->i_mode
)) {
2001 if (oldnd
.last
.name
[oldnd
.last
.len
])
2003 if (newnd
.last
.name
[newnd
.last
.len
])
2006 new_dentry
= lookup_hash(&newnd
.last
, new_dir
);
2007 error
= PTR_ERR(new_dentry
);
2008 if (IS_ERR(new_dentry
))
2012 error
= presto_do_rename(fset
, old_dir
, old_dentry
,
2013 new_dir
, new_dentry
, info
);
2020 unlock_rename(new_dir
, old_dir
);
2022 path_release(&newnd
);
2024 path_release(&oldnd
);
2029 int lento_rename(const char * oldname
, const char * newname
,
2030 struct lento_vfs_context
*info
)
2036 from
= getname(oldname
);
2038 return PTR_ERR(from
);
2039 to
= getname(newname
);
2040 error
= PTR_ERR(to
);
2042 error
= lento_do_rename(from
,to
, info
);
2049 struct dentry
*presto_iopen(struct dentry
*dentry
,
2050 ino_t ino
, unsigned int generation
)
2052 struct presto_file_set
*fset
;
2057 /* see if we already have the dentry we want */
2058 if (dentry
->d_inode
&& dentry
->d_inode
->i_ino
== ino
&&
2059 dentry
->d_inode
->i_generation
== generation
) {
2064 /* Make sure we have a cache beneath us. We should always find at
2065 * least one dentry inside the cache (if it exists), otherwise not
2066 * even the cache root exists, or we passed in a bad name.
2068 fset
= presto_fset(dentry
);
2071 CERROR("No fileset for %*s!\n",
2072 dentry
->d_name
.len
, dentry
->d_name
.name
);
2075 return ERR_PTR(error
);
2079 sprintf(name
, "%s%#lx%c%#x",
2080 PRESTO_ILOOKUP_MAGIC
, ino
, PRESTO_ILOOKUP_SEP
, generation
);
2081 CDEBUG(D_PIOCTL
, "opening %ld by number (as %s)\n", ino
, name
);
2082 return lookup_one_len(name
, fset
->fset_dentry
, strlen(name
));
2085 static struct file
*presto_filp_dopen(struct dentry
*dentry
, int flags
)
2088 struct inode
*inode
;
2093 f
= get_empty_filp();
2095 CDEBUG(D_PIOCTL
, "error getting file pointer\n");
2099 f
->f_flags
= flag
= flags
;
2100 f
->f_mode
= (flag
+1) & O_ACCMODE
;
2101 inode
= dentry
->d_inode
;
2102 if (f
->f_mode
& FMODE_WRITE
) {
2103 error
= get_write_access(inode
);
2105 CDEBUG(D_PIOCTL
, "error getting write access\n");
2106 EXIT
; goto cleanup_file
;
2110 f
->f_dentry
= dentry
;
2115 /* XXX should we set to presto ops, or leave at cache ops? */
2116 f
->f_op
= inode
->i_fop
;
2117 if (f
->f_op
&& f
->f_op
->open
) {
2118 error
= f
->f_op
->open(inode
, f
);
2120 CDEBUG(D_PIOCTL
, "error calling cache 'open'\n");
2125 f
->f_flags
&= ~(O_CREAT
| O_EXCL
| O_NOCTTY
| O_TRUNC
);
2130 if (f
->f_mode
& FMODE_WRITE
)
2131 put_write_access(inode
);
2135 return ERR_PTR(error
);
2139 /* Open an inode by number. We pass in the cache root name (or a subdirectory
2140 * from the cache that is guaranteed to exist) to be able to access the cache.
2142 int lento_iopen(const char *name
, ino_t ino
, unsigned int generation
,
2146 struct dentry
*dentry
;
2147 struct nameidata nd
;
2153 "open %s:inode %#lx (%ld), generation %x (%d), flags %d \n",
2154 name
, ino
, ino
, generation
, generation
, flags
);
2155 /* We don't allow creation of files by number only, as it would
2156 * lead to a dangling files not in any directory. We could also
2157 * just turn off the flag and ignore it.
2159 if (flags
& O_CREAT
) {
2160 CERROR("%s: create file by inode number (%ld) not allowed\n",
2166 tmp
= getname(name
);
2169 return PTR_ERR(tmp
);
2173 again
: /* look the named file or a parent directory so we can get the cache */
2174 error
= presto_walk(tmp
, &nd
);
2175 if ( error
&& error
!= -ENOENT
) {
2180 if (error
== -ENOENT
)
2185 /* we didn't find the named file, so see if a parent exists */
2189 slash
= strrchr(tmp
, '/');
2190 if (slash
&& slash
!= tmp
) {
2195 /* we should never get here... */
2196 CDEBUG(D_PIOCTL
, "no more path components to try!\n");
2200 CDEBUG(D_PIOCTL
, "returned dentry %p\n", dentry
);
2202 dentry
= presto_iopen(dentry
, ino
, generation
);
2203 fd
= PTR_ERR(dentry
);
2204 if (IS_ERR(dentry
)) {
2209 /* XXX start of code that might be replaced by something like:
2210 * if (flags & (O_WRONLY | O_RDWR)) {
2211 * error = get_write_access(dentry->d_inode);
2214 * goto cleanup_dput;
2217 * fd = open_dentry(dentry, flags);
2219 * including the presto_filp_dopen() function (check dget counts!)
2221 fd
= get_unused_fd();
2229 struct file
* f
= presto_filp_dopen(dentry
, flags
);
2239 /* end of code that might be replaced by open_dentry */
2253 #ifdef CONFIG_FS_EXT_ATTR
2255 #if 0 /* was a broken check for Posix ACLs */
2256 /* Posix ACL code changes i_mode without using a notify_change (or
2257 * a mark_inode_dirty!). We need to duplicate this at the reintegrator
2258 * which is done by this function. This function also takes care of
2259 * resetting the cached posix acls in this inode. If we don't reset these
2260 * VFS continues using the old acl information, which by now may be out of
2263 int presto_setmode(struct presto_file_set
*fset
, struct dentry
*dentry
,
2266 struct inode
*inode
= dentry
->d_inode
;
2269 /* The extended attributes for this inode were modified.
2270 * At this point we can not be sure if any of the ACL
2271 * information for this inode was updated. So we will
2272 * force VFS to reread the acls. Note that we do this
2273 * only when called from the SETEXTATTR ioctl, which is why we
2274 * do this while setting the mode of the file. Also note
2275 * that mark_inode_dirty is not be needed for i_*acl only
2276 * to force i_mode info to disk, and should be removed once
2277 * we use notify_change to update the mode.
2278 * XXX: is mode setting really needed? Just setting acl's should
2279 * be enough! VFS should change the i_mode as needed? SHP
2282 inode
->i_acl
!= POSIX_ACL_NOT_CACHED
)
2283 posix_acl_release(inode
->i_acl
);
2284 if (inode
->i_default_acl
&&
2285 inode
->i_default_acl
!= POSIX_ACL_NOT_CACHED
)
2286 posix_acl_release(inode
->i_default_acl
);
2287 inode
->i_acl
= POSIX_ACL_NOT_CACHED
;
2288 inode
->i_default_acl
= POSIX_ACL_NOT_CACHED
;
2289 inode
->i_mode
= mode
;
2290 /* inode should already be dirty...but just in case */
2291 mark_inode_dirty(inode
);
2295 /* XXX: The following code is the preferred way to set mode,
2296 * however, I need to carefully go through possible recursion
2297 * paths back into presto. See comments in presto_do_setattr.
2301 struct super_operations
*sops
;
2304 iattr
.ia_mode
= mode
;
2305 iattr
.ia_valid
= ATTR_MODE
|ATTR_FORCE
;
2308 sops
= filter_c2csops(fset
->fset_cache
->cache_filter
);
2310 !sops
->notify_change
) {
2315 error
= sops
->notify_change(dentry
, &iattr
);
2324 /* setextattr Interface to cache filesystem */
2325 int presto_do_set_ext_attr(struct presto_file_set
*fset
,
2326 struct dentry
*dentry
,
2327 const char *name
, void *buffer
,
2328 size_t buffer_len
, int flags
, mode_t
*mode
,
2329 struct lento_vfs_context
*info
)
2331 struct rec_info rec
;
2332 struct inode
*inode
= dentry
->d_inode
;
2333 struct inode_operations
*iops
;
2335 struct presto_version ver
;
2337 char temp
[PRESTO_EXT_ATTR_NAME_MAX
+1];
2341 if (IS_RDONLY(inode
)) {
2346 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
)) {
2351 presto_getversion(&ver
, inode
);
2353 /* We need to invoke different filters based on whether
2354 * this dentry is a regular file, directory or symlink.
2356 switch (inode
->i_mode
& S_IFMT
) {
2357 case S_IFLNK
: /* symlink */
2358 iops
= filter_c2csiops(fset
->fset_cache
->cache_filter
);
2360 case S_IFDIR
: /* directory */
2361 iops
= filter_c2cdiops(fset
->fset_cache
->cache_filter
);
2364 default: /* everything else including regular files */
2365 iops
= filter_c2cfiops(fset
->fset_cache
->cache_filter
);
2368 if (!iops
&& !iops
->set_ext_attr
) {
2373 error
= presto_reserve_space(fset
->fset_cache
, PRESTO_REQHIGH
);
2380 handle
= presto_trans_start(fset
,dentry
->d_inode
,KML_OPCODE_SETEXTATTR
);
2381 if ( IS_ERR(handle
) ) {
2382 CERROR("presto_do_set_ext_attr: no space for transaction\n");
2383 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
2387 /* We first "truncate" name to the maximum allowable in presto */
2388 /* This simulates the strncpy_from_use code in fs/ext_attr.c */
2389 strncpy(temp
,name
,sizeof(temp
));
2391 /* Pass down to cache*/
2392 error
= iops
->set_ext_attr(inode
,temp
,buffer
,buffer_len
,flags
);
2398 #if 0 /* was a broken check for Posix ACLs */
2399 /* Reset mode if specified*/
2400 /* XXX: when we do native acl support, move this code out! */
2402 error
= presto_setmode(fset
, dentry
, *mode
);
2410 /* Reset ctime. Only inode change time (ctime) is affected */
2411 error
= presto_settime(fset
, NULL
, NULL
, dentry
, info
, ATTR_CTIME
);
2417 if (flags
& EXT_ATTR_FLAG_USER
) {
2418 CERROR(" USER flag passed to presto_do_set_ext_attr!\n");
2422 /* We are here, so set_ext_attr succeeded. We no longer need to keep
2423 * track of EXT_ATTR_FLAG_{EXISTS,CREATE}, instead, we will force
2424 * the attribute value during log replay. -SHP
2426 flags
&= ~(EXT_ATTR_FLAG_EXISTS
| EXT_ATTR_FLAG_CREATE
);
2428 presto_debug_fail_blkdev(fset
, KML_OPCODE_SETEXTATTR
| 0x10);
2429 if ( presto_do_kml(info
, dentry
) )
2430 error
= presto_journal_set_ext_attr
2431 (&rec
, fset
, dentry
, &ver
, name
, buffer
,
2434 presto_debug_fail_blkdev(fset
, KML_OPCODE_SETEXTATTR
| 0x20);
2435 if ( presto_do_rcvd(info
, dentry
) )
2436 error
= presto_write_last_rcvd(&rec
, fset
, info
);
2438 presto_debug_fail_blkdev(fset
, KML_OPCODE_SETEXTATTR
| 0x30);
2441 presto_release_space(fset
->fset_cache
, PRESTO_REQHIGH
);
2442 presto_trans_commit(fset
, handle
);