dir.c (47237687d73cbeae1dd7a133c3fc3d7239094568) | dir.c (d95852777bc8ba6b3ad3397d495c5f9dd8ca8383) |
---|---|
1/* 2 * linux/fs/nfs/dir.c 3 * 4 * Copyright (C) 1992 Rick Sladkey 5 * 6 * nfs directory handling functions 7 * 8 * 10 Apr 1996 Added silly rename for unlink --okir --- 97 unchanged lines hidden (view full) --- 106 .getxattr = nfs3_getxattr, 107 .setxattr = nfs3_setxattr, 108 .removexattr = nfs3_removexattr, 109}; 110#endif /* CONFIG_NFS_V3 */ 111 112#ifdef CONFIG_NFS_V4 113 | 1/* 2 * linux/fs/nfs/dir.c 3 * 4 * Copyright (C) 1992 Rick Sladkey 5 * 6 * nfs directory handling functions 7 * 8 * 10 Apr 1996 Added silly rename for unlink --okir --- 97 unchanged lines hidden (view full) --- 106 .getxattr = nfs3_getxattr, 107 .setxattr = nfs3_setxattr, 108 .removexattr = nfs3_removexattr, 109}; 110#endif /* CONFIG_NFS_V3 */ 111 112#ifdef CONFIG_NFS_V4 113 |
114static struct file *nfs_atomic_open(struct inode *, struct dentry *, 115 struct opendata *, unsigned, umode_t, 116 int *); | 114static int nfs_atomic_open(struct inode *, struct dentry *, 115 struct opendata *, unsigned, umode_t, 116 int *); |
117const struct inode_operations nfs4_dir_inode_operations = { 118 .create = nfs_create, 119 .lookup = nfs_lookup, 120 .atomic_open = nfs_atomic_open, 121 .link = nfs_link, 122 .unlink = nfs_unlink, 123 .symlink = nfs_symlink, 124 .mkdir = nfs_mkdir, --- 1257 unchanged lines hidden (view full) --- 1382} 1383 1384static int do_open(struct inode *inode, struct file *filp) 1385{ 1386 nfs_fscache_set_inode_cookie(inode, filp); 1387 return 0; 1388} 1389 | 117const struct inode_operations nfs4_dir_inode_operations = { 118 .create = nfs_create, 119 .lookup = nfs_lookup, 120 .atomic_open = nfs_atomic_open, 121 .link = nfs_link, 122 .unlink = nfs_unlink, 123 .symlink = nfs_symlink, 124 .mkdir = nfs_mkdir, --- 1257 unchanged lines hidden (view full) --- 1382} 1383 1384static int do_open(struct inode *inode, struct file *filp) 1385{ 1386 nfs_fscache_set_inode_cookie(inode, filp); 1387 return 0; 1388} 1389 |
1390static struct file *nfs_finish_open(struct nfs_open_context *ctx, 1391 struct dentry *dentry, 1392 struct opendata *od, unsigned open_flags, 1393 int *opened) | 1390static int nfs_finish_open(struct nfs_open_context *ctx, 1391 struct dentry *dentry, 1392 struct opendata *od, unsigned open_flags, 1393 int *opened) |
1394{ 1395 struct file *filp; 1396 int err; 1397 1398 if (ctx->dentry != dentry) { 1399 dput(ctx->dentry); 1400 ctx->dentry = dget(dentry); 1401 } 1402 1403 /* If the open_intent is for execute, we have an extra check to make */ 1404 if (ctx->mode & FMODE_EXEC) { 1405 err = nfs_may_open(dentry->d_inode, ctx->cred, open_flags); | 1394{ 1395 struct file *filp; 1396 int err; 1397 1398 if (ctx->dentry != dentry) { 1399 dput(ctx->dentry); 1400 ctx->dentry = dget(dentry); 1401 } 1402 1403 /* If the open_intent is for execute, we have an extra check to make */ 1404 if (ctx->mode & FMODE_EXEC) { 1405 err = nfs_may_open(dentry->d_inode, ctx->cred, open_flags); |
1406 if (err < 0) { 1407 filp = ERR_PTR(err); | 1406 if (err < 0) |
1408 goto out; | 1407 goto out; |
1409 } | |
1410 } 1411 1412 filp = finish_open(od, dentry, do_open, opened); | 1408 } 1409 1410 filp = finish_open(od, dentry, do_open, opened); |
1413 if (!IS_ERR(filp)) 1414 nfs_file_set_open_context(filp, ctx); | 1411 if (IS_ERR(filp)) { 1412 err = PTR_ERR(filp); 1413 goto out; 1414 } 1415 nfs_file_set_open_context(filp, ctx); 1416 err = 0; |
1415 1416out: 1417 put_nfs_open_context(ctx); | 1417 1418out: 1419 put_nfs_open_context(ctx); |
1418 return filp; | 1420 return err; |
1419} 1420 | 1421} 1422 |
1421static struct file *nfs_atomic_open(struct inode *dir, struct dentry *dentry, 1422 struct opendata *od, unsigned open_flags, 1423 umode_t mode, int *opened) | 1423static int nfs_atomic_open(struct inode *dir, struct dentry *dentry, 1424 struct opendata *od, unsigned open_flags, 1425 umode_t mode, int *opened) |
1424{ 1425 struct nfs_open_context *ctx; 1426 struct dentry *res; 1427 struct iattr attr = { .ia_valid = ATTR_OPEN }; 1428 struct inode *inode; | 1426{ 1427 struct nfs_open_context *ctx; 1428 struct dentry *res; 1429 struct iattr attr = { .ia_valid = ATTR_OPEN }; 1430 struct inode *inode; |
1429 struct file *filp; | |
1430 int err; 1431 1432 /* Expect a negative dentry */ 1433 BUG_ON(dentry->d_inode); 1434 1435 dfprintk(VFS, "NFS: atomic_open(%s/%ld), %s\n", 1436 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); 1437 1438 /* NFS only supports OPEN on regular files */ 1439 if ((open_flags & O_DIRECTORY)) { | 1431 int err; 1432 1433 /* Expect a negative dentry */ 1434 BUG_ON(dentry->d_inode); 1435 1436 dfprintk(VFS, "NFS: atomic_open(%s/%ld), %s\n", 1437 dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); 1438 1439 /* NFS only supports OPEN on regular files */ 1440 if ((open_flags & O_DIRECTORY)) { |
1440 err = -ENOENT; | |
1441 if (!d_unhashed(dentry)) { 1442 /* 1443 * Hashed negative dentry with O_DIRECTORY: dentry was 1444 * revalidated and is fine, no need to perform lookup 1445 * again 1446 */ | 1441 if (!d_unhashed(dentry)) { 1442 /* 1443 * Hashed negative dentry with O_DIRECTORY: dentry was 1444 * revalidated and is fine, no need to perform lookup 1445 * again 1446 */ |
1447 goto out_err; | 1447 return -ENOENT; |
1448 } 1449 goto no_open; 1450 } 1451 | 1448 } 1449 goto no_open; 1450 } 1451 |
1452 err = -ENAMETOOLONG; | |
1453 if (dentry->d_name.len > NFS_SERVER(dir)->namelen) | 1452 if (dentry->d_name.len > NFS_SERVER(dir)->namelen) |
1454 goto out_err; | 1453 return -ENAMETOOLONG; |
1455 1456 if (open_flags & O_CREAT) { 1457 attr.ia_valid |= ATTR_MODE; 1458 attr.ia_mode = mode & ~current_umask(); 1459 } 1460 if (open_flags & O_TRUNC) { 1461 attr.ia_valid |= ATTR_SIZE; 1462 attr.ia_size = 0; 1463 } 1464 1465 ctx = create_nfs_open_context(dentry, open_flags); 1466 err = PTR_ERR(ctx); 1467 if (IS_ERR(ctx)) | 1454 1455 if (open_flags & O_CREAT) { 1456 attr.ia_valid |= ATTR_MODE; 1457 attr.ia_mode = mode & ~current_umask(); 1458 } 1459 if (open_flags & O_TRUNC) { 1460 attr.ia_valid |= ATTR_SIZE; 1461 attr.ia_size = 0; 1462 } 1463 1464 ctx = create_nfs_open_context(dentry, open_flags); 1465 err = PTR_ERR(ctx); 1466 if (IS_ERR(ctx)) |
1468 goto out_err; | 1467 goto out; |
1469 1470 nfs_block_sillyrename(dentry->d_parent); 1471 inode = NFS_PROTO(dir)->open_context(dir, ctx, open_flags, &attr); 1472 d_drop(dentry); 1473 if (IS_ERR(inode)) { 1474 nfs_unblock_sillyrename(dentry->d_parent); 1475 put_nfs_open_context(ctx); 1476 err = PTR_ERR(inode); --- 7 unchanged lines hidden (view full) --- 1484 case -ELOOP: 1485 if (!(open_flags & O_NOFOLLOW)) 1486 goto no_open; 1487 break; 1488 /* case -EINVAL: */ 1489 default: 1490 break; 1491 } | 1468 1469 nfs_block_sillyrename(dentry->d_parent); 1470 inode = NFS_PROTO(dir)->open_context(dir, ctx, open_flags, &attr); 1471 d_drop(dentry); 1472 if (IS_ERR(inode)) { 1473 nfs_unblock_sillyrename(dentry->d_parent); 1474 put_nfs_open_context(ctx); 1475 err = PTR_ERR(inode); --- 7 unchanged lines hidden (view full) --- 1483 case -ELOOP: 1484 if (!(open_flags & O_NOFOLLOW)) 1485 goto no_open; 1486 break; 1487 /* case -EINVAL: */ 1488 default: 1489 break; 1490 } |
1492 goto out_err; | 1491 goto out; |
1493 } 1494 res = d_add_unique(dentry, inode); 1495 if (res != NULL) 1496 dentry = res; 1497 1498 nfs_unblock_sillyrename(dentry->d_parent); 1499 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1500 | 1492 } 1493 res = d_add_unique(dentry, inode); 1494 if (res != NULL) 1495 dentry = res; 1496 1497 nfs_unblock_sillyrename(dentry->d_parent); 1498 nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 1499 |
1501 filp = nfs_finish_open(ctx, dentry, od, open_flags, opened); | 1500 err = nfs_finish_open(ctx, dentry, od, open_flags, opened); |
1502 1503 dput(res); | 1501 1502 dput(res); |
1504 return filp; | 1503out: 1504 return err; |
1505 | 1505 |
1506out_err: 1507 return ERR_PTR(err); 1508 | |
1509no_open: 1510 res = nfs_lookup(dir, dentry, NULL); 1511 err = PTR_ERR(res); 1512 if (IS_ERR(res)) | 1506no_open: 1507 res = nfs_lookup(dir, dentry, NULL); 1508 err = PTR_ERR(res); 1509 if (IS_ERR(res)) |
1513 goto out_err; | 1510 goto out; |
1514 1515 finish_no_open(od, res); | 1511 1512 finish_no_open(od, res); |
1516 return NULL; | 1513 return 1; |
1517} 1518 1519static int nfs4_lookup_revalidate(struct dentry *dentry, struct nameidata *nd) 1520{ 1521 struct dentry *parent = NULL; 1522 struct inode *inode; 1523 struct inode *dir; 1524 int ret = 0; --- 775 unchanged lines hidden --- | 1514} 1515 1516static int nfs4_lookup_revalidate(struct dentry *dentry, struct nameidata *nd) 1517{ 1518 struct dentry *parent = NULL; 1519 struct inode *inode; 1520 struct inode *dir; 1521 int ret = 0; --- 775 unchanged lines hidden --- |