dir.c 15.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14

/*
 * Directory operations for Coda filesystem
 * Original version: (C) 1996 P. Braam and M. Callahan
 * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
 * 
 * Carnegie Mellon encourages users to contribute improvements to
 * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
 */

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/time.h>
#include <linux/fs.h>
15
#include <linux/slab.h>
L
Linus Torvalds 已提交
16 17 18 19
#include <linux/file.h>
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/string.h>
20
#include <linux/spinlock.h>
21
#include <linux/namei.h>
F
Fabian Frederick 已提交
22
#include <linux/uaccess.h>
L
Linus Torvalds 已提交
23 24 25

#include <linux/coda.h>
#include <linux/coda_psdev.h>
26 27
#include "coda_linux.h"
#include "coda_cache.h"
L
Linus Torvalds 已提交
28

29 30
#include "coda_int.h"

L
Linus Torvalds 已提交
31
/* dir inode-ops */
A
Al Viro 已提交
32
static int coda_create(struct inode *dir, struct dentry *new, umode_t mode, bool excl);
A
Al Viro 已提交
33
static struct dentry *coda_lookup(struct inode *dir, struct dentry *target, unsigned int flags);
L
Linus Torvalds 已提交
34 35 36 37 38
static int coda_link(struct dentry *old_dentry, struct inode *dir_inode, 
		     struct dentry *entry);
static int coda_unlink(struct inode *dir_inode, struct dentry *entry);
static int coda_symlink(struct inode *dir_inode, struct dentry *entry,
			const char *symname);
39
static int coda_mkdir(struct inode *dir_inode, struct dentry *entry, umode_t mode);
L
Linus Torvalds 已提交
40 41 42 43 44
static int coda_rmdir(struct inode *dir_inode, struct dentry *entry);
static int coda_rename(struct inode *old_inode, struct dentry *old_dentry, 
                       struct inode *new_inode, struct dentry *new_dentry);

/* dir file-ops */
A
Al Viro 已提交
45
static int coda_readdir(struct file *file, struct dir_context *ctx);
L
Linus Torvalds 已提交
46 47

/* dentry ops */
48
static int coda_dentry_revalidate(struct dentry *de, unsigned int flags);
N
Nick Piggin 已提交
49
static int coda_dentry_delete(const struct dentry *);
L
Linus Torvalds 已提交
50 51

/* support routines */
A
Al Viro 已提交
52
static int coda_venus_readdir(struct file *, struct dir_context *);
L
Linus Torvalds 已提交
53 54 55 56 57 58 59 60

/* same as fs/bad_inode.c */
static int coda_return_EIO(void)
{
	return -EIO;
}
#define CODA_EIO_ERROR ((void *) (coda_return_EIO))

A
Al Viro 已提交
61
const struct dentry_operations coda_dentry_operations =
L
Linus Torvalds 已提交
62 63 64 65 66
{
	.d_revalidate	= coda_dentry_revalidate,
	.d_delete	= coda_dentry_delete,
};

67
const struct inode_operations coda_dir_inode_operations =
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
{
	.create		= coda_create,
	.lookup		= coda_lookup,
	.link		= coda_link,
	.unlink		= coda_unlink,
	.symlink	= coda_symlink,
	.mkdir		= coda_mkdir,
	.rmdir		= coda_rmdir,
	.mknod		= CODA_EIO_ERROR,
	.rename		= coda_rename,
	.permission	= coda_permission,
	.getattr	= coda_getattr,
	.setattr	= coda_setattr,
};

83
const struct file_operations coda_dir_operations = {
L
Linus Torvalds 已提交
84 85
	.llseek		= generic_file_llseek,
	.read		= generic_read_dir,
A
Al Viro 已提交
86
	.iterate	= coda_readdir,
L
Linus Torvalds 已提交
87 88 89 90 91 92 93 94
	.open		= coda_open,
	.release	= coda_release,
	.fsync		= coda_fsync,
};


/* inode operations for directories */
/* access routines: lookup, readlink, permission */
A
Al Viro 已提交
95
static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, unsigned int flags)
L
Linus Torvalds 已提交
96
{
97
	struct super_block *sb = dir->i_sb;
L
Linus Torvalds 已提交
98 99
	const char *name = entry->d_name.name;
	size_t length = entry->d_name.len;
100 101
	struct inode *inode;
	int type = 0;
102 103

	if (length > CODA_MAXNAMLEN) {
104
		pr_err("name too long: lookup, %s (%*s)\n",
L
Linus Torvalds 已提交
105 106 107 108
		       coda_i2s(dir), (int)length, name);
		return ERR_PTR(-ENAMETOOLONG);
	}

109
	/* control object, create inode on the fly */
A
Al Viro 已提交
110
	if (is_root_inode(dir) && coda_iscontrol(name, length)) {
111
		inode = coda_cnode_makectl(sb);
112
		type = CODA_NOCACHE;
113 114 115 116 117
	} else {
		struct CodaFid fid = { { 0, } };
		int error = venus_lookup(sb, coda_i2f(dir), name, length,
				     &type, &fid);
		inode = !error ? coda_cnode_make(&fid, sb) : ERR_PTR(error);
118 119
	}

120
	if (!IS_ERR(inode) && (type & CODA_NOCACHE))
121 122
		coda_flag_inode(inode, C_VATTR | C_PURGE);

123 124 125
	if (inode == ERR_PTR(-ENOENT))
		inode = NULL;

126
	return d_splice_alias(inode, entry);
L
Linus Torvalds 已提交
127 128 129
}


130
int coda_permission(struct inode *inode, int mask)
L
Linus Torvalds 已提交
131
{
132
	int error;
133

134
	if (mask & MAY_NOT_BLOCK)
135 136
		return -ECHILD;

137
	mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
L
Linus Torvalds 已提交
138 139
 
	if (!mask)
140
		return 0;
L
Linus Torvalds 已提交
141

142 143 144
	if ((mask & MAY_EXEC) && !execute_ok(inode))
		return -EACCES;

L
Linus Torvalds 已提交
145
	if (coda_cache_check(inode, mask))
146
		return 0;
L
Linus Torvalds 已提交
147

148
	error = venus_access(inode->i_sb, coda_i2f(inode), mask);
L
Linus Torvalds 已提交
149 150 151 152
    
	if (!error)
		coda_cache_enter(inode, mask);

153
	return error;
L
Linus Torvalds 已提交
154 155 156
}


157
static inline void coda_dir_update_mtime(struct inode *dir)
L
Linus Torvalds 已提交
158 159 160 161 162 163 164
{
#ifdef REQUERY_VENUS_FOR_MTIME
	/* invalidate the directory cnode's attributes so we refetch the
	 * attributes from venus next time the inode is referenced */
	coda_flag_inode(dir, C_VATTR);
#else
	/* optimistically we can also act as if our nose bleeds. The
165 166
	 * granularity of the mtime is coarse anyways so we might actually be
	 * right most of the time. Note: we only do this for directories. */
L
Linus Torvalds 已提交
167 168
	dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
#endif
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
}

/* we have to wrap inc_nlink/drop_nlink because sometimes userspace uses a
 * trick to fool GNU find's optimizations. If we can't be sure of the link
 * (because of volume mount points) we set i_nlink to 1 which forces find
 * to consider every child as a possible directory. We should also never
 * see an increment or decrement for deleted directories where i_nlink == 0 */
static inline void coda_dir_inc_nlink(struct inode *dir)
{
	if (dir->i_nlink >= 2)
		inc_nlink(dir);
}

static inline void coda_dir_drop_nlink(struct inode *dir)
{
	if (dir->i_nlink > 2)
		drop_nlink(dir);
L
Linus Torvalds 已提交
186 187 188
}

/* creation routines: create, mknod, mkdir, link, symlink */
A
Al Viro 已提交
189
static int coda_create(struct inode *dir, struct dentry *de, umode_t mode, bool excl)
L
Linus Torvalds 已提交
190
{
191
	int error;
L
Linus Torvalds 已提交
192 193 194 195 196 197
	const char *name=de->d_name.name;
	int length=de->d_name.len;
	struct inode *inode;
	struct CodaFid newfid;
	struct coda_vattr attrs;

A
Al Viro 已提交
198
	if (is_root_inode(dir) && coda_iscontrol(name, length))
L
Linus Torvalds 已提交
199 200 201 202
		return -EPERM;

	error = venus_create(dir->i_sb, coda_i2f(dir), name, length, 
				0, mode, &newfid, &attrs);
203 204
	if (error)
		goto err_out;
L
Linus Torvalds 已提交
205 206

	inode = coda_iget(dir->i_sb, &newfid, &attrs);
207 208 209
	if (IS_ERR(inode)) {
		error = PTR_ERR(inode);
		goto err_out;
L
Linus Torvalds 已提交
210 211 212
	}

	/* invalidate the directory cnode's attributes */
213
	coda_dir_update_mtime(dir);
L
Linus Torvalds 已提交
214
	d_instantiate(de, inode);
215
	return 0;
216 217 218
err_out:
	d_drop(de);
	return error;
L
Linus Torvalds 已提交
219 220
}

221
static int coda_mkdir(struct inode *dir, struct dentry *de, umode_t mode)
L
Linus Torvalds 已提交
222 223 224 225 226 227 228 229
{
	struct inode *inode;
	struct coda_vattr attrs;
	const char *name = de->d_name.name;
	int len = de->d_name.len;
	int error;
	struct CodaFid newfid;

A
Al Viro 已提交
230
	if (is_root_inode(dir) && coda_iscontrol(name, len))
L
Linus Torvalds 已提交
231 232 233 234 235
		return -EPERM;

	attrs.va_mode = mode;
	error = venus_mkdir(dir->i_sb, coda_i2f(dir), 
			       name, len, &newfid, &attrs);
236 237
	if (error)
		goto err_out;
L
Linus Torvalds 已提交
238 239
         
	inode = coda_iget(dir->i_sb, &newfid, &attrs);
240 241 242
	if (IS_ERR(inode)) {
		error = PTR_ERR(inode);
		goto err_out;
L
Linus Torvalds 已提交
243
	}
244

L
Linus Torvalds 已提交
245
	/* invalidate the directory cnode's attributes */
246 247
	coda_dir_inc_nlink(dir);
	coda_dir_update_mtime(dir);
L
Linus Torvalds 已提交
248
	d_instantiate(de, inode);
249
	return 0;
250 251 252
err_out:
	d_drop(de);
	return error;
L
Linus Torvalds 已提交
253 254 255 256 257 258 259 260 261 262 263
}

/* try to make de an entry in dir_inodde linked to source_de */ 
static int coda_link(struct dentry *source_de, struct inode *dir_inode, 
	  struct dentry *de)
{
	struct inode *inode = source_de->d_inode;
        const char * name = de->d_name.name;
	int len = de->d_name.len;
	int error;

A
Al Viro 已提交
264
	if (is_root_inode(dir_inode) && coda_iscontrol(name, len))
L
Linus Torvalds 已提交
265 266 267 268
		return -EPERM;

	error = venus_link(dir_inode->i_sb, coda_i2f(inode),
			   coda_i2f(dir_inode), (const char *)name, len);
269
	if (error) {
L
Linus Torvalds 已提交
270
		d_drop(de);
271
		return error;
L
Linus Torvalds 已提交
272 273
	}

274
	coda_dir_update_mtime(dir_inode);
A
Al Viro 已提交
275
	ihold(inode);
L
Linus Torvalds 已提交
276
	d_instantiate(de, inode);
277
	inc_nlink(inode);
278
	return 0;
L
Linus Torvalds 已提交
279 280 281 282 283 284
}


static int coda_symlink(struct inode *dir_inode, struct dentry *de,
			const char *symname)
{
285
	const char *name = de->d_name.name;
L
Linus Torvalds 已提交
286 287
	int len = de->d_name.len;
	int symlen;
288
	int error;
L
Linus Torvalds 已提交
289

A
Al Viro 已提交
290
	if (is_root_inode(dir_inode) && coda_iscontrol(name, len))
L
Linus Torvalds 已提交
291 292 293
		return -EPERM;

	symlen = strlen(symname);
294
	if (symlen > CODA_MAXPATHLEN)
L
Linus Torvalds 已提交
295 296 297 298
		return -ENAMETOOLONG;

	/*
	 * This entry is now negative. Since we do not create
299
	 * an inode for the entry we have to drop it.
L
Linus Torvalds 已提交
300 301
	 */
	d_drop(de);
302
	error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len,
L
Linus Torvalds 已提交
303 304 305
			      symname, symlen);

	/* mtime is no good anymore */
306
	if (!error)
307
		coda_dir_update_mtime(dir_inode);
L
Linus Torvalds 已提交
308

309
	return error;
L
Linus Torvalds 已提交
310 311 312
}

/* destruction routines: unlink, rmdir */
313
static int coda_unlink(struct inode *dir, struct dentry *de)
L
Linus Torvalds 已提交
314 315 316 317 318
{
        int error;
	const char *name = de->d_name.name;
	int len = de->d_name.len;

319
	error = venus_remove(dir->i_sb, coda_i2f(dir), name, len);
320
	if (error)
321
		return error;
L
Linus Torvalds 已提交
322

323
	coda_dir_update_mtime(dir);
324
	drop_nlink(de->d_inode);
325
	return 0;
L
Linus Torvalds 已提交
326 327
}

328
static int coda_rmdir(struct inode *dir, struct dentry *de)
L
Linus Torvalds 已提交
329 330 331
{
	const char *name = de->d_name.name;
	int len = de->d_name.len;
332
	int error;
L
Linus Torvalds 已提交
333 334

	error = venus_rmdir(dir->i_sb, coda_i2f(dir), name, len);
335 336 337
	if (!error) {
		/* VFS may delete the child */
		if (de->d_inode)
338
			clear_nlink(de->d_inode);
L
Linus Torvalds 已提交
339

340 341 342
		/* fix the link count of the parent */
		coda_dir_drop_nlink(dir);
		coda_dir_update_mtime(dir);
343
	}
344
	return error;
L
Linus Torvalds 已提交
345 346 347
}

/* rename */
348
static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
L
Linus Torvalds 已提交
349 350
		       struct inode *new_dir, struct dentry *new_dentry)
{
351 352
	const char *old_name = old_dentry->d_name.name;
	const char *new_name = new_dentry->d_name.name;
L
Linus Torvalds 已提交
353 354
	int old_length = old_dentry->d_name.len;
	int new_length = new_dentry->d_name.len;
355
	int error;
L
Linus Torvalds 已提交
356

357 358
	error = venus_rename(old_dir->i_sb, coda_i2f(old_dir),
			     coda_i2f(new_dir), old_length, new_length,
L
Linus Torvalds 已提交
359
			     (const char *) old_name, (const char *)new_name);
360 361 362
	if (!error) {
		if (new_dentry->d_inode) {
			if (S_ISDIR(new_dentry->d_inode->i_mode)) {
363 364 365 366 367
				coda_dir_drop_nlink(old_dir);
				coda_dir_inc_nlink(new_dir);
			}
			coda_dir_update_mtime(old_dir);
			coda_dir_update_mtime(new_dir);
L
Linus Torvalds 已提交
368 369 370 371
			coda_flag_inode(new_dentry->d_inode, C_VATTR);
		} else {
			coda_flag_inode(old_dir, C_VATTR);
			coda_flag_inode(new_dir, C_VATTR);
372
		}
L
Linus Torvalds 已提交
373 374 375 376 377 378
	}
	return error;
}


/* file operations for directories */
A
Al Viro 已提交
379
static int coda_readdir(struct file *coda_file, struct dir_context *ctx)
L
Linus Torvalds 已提交
380 381 382 383 384 385 386 387 388
{
	struct coda_file_info *cfi;
	struct file *host_file;
	int ret;

	cfi = CODA_FTOC(coda_file);
	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
	host_file = cfi->cfi_container;

A
Al Viro 已提交
389
	if (host_file->f_op->iterate) {
A
Al Viro 已提交
390
		struct inode *host_inode = file_inode(host_file);
391 392 393 394 395 396 397
		mutex_lock(&host_inode->i_mutex);
		ret = -ENOENT;
		if (!IS_DEADDIR(host_inode)) {
			ret = host_file->f_op->iterate(host_file, ctx);
			file_accessed(host_file);
		}
		mutex_unlock(&host_inode->i_mutex);
A
Al Viro 已提交
398 399 400 401
		return ret;
	}
	/* Venus: we must read Venus dirents from a file */
	return coda_venus_readdir(coda_file, ctx);
L
Linus Torvalds 已提交
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
}

static inline unsigned int CDT2DT(unsigned char cdt)
{
	unsigned int dt;

	switch(cdt) {
	case CDT_UNKNOWN: dt = DT_UNKNOWN; break;
	case CDT_FIFO:	  dt = DT_FIFO;    break;
	case CDT_CHR:	  dt = DT_CHR;     break;
	case CDT_DIR:	  dt = DT_DIR;     break;
	case CDT_BLK:	  dt = DT_BLK;     break;
	case CDT_REG:	  dt = DT_REG;     break;
	case CDT_LNK:	  dt = DT_LNK;     break;
	case CDT_SOCK:	  dt = DT_SOCK;    break;
	case CDT_WHT:	  dt = DT_WHT;     break;
	default:	  dt = DT_UNKNOWN; break;
	}
	return dt;
}

/* support routines */
A
Al Viro 已提交
424
static int coda_venus_readdir(struct file *coda_file, struct dir_context *ctx)
L
Linus Torvalds 已提交
425
{
426 427 428
	struct coda_file_info *cfi;
	struct coda_inode_info *cii;
	struct file *host_file;
L
Linus Torvalds 已提交
429
	struct venus_dirent *vdir;
A
Al Viro 已提交
430
	unsigned long vdir_size = offsetof(struct venus_dirent, d_name);
L
Linus Torvalds 已提交
431 432 433
	unsigned int type;
	struct qstr name;
	ino_t ino;
434 435 436 437 438 439
	int ret;

	cfi = CODA_FTOC(coda_file);
	BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
	host_file = cfi->cfi_container;

A
Al Viro 已提交
440
	cii = ITOC(file_inode(coda_file));
L
Linus Torvalds 已提交
441

442
	vdir = kmalloc(sizeof(*vdir), GFP_KERNEL);
L
Linus Torvalds 已提交
443 444
	if (!vdir) return -ENOMEM;

A
Al Viro 已提交
445 446 447
	if (!dir_emit_dots(coda_file, ctx))
		goto out;

L
Linus Torvalds 已提交
448 449
	while (1) {
		/* read entries from the directory file */
A
Al Viro 已提交
450
		ret = kernel_read(host_file, ctx->pos - 2, (char *)vdir,
L
Linus Torvalds 已提交
451 452
				  sizeof(*vdir));
		if (ret < 0) {
F
Fabian Frederick 已提交
453 454
			pr_err("%s: read dir %s failed %d\n",
			       __func__, coda_f2s(&cii->c_fid), ret);
L
Linus Torvalds 已提交
455 456 457 458 459 460
			break;
		}
		if (ret == 0) break; /* end of directory file reached */

		/* catch truncated reads */
		if (ret < vdir_size || ret < vdir_size + vdir->d_namlen) {
F
Fabian Frederick 已提交
461 462
			pr_err("%s: short read on %s\n",
			       __func__, coda_f2s(&cii->c_fid));
L
Linus Torvalds 已提交
463 464 465 466 467
			ret = -EBADF;
			break;
		}
		/* validate whether the directory file actually makes sense */
		if (vdir->d_reclen < vdir_size + vdir->d_namlen) {
F
Fabian Frederick 已提交
468 469
			pr_err("%s: invalid dir %s\n",
			       __func__, coda_f2s(&cii->c_fid));
L
Linus Torvalds 已提交
470 471 472 473 474 475 476 477 478
			ret = -EBADF;
			break;
		}

		name.len = vdir->d_namlen;
		name.name = vdir->d_name;

		/* Make sure we skip '.' and '..', we already got those */
		if (name.name[0] == '.' && (name.len == 1 ||
A
Al Viro 已提交
479
		    (name.name[1] == '.' && name.len == 2)))
L
Linus Torvalds 已提交
480 481 482 483
			vdir->d_fileno = name.len = 0;

		/* skip null entries */
		if (vdir->d_fileno && name.len) {
484
			ino = vdir->d_fileno;
L
Linus Torvalds 已提交
485
			type = CDT2DT(vdir->d_type);
A
Al Viro 已提交
486 487
			if (!dir_emit(ctx, name.name, name.len, ino, type))
				break;
L
Linus Torvalds 已提交
488 489 490
		}
		/* we'll always have progress because d_reclen is unsigned and
		 * we've already established it is non-zero. */
A
Al Viro 已提交
491
		ctx->pos += vdir->d_reclen;
492
	}
A
Al Viro 已提交
493
out:
L
Linus Torvalds 已提交
494
	kfree(vdir);
A
Al Viro 已提交
495
	return 0;
L
Linus Torvalds 已提交
496 497 498
}

/* called when a cache lookup succeeds */
499
static int coda_dentry_revalidate(struct dentry *de, unsigned int flags)
L
Linus Torvalds 已提交
500
{
501
	struct inode *inode;
L
Linus Torvalds 已提交
502 503
	struct coda_inode_info *cii;

504
	if (flags & LOOKUP_RCU)
505 506 507
		return -ECHILD;

	inode = de->d_inode;
A
Al Viro 已提交
508
	if (!inode || is_root_inode(inode))
L
Linus Torvalds 已提交
509 510 511 512 513 514 515 516 517 518 519 520 521 522
		goto out;
	if (is_bad_inode(inode))
		goto bad;

	cii = ITOC(de->d_inode);
	if (!(cii->c_flags & (C_PURGE | C_FLUSH)))
		goto out;

	shrink_dcache_parent(de);

	/* propagate for a flush */
	if (cii->c_flags & C_FLUSH) 
		coda_flag_inode_children(inode, C_FLUSH);

A
Al Viro 已提交
523
	if (d_count(de) > 1)
L
Linus Torvalds 已提交
524 525 526 527
		/* pretend it's valid, but don't change the flags */
		goto out;

	/* clear the flags. */
528
	spin_lock(&cii->c_lock);
L
Linus Torvalds 已提交
529
	cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
530
	spin_unlock(&cii->c_lock);
L
Linus Torvalds 已提交
531 532 533 534 535 536 537 538 539 540
bad:
	return 0;
out:
	return 1;
}

/*
 * This is the callback from dput() when d_count is going to 0.
 * We use this to unhash dentries with bad inodes.
 */
N
Nick Piggin 已提交
541
static int coda_dentry_delete(const struct dentry * dentry)
L
Linus Torvalds 已提交
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
{
	int flags;

	if (!dentry->d_inode) 
		return 0;

	flags = (ITOC(dentry->d_inode)->c_flags) & C_PURGE;
	if (is_bad_inode(dentry->d_inode) || flags) {
		return 1;
	}
	return 0;
}



/*
 * This is called when we want to check if the inode has
 * changed on the server.  Coda makes this easy since the
 * cache manager Venus issues a downcall to the kernel when this 
 * happens 
 */
563
int coda_revalidate_inode(struct inode *inode)
L
Linus Torvalds 已提交
564 565
{
	struct coda_vattr attr;
566
	int error;
L
Linus Torvalds 已提交
567 568 569 570
	int old_mode;
	ino_t old_ino;
	struct coda_inode_info *cii = ITOC(inode);

571 572
	if (!cii->c_flags)
		return 0;
L
Linus Torvalds 已提交
573 574 575

	if (cii->c_flags & (C_VATTR | C_PURGE | C_FLUSH)) {
		error = venus_getattr(inode->i_sb, &(cii->c_fid), &attr);
576 577
		if (error)
			return -EIO;
L
Linus Torvalds 已提交
578 579 580 581 582 583 584 585 586 587 588

		/* this inode may be lost if:
		   - it's ino changed 
		   - type changes must be permitted for repair and
		   missing mount points.
		*/
		old_mode = inode->i_mode;
		old_ino = inode->i_ino;
		coda_vattr_to_iattr(inode, &attr);

		if ((old_mode & S_IFMT) != (inode->i_mode & S_IFMT)) {
589
			pr_warn("inode %ld, fid %s changed type!\n",
590
				inode->i_ino, coda_f2s(&(cii->c_fid)));
L
Linus Torvalds 已提交
591 592 593 594 595
		}

		/* the following can happen when a local fid is replaced 
		   with a global one, here we lose and declare the inode bad */
		if (inode->i_ino != old_ino)
596
			return -EIO;
L
Linus Torvalds 已提交
597 598
		
		coda_flag_inode_children(inode, C_FLUSH);
599 600

		spin_lock(&cii->c_lock);
L
Linus Torvalds 已提交
601
		cii->c_flags &= ~(C_VATTR | C_PURGE | C_FLUSH);
602
		spin_unlock(&cii->c_lock);
L
Linus Torvalds 已提交
603 604 605
	}
	return 0;
}