1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define DEBUG_SUBSYSTEM S_SM
25 #include <linux/module.h>
26 #include <linux/kernel.h>
27 #include <linux/pagemap.h>
28 #include <linux/string.h>
29 #include <linux/slab.h>
30 #include <linux/stat.h>
31 #include <linux/unistd.h>
32 #include <linux/smp_lock.h>
33 #include <linux/obd_class.h>
34 #include <linux/obd_support.h>
35 #include <linux/lustre_lib.h>
36 #include <linux/lustre_idl.h>
37 #include <linux/lustre_fsfilt.h>
39 #include <linux/lustre_snap.h>
40 #include <linux/lustre_smfs.h>
42 #include "smfs_internal.h"
43 #define SNAPTABLE_SIZE(size) (sizeof(struct snap_table) + size * sizeof(struct snap))
44 static int smfs_init_snaptabe(struct super_block *sb)
46 struct snap_info *snap_info = S2SNAPI(sb);
47 struct snap_table *snap_table = NULL;
48 struct fsfilt_operations *snapops = snap_info->snap_fsfilt;
49 struct dentry *d_root = snap_info->snap_root;
50 int rc = 0, size, table_size, vallen, i;
54 init_MUTEX(&snap_info->sntbl_sema);
55 /*Initialized table */
56 /*get the maxsize of snaptable*/
58 rc = snapops->fs_get_snap_info(d_root->d_inode, MAX_SNAPTABLE_COUNT,
59 strlen(MAX_SNAPTABLE_COUNT), &size,
62 CERROR("the Max snaptable count should not be zero\n");
66 table_size = SNAPTABLE_SIZE(size);
68 OBD_ALLOC(snap_info->sntbl, table_size);
70 if (!snap_info->sntbl) {
74 snap_table = snap_info->sntbl;
76 snap_table->sntbl_magic = cpu_to_le32((__u32)SNAPTABLE_MAGIC);
77 snap_table->sntbl_max_count = size;
78 for (i = 0; i < snap_table->sntbl_max_count; i++) {
79 /*init sn_index to -1*/
80 snap_table->sntbl_items[i].sn_index = -1;
82 /*get snaptable info*/
83 rc = snapops->fs_get_snap_info(d_root->d_inode, SNAPTABLE_INFO,
84 strlen(SNAPTABLE_INFO),
85 snap_table, &table_size);
88 snap_table->sntbl_count = 0;
89 CDEBUG(D_INFO, "No snaptable here\n");
92 CERROR("Can not retrive the snaptable from this filesystem\n");
93 OBD_FREE(snap_table, table_size);
97 if (le32_to_cpu(snap_table->sntbl_magic) != SNAPTABLE_MAGIC) {
98 CERROR("On disk snaptable is not right \n");
99 OBD_FREE(snap_table, table_size);
104 #define COWED_NAME_LEN (7 + 8 + 1)
105 static int smfs_init_cowed_dir(struct super_block *sb, struct dentry* cowed_dir)
107 struct snap_info *snap_info = S2SNAPI(sb);
108 struct dentry *dentry = NULL;
109 struct lvfs_run_ctxt saved;
110 char name[COWED_NAME_LEN];
114 sprintf(name, ".cowed_%08x", (__u32)cowed_dir->d_inode->i_ino);
115 push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
116 dentry = simple_mkdir(cowed_dir, name, 0777, 1);
117 pop_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
118 if (IS_ERR(dentry)) {
119 rc = PTR_ERR(dentry);
120 CERROR("create cowed directory: rc = %d\n", rc);
123 snap_info->sn_cowed_dentry = dentry;
126 #define DOT_SNAP_NAME ".snap"
127 static int smfs_init_dotinfo(struct super_block *sb)
129 struct snap_info *snap_info = S2SNAPI(sb);
130 struct snap_dot_info *dot_info = NULL;
134 if (snap_info->sn_dot_info)
137 OBD_ALLOC(snap_info->sn_dot_info, sizeof(struct snap_dot_info));
139 if (!snap_info->sn_dot_info)
142 dot_info = snap_info->sn_dot_info;
144 OBD_ALLOC(dot_info->dot_name, strlen(DOT_SNAP_NAME) + 1);
146 if (!dot_info->dot_name) {
147 OBD_FREE(snap_info->sn_dot_info, sizeof(struct snap_dot_info));
150 memcpy(dot_info->dot_name, DOT_SNAP_NAME, strlen(DOT_SNAP_NAME));
152 dot_info->dot_name_len = strlen(DOT_SNAP_NAME);
153 dot_info->dot_snap_enable = 1;
158 static int smfs_cleanup_dotinfo(struct super_block *sb)
160 struct snap_info *snap_info = S2SNAPI(sb);
161 struct snap_dot_info *dot_info = NULL;
165 if (!snap_info->sn_dot_info)
168 dot_info = snap_info->sn_dot_info;
170 if (dot_info->dot_name) {
171 OBD_FREE(dot_info->dot_name, dot_info->dot_name_len + 1);
174 OBD_FREE(dot_info, sizeof(struct snap_dot_info));
179 int smfs_start_cow(struct super_block *sb)
185 /*init snap fsfilt operations*/
186 if (!S2SNAPI(sb)->snap_cache_fsfilt) {
187 char *snap_cache_ftype = NULL;
188 int tmp = strlen(S2SMI(sb)->smsi_cache_ftype) + strlen("_snap");
190 OBD_ALLOC(snap_cache_ftype, tmp + 1);
191 sprintf(snap_cache_ftype, "%s_snap", S2SMI(sb)->smsi_cache_ftype);
192 S2SNAPI(sb)->snap_cache_fsfilt = fsfilt_get_ops(snap_cache_ftype);
193 OBD_FREE(snap_cache_ftype, tmp + 1);
194 if (!S2SNAPI(sb)->snap_cache_fsfilt) {
195 CERROR("Can not get %s fsfilt ops needed by snap\n",
200 if (!S2SNAPI(sb)->snap_fsfilt) {
201 char *snap_ftype = NULL;
202 int tmp = strlen(S2SMI(sb)->smsi_ftype) + strlen("_snap");
204 OBD_ALLOC(snap_ftype, tmp + 1);
205 sprintf(snap_ftype, "%s_snap", S2SMI(sb)->smsi_ftype);
206 S2SNAPI(sb)->snap_fsfilt = fsfilt_get_ops(snap_ftype);
207 OBD_FREE(snap_ftype, tmp + 1);
208 if (!S2SNAPI(sb)->snap_fsfilt) {
209 CERROR("Can not get %s fsfilt ops needed by snap\n",
214 rc = smfs_init_snaptabe(sb);
216 CERROR("can not init snaptable rc=%d\n", rc);
219 /*init dot snap info*/
220 rc = smfs_init_dotinfo(sb);
222 CERROR("can not init dot snap info rc=%d\n", rc);
225 /*init cowed dir to put the primary cowed inode
226 *FIXME-WANGDI, later the s_root may not be the
227 *snap dir, we can indicate any dir to be cowed*/
228 rc = smfs_init_cowed_dir(sb, sb->s_root);
231 EXPORT_SYMBOL(smfs_start_cow);
232 int smfs_stop_cow(struct super_block *sb)
234 struct snap_info *snap_info = S2SNAPI(sb);
235 struct snap_table *snap_table = snap_info->sntbl;
236 int rc = 0, table_size;
239 l_dput(snap_info->sn_cowed_dentry);
241 if (snap_info->snap_fsfilt)
242 fsfilt_put_ops(snap_info->snap_fsfilt);
243 if (snap_info->snap_cache_fsfilt)
244 fsfilt_put_ops(snap_info->snap_cache_fsfilt);
247 table_size = SNAPTABLE_SIZE(snap_table->sntbl_max_count);
248 OBD_FREE(snap_info->sntbl, table_size);
250 smfs_cleanup_dotinfo(sb);
254 EXPORT_SYMBOL(smfs_stop_cow);
256 #define COW_HOOK "cow_hook"
257 static int smfs_cow_pre_hook(struct inode *inode, struct dentry *dentry,
258 void *data1, void *data2, int op, void *handle)
263 if (smfs_do_cow(inode)) {
264 rc = smfs_cow(inode, dentry, data1, data2, op);
268 int smfs_cow_init(struct super_block *sb)
270 struct smfs_super_info *smfs_info = S2SMI(sb);
271 struct smfs_hook_ops *cow_hops = NULL;
276 SMFS_SET_COW(smfs_info);
278 cow_hops = smfs_alloc_hook_ops(COW_HOOK, smfs_cow_pre_hook, NULL);
283 rc = smfs_register_hook_ops(sb, cow_hops);
286 smfs_free_hook_ops(cow_hops);
290 OBD_ALLOC(smfs_info->smsi_snap_info, sizeof(struct snap_info));
292 if (!smfs_info->smsi_snap_info)
293 GOTO(exit, rc = -ENOMEM);
295 if (rc && cow_hops) {
296 smfs_unregister_hook_ops(sb, cow_hops->smh_name);
297 smfs_free_hook_ops(cow_hops);
302 int smfs_cow_cleanup(struct super_block *sb)
305 struct snap_info *snap_info = S2SNAPI(sb);
306 struct smfs_hook_ops *cow_hops;
309 cow_hops = smfs_unregister_hook_ops(sb, COW_HOOK);
310 smfs_free_hook_ops(cow_hops);
312 SMFS_CLEAN_COW(S2SMI(sb));
314 OBD_FREE(snap_info, sizeof(*snap_info));
318 /*FIXME Note indirect and primary inode
319 * should be recorgnized here*/
320 int smfs_init_snap_inode_info(struct inode *inode, int flags)
325 if (SMFS_DO_COW(S2SMI(inode->i_sb)) &&
326 (flags & SM_DO_COW)) {
327 struct snap_inode_info *sni_info = I2SNAPI(inode);
328 struct fsfilt_operations *snapops = I2SNAPOPS(inode);
330 sni_info->sn_flags = flags;
331 vallen = sizeof(sni_info->sn_gen);
333 rc = snapops->fs_get_snap_info(inode, SNAP_GENERATION,
334 strlen(SNAP_GENERATION),
335 &sni_info->sn_gen, &vallen);
340 /* latest snap: returns
341 - the index of the latest snapshot before NOW
342 - hence it returns 0 in case all the volume snapshots lie in the future
343 - this is the index where a COW will land (will be created)
345 void snap_last(struct super_block *sb, struct snap *snap)
347 struct snap_info *snap_info = S2SNAPI(sb);
348 struct snap_table *table = snap_info->sntbl;
349 time_t now = CURRENT_TIME;
353 /* start at the highest index in the superblock snaptime array */
354 if (table->sntbl_count == 0) {
355 memset(snap, 0, sizeof(struct snap));
357 i = table->sntbl_count - 1;
358 snap->sn_index = table->sntbl_items[i].sn_index;
359 snap->sn_time = table->sntbl_items[i].sn_time;
360 snap->sn_gen = table->sntbl_items[i].sn_gen;
362 CDEBUG(D_INFO, "index: %d, time[i]: %ld, now: %ld\n",
363 snap->sn_index, snap->sn_time, now);
368 static int inline get_index_of_item(struct snap_table *table, char *name)
370 int count = table->sntbl_count;
374 for (i = 0; i < table->sntbl_max_count; i++) {
375 if (!strcmp(name, table->sntbl_items[i].sn_name)) {
376 CERROR("Duplicate name %s in snaptable\n", name);
381 for (i = 0; i < table->sntbl_max_count; i++) {
383 for (j = 0; j < (count + 1); j++) {
384 if (table->sntbl_items[j].sn_index == i) {
392 CERROR("snaptable Full\n");
396 int smfs_add_snap_item(struct super_block *sb, char *name)
398 struct snap_info *snap_info = S2SNAPI(sb);
399 struct fsfilt_operations *snapops = snap_info->snap_fsfilt;
400 struct snap_table *snap_table = snap_info->sntbl;
401 struct dentry *d_root = snap_info->snap_root;
402 struct snap *snap_item;
403 int table_size, count = 0, index = 0, rc = 0;
405 count = snap_table->sntbl_count;
406 /* XXX Is down this sema necessary*/
407 down_interruptible(&snap_info->sntbl_sema);
408 snap_item = &snap_table->sntbl_items[count];
410 /*add item in snap_table set generation*/
411 snap_item->sn_time = CURRENT_TIME;
412 /* find table index */
413 index = get_index_of_item(snap_table, name);
415 GOTO(exit, rc = index);
417 snap_item->sn_index = index;
418 snap_item->sn_flags = 0;
419 snap_item->sn_gen = snap_table->sntbl_generation + 1;
420 memcpy(snap_item->sn_name, name, SNAP_MAX_NAMELEN);
421 /* Wrote the whole snap_table to disk */
422 table_size = SNAPTABLE_SIZE(snap_table->sntbl_max_count);
424 rc = snapops->fs_set_snap_info(d_root->d_inode, SNAPTABLE_INFO,
425 strlen(SNAPTABLE_INFO),
426 snap_table, &table_size);
428 CERROR("Set snaptable error rc=%d\n", rc);
431 snap_table->sntbl_count++;
432 snap_table->sntbl_generation++;
434 up(&snap_info->sntbl_sema);
437 EXPORT_SYMBOL(smfs_add_snap_item);
439 * Note: this function should be differnet with snap_do_cow.
440 * In smfs_do_cow, we check the EA for whether do cow for that inode.
441 * In smfs_needs_cow, we check whether we do need to do cow.
443 int smfs_needs_cow(struct inode *inode)
445 struct smfs_inode_info *smi_info = I2SMI(inode);
446 struct snap_inode_info *snap_info = NULL;
451 snap_info = &(smi_info->sm_sninfo);
453 snap_last(inode->i_sb, &snap);
454 /* decision .... if the snapshot is more recent than the object,
455 * then any change to the object should cause a COW.
457 if (snap_info->sn_gen < snap.sn_gen )
458 index = snap.sn_index;
460 CDEBUG(D_INFO, "snap_needs_cow, ino %lu , get index %d\n",
461 inode->i_ino, index);
464 } /* snap_needs_cow */
466 static int link_cowed_inode(struct inode *inode)
468 struct snap_info *snap_info = S2SNAPI(inode->i_sb);
469 struct dentry *cowed_dir = NULL;
470 char fidname[LL_FID_NAMELEN];
471 int fidlen = 0, rc = 0;
472 struct dentry *dchild = NULL;
473 struct dentry *tmp = NULL;
476 cowed_dir = snap_info->sn_cowed_dentry;
478 fidlen = ll_fid2str(fidname, inode->i_ino, inode->i_generation);
480 down(&cowed_dir->d_inode->i_sem);
481 dchild = ll_lookup_one_len(fidname, cowed_dir, fidlen);
482 if (IS_ERR(dchild)) {
483 rc = PTR_ERR(dchild);
484 if (rc != -EPERM && rc != -EACCES)
485 CERROR("child lookup error %d\n", rc);
488 if (dchild->d_inode != NULL) {
489 CERROR("re-cowed file %s?\n", dchild->d_name.name);
490 LASSERT(dchild->d_inode == inode);
491 GOTO(out_dput, rc = 0);
493 tmp = pre_smfs_dentry(NULL, inode, cowed_dir);
494 /* link() is semanticaly-wrong for S_IFDIR, so we set S_IFREG
495 * for linking and return real mode back then -bzzz */
496 mode = inode->i_mode;
497 inode->i_mode = S_IFREG;
498 rc = vfs_link(tmp, cowed_dir->d_inode, dchild);
499 post_smfs_dentry(tmp);
501 CERROR("error linking cowed inode %s to COWED: rc = %d\n",
504 inode->i_mode = mode;
505 if ((mode & S_IFMT) == S_IFDIR) {
506 dchild->d_inode->i_nlink++;
507 cowed_dir->d_inode->i_nlink++;
509 mark_inode_dirty(dchild->d_inode);
513 up(&cowed_dir->d_inode->i_sem);
517 * Make a copy of the data and plug a redirector in between if there
518 * is no redirector yet.
520 int snap_do_cow(struct inode *inode, struct dentry *dparent, int del)
522 struct snap_info *snap_info = S2SNAPI(inode->i_sb);
523 struct fsfilt_operations *snapops = snap_info->snap_fsfilt;
525 struct inode *ind = NULL;
529 if (!snapops || !snapops->fs_create_indirect)
532 snap_last(inode->i_sb, &snap);
533 ind = snapops->fs_create_indirect(inode, snap.sn_index, snap.sn_gen,
534 dparent->d_inode, del);
535 if(ind && IS_ERR(ind)) {
536 CERROR("Create ind inode %lu index %d gen %d del %d\n rc%u\n",
537 inode->i_ino, snap.sn_index, snap.sn_gen, del,
539 RETURN(PTR_ERR(ind));
542 if (!SMFS_DO_INODE_COWED(inode)) {
543 /*insert the inode to cowed inode*/
544 SMFS_SET_INODE_COWED(inode);
545 link_cowed_inode(inode);
548 I2SMI(ind)->sm_sninfo.sn_flags = 0;
549 I2SMI(ind)->sm_sninfo.sn_gen = snap.sn_gen;
555 /*Dir inode will do cow*/
556 int smfs_cow_create(struct inode *dir, struct dentry *dentry,
557 void *data1, void *data2)
560 struct dentry *dparent;
563 if (smfs_needs_cow(dir) != -1) {
564 CDEBUG(D_INODE, "snap_needs_cow for ino %lu \n",dir->i_ino);
565 LASSERT(dentry->d_parent && dentry->d_parent->d_parent);
566 dparent = dentry->d_parent->d_parent;
567 if ((rc = snap_do_cow(dir, dparent, 0))) {
568 CERROR("Do cow error %d\n", rc);
575 int smfs_cow_setattr(struct inode *dir, struct dentry *dentry,
576 void *data1, void *data2)
580 if (smfs_needs_cow(dir) != -1) {
581 CDEBUG(D_INODE, "snap_needs_cow for ino %lu \n",dir->i_ino);
582 if ((snap_do_cow(dir, dentry->d_parent, 0))) {
583 CERROR("Do cow error\n");
590 int smfs_cow_link(struct inode *dir, struct dentry *dentry,
591 void *data1, void *data2)
594 struct dentry *dparent;
597 if (smfs_needs_cow(dir) != -1) {
598 CDEBUG(D_INODE, "snap_needs_cow for ino %lu \n",dir->i_ino);
599 LASSERT(dentry->d_parent && dentry->d_parent->d_parent);
600 dparent = dentry->d_parent->d_parent;
601 if ((snap_do_cow(dir, dparent, 0))) {
602 CERROR("Do cow error\n");
605 if ((snap_do_cow(dentry->d_inode, dentry->d_parent, 0))) {
606 CERROR("Do cow error\n");
613 int smfs_cow_unlink(struct inode *dir, struct dentry *dentry,
614 void *data1, void *data2)
616 struct dentry *dparent;
620 if (smfs_needs_cow(dir) != -1) {
621 CDEBUG(D_INODE, "snap_needs_cow for ino %lu \n",dir->i_ino);
622 LASSERT(dentry->d_parent && dentry->d_parent->d_parent);
623 dparent = dentry->d_parent->d_parent;
624 if ((snap_do_cow(dir, dparent, 0))) {
625 CERROR("Do cow error\n");
628 if ((snap_do_cow(dentry->d_inode, dentry->d_parent, 1))) {
629 CERROR("Do cow error\n");
637 int smfs_cow_rename(struct inode *dir, struct dentry *dentry,
638 void *data1, void *data2)
640 struct inode *new_dir = (struct inode *)data1;
641 struct dentry *new_dentry = (struct dentry *)data2;
642 struct dentry *dparent;
648 if (smfs_needs_cow(dir) != -1) {
649 CDEBUG(D_INODE, "snap_needs_cow for ino %lu \n", dir->i_ino);
650 LASSERT(dentry->d_parent && dentry->d_parent->d_parent);
651 dparent = dentry->d_parent->d_parent;
652 if ((snap_do_cow(dir, dparent, 0))) {
653 CERROR("Do cow error\n");
656 if ((snap_do_cow(dentry->d_inode, dentry->d_parent, 0))) {
657 CERROR("Do cow error\n");
661 if (smfs_needs_cow(new_dir) != -1) {
662 CDEBUG(D_INODE, "snap_needs_cow for ino %lu \n", new_dir->i_ino);
663 LASSERT(new_dentry->d_parent && new_dentry->d_parent->d_parent);
664 dparent = new_dentry->d_parent->d_parent;
665 if ((new_dir != dir) && (snap_do_cow(new_dir, dparent, 0))){
666 CERROR("Do cow error\n");
669 if (new_dentry->d_inode && new_dentry->d_inode->i_nlink == 1) {
670 if ((snap_do_cow(new_dentry->d_inode,
671 new_dentry->d_parent, 0))) {
672 CERROR("Do cow error\n");
680 int smfs_cow_write(struct inode *inode, struct dentry *dentry, void *data1,
683 struct snap_info *snap_info = S2SNAPI(inode->i_sb);
684 struct snap_table *table = snap_info->sntbl;
685 long blocks[2]={-1,-1};
686 int index = 0, i, rc = 0;
695 count = *(size_t *)data1;
696 pos = *(loff_t*)data2;
700 if (smfs_needs_cow(inode) != -1 ) {
701 CDEBUG(D_INFO, "snap_needs_cow for ino %lu \n",inode->i_ino);
702 snap_do_cow(inode, dentry->d_parent, 0);
705 CDEBUG(D_INFO, "write offset %lld count %u \n", pos, count);
707 if(pos & (PAGE_CACHE_SIZE - 1)){
708 blocks[0] = pos >> inode->i_sb->s_blocksize_bits;
711 if((pos + 1) & (PAGE_CACHE_SIZE - 1)){
712 blocks[1] = pos >> inode->i_sb->s_blocksize_bits;
715 if (blocks[0] == blocks[1])
718 for (i = 0; i < 2; i++) {
722 /*Find the nearest page in snaptable and copy back it*/
723 for (slot = table->sntbl_count - 1; slot >= 0; slot--) {
724 struct fsfilt_operations *snapops = snap_info->snap_fsfilt;
725 struct inode *cache_inode = NULL;
728 index = table->sntbl_items[slot].sn_index;
729 cache_inode = snapops->fs_get_indirect(inode, NULL, index);
731 if (!cache_inode) continue;
733 CDEBUG(D_INFO, "find cache_ino %lu\n", cache_inode->i_ino);
735 result = snapops->fs_copy_block(inode, cache_inode, blocks[i]);
744 GOTO(exit, rc = result);
753 EXPORT_SYMBOL(smfs_cow_write);
755 int smfs_cow_lookup(struct inode *inode, struct dentry *dentry, void *data1,
758 struct snap_info *snap_info = S2SNAPI(inode->i_sb);
759 struct fsfilt_operations *snapops = snap_info->snap_fsfilt;
760 struct dentry *dparent = dentry->d_parent;
761 struct clonefs_info *clone_info=(struct clonefs_info*)dparent->d_fsdata;
764 if (clone_info && clone_info->clone_flags && SM_CLONE_FS) {
765 struct inode *ind_inode = NULL;
766 struct inode *cache_ind = NULL;
767 struct dentry *cache_dentry = NULL;
768 struct dentry *cache_parent = NULL;
769 struct inode *cache_inode;
773 ind_inode = snapops->fs_get_indirect(inode, NULL, clone_info->clone_index);
777 if (!(cache_ind = I2CI(ind_inode)))
778 GOTO(exit, rc = -ENOENT);
780 cache_parent=pre_smfs_dentry(NULL, cache_ind, dentry->d_parent);
781 cache_dentry=pre_smfs_dentry(cache_parent, NULL, dentry);
783 tmp = cache_ind->i_op->lookup(cache_ind, cache_dentry);
786 GOTO(exit, rc = -ENOENT);
788 if ((cache_inode = tmp ? tmp->d_inode : cache_dentry->d_inode)) {
789 if (IS_ERR(cache_inode)) {
790 dentry->d_inode = cache_inode;
791 GOTO(exit, rc = -ENOENT);
793 inode = iget4(inode->i_sb, cache_inode->i_ino, NULL,
794 &I2SMI(inode)->smi_flags);
797 GOTO(exit, rc = -ENOENT);
799 d_add(dentry, inode);
802 post_smfs_dentry(cache_dentry);
803 post_smfs_dentry(cache_parent);
809 struct inode *smfs_cow_get_ind(struct inode *inode, int index)
811 struct snap_info *snap_info = S2SNAPI(inode->i_sb);
812 struct fsfilt_operations *snapops = snap_info->snap_fsfilt;
813 struct snap_table *table = snap_info->sntbl;
814 long block=(index << PAGE_CACHE_SHIFT) >> inode->i_sb->s_blocksize_bits;
818 for (slot = table->sntbl_count - 1; slot >= 0; slot--) {
819 struct address_space_operations *aops = inode->i_mapping->a_ops;
820 struct inode *cache_inode = NULL;
823 index = table->sntbl_items[slot].sn_index;
824 cache_inode = snapops->fs_get_indirect(inode, NULL, index);
826 if (!cache_inode ) continue;
828 if (aops->bmap(cache_inode->i_mapping, block))
835 EXPORT_SYMBOL(smfs_cow_get_ind);
837 typedef int (*cow_funcs)(struct inode *dir, struct dentry *dentry,
838 void *new_dir, void *new_dentry);
840 static cow_funcs smfs_cow_funcs[HOOK_MAX + 1] = {
841 [HOOK_CREATE] smfs_cow_create,
842 [HOOK_LOOKUP] smfs_cow_lookup,
843 [HOOK_LINK] smfs_cow_link,
844 [HOOK_UNLINK] smfs_cow_unlink,
845 [HOOK_SYMLINK] smfs_cow_create,
846 [HOOK_MKDIR] smfs_cow_create,
847 [HOOK_RMDIR] smfs_cow_unlink,
848 [HOOK_MKNOD] smfs_cow_create,
849 [HOOK_RENAME] smfs_cow_rename,
850 [HOOK_SETATTR] smfs_cow_setattr,
851 [HOOK_WRITE] smfs_cow_write,
854 int smfs_cow(struct inode *dir, struct dentry *dentry, void *new_dir,
855 void *new_dentry, int op)
857 if (smfs_cow_funcs[op]) {
858 return smfs_cow_funcs[op](dir, dentry, new_dir, new_dentry);