dir.c (f26e8817b235d8764363bffcc9cbfc61867371f2) dir.c (9cdd1d3f1a8cea9cfe7953f45fae9ff51c37afa3)
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

--- 421 unchanged lines hidden (view full) ---

430 if (d_really_is_negative(dentry))
431 return 0;
432
433 inode = d_inode(dentry);
434 if (is_bad_inode(inode) || NFS_STALE(inode))
435 return 0;
436
437 nfsi = NFS_I(inode);
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

--- 421 unchanged lines hidden (view full) ---

430 if (d_really_is_negative(dentry))
431 return 0;
432
433 inode = d_inode(dentry);
434 if (is_bad_inode(inode) || NFS_STALE(inode))
435 return 0;
436
437 nfsi = NFS_I(inode);
438 if (entry->fattr->fileid == nfsi->fileid)
439 return 1;
440 if (nfs_compare_fh(entry->fh, &nfsi->fh) == 0)
441 return 1;
442 return 0;
438 if (entry->fattr->fileid != nfsi->fileid)
439 return 0;
440 if (entry->fh->size && nfs_compare_fh(entry->fh, &nfsi->fh) != 0)
441 return 0;
442 return 1;
443}
444
445static
446bool nfs_use_readdirplus(struct inode *dir, struct dir_context *ctx)
447{
448 if (!nfs_server_capable(dir, NFS_CAP_READDIRPLUS))
449 return false;
450 if (test_and_clear_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(dir)->flags))
451 return true;
452 if (ctx->pos == 0)
453 return true;
454 return false;
455}
456
457/*
443}
444
445static
446bool nfs_use_readdirplus(struct inode *dir, struct dir_context *ctx)
447{
448 if (!nfs_server_capable(dir, NFS_CAP_READDIRPLUS))
449 return false;
450 if (test_and_clear_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(dir)->flags))
451 return true;
452 if (ctx->pos == 0)
453 return true;
454 return false;
455}
456
457/*
458 * This function is called by the lookup code to request the use of
459 * readdirplus to accelerate any future lookups in the same
458 * This function is called by the lookup and getattr code to request the
459 * use of readdirplus to accelerate any future lookups in the same
460 * directory.
461 */
460 * directory.
461 */
462static
463void nfs_advise_use_readdirplus(struct inode *dir)
464{
462void nfs_advise_use_readdirplus(struct inode *dir)
463{
465 set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(dir)->flags);
464 struct nfs_inode *nfsi = NFS_I(dir);
465
466 if (nfs_server_capable(dir, NFS_CAP_READDIRPLUS) &&
467 !list_empty(&nfsi->open_files))
468 set_bit(NFS_INO_ADVISE_RDPLUS, &nfsi->flags);
466}
467
468/*
469 * This function is mainly for use by nfs_getattr().
470 *
471 * If this is an 'ls -l', we want to force use of readdirplus.
472 * Do this by checking if there is an active file descriptor
473 * and calling nfs_advise_use_readdirplus, then forcing a
474 * cache flush.
475 */
476void nfs_force_use_readdirplus(struct inode *dir)
477{
469}
470
471/*
472 * This function is mainly for use by nfs_getattr().
473 *
474 * If this is an 'ls -l', we want to force use of readdirplus.
475 * Do this by checking if there is an active file descriptor
476 * and calling nfs_advise_use_readdirplus, then forcing a
477 * cache flush.
478 */
479void nfs_force_use_readdirplus(struct inode *dir)
480{
478 if (!list_empty(&NFS_I(dir)->open_files)) {
479 nfs_advise_use_readdirplus(dir);
480 nfs_zap_mapping(dir, dir->i_mapping);
481 struct nfs_inode *nfsi = NFS_I(dir);
482
483 if (nfs_server_capable(dir, NFS_CAP_READDIRPLUS) &&
484 !list_empty(&nfsi->open_files)) {
485 set_bit(NFS_INO_ADVISE_RDPLUS, &nfsi->flags);
486 invalidate_mapping_pages(dir->i_mapping, 0, -1);
481 }
482}
483
484static
485void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
486{
487 struct qstr filename = QSTR_INIT(entry->name, entry->len);
488 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
489 struct dentry *dentry;
490 struct dentry *alias;
491 struct inode *dir = d_inode(parent);
492 struct inode *inode;
493 int status;
494
495 if (!(entry->fattr->valid & NFS_ATTR_FATTR_FILEID))
496 return;
497 if (!(entry->fattr->valid & NFS_ATTR_FATTR_FSID))
498 return;
487 }
488}
489
490static
491void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
492{
493 struct qstr filename = QSTR_INIT(entry->name, entry->len);
494 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
495 struct dentry *dentry;
496 struct dentry *alias;
497 struct inode *dir = d_inode(parent);
498 struct inode *inode;
499 int status;
500
501 if (!(entry->fattr->valid & NFS_ATTR_FATTR_FILEID))
502 return;
503 if (!(entry->fattr->valid & NFS_ATTR_FATTR_FSID))
504 return;
505 if (filename.len == 0)
506 return;
507 /* Validate that the name doesn't contain any illegal '\0' */
508 if (strnlen(filename.name, filename.len) != filename.len)
509 return;
510 /* ...or '/' */
511 if (strnchr(filename.name, filename.len, '/'))
512 return;
499 if (filename.name[0] == '.') {
500 if (filename.len == 1)
501 return;
502 if (filename.len == 2 && filename.name[1] == '.')
503 return;
504 }
505 filename.hash = full_name_hash(parent, filename.name, filename.len);
506

--- 5 unchanged lines hidden (view full) ---

512 return;
513 }
514 if (!d_in_lookup(dentry)) {
515 /* Is there a mountpoint here? If so, just exit */
516 if (!nfs_fsid_equal(&NFS_SB(dentry->d_sb)->fsid,
517 &entry->fattr->fsid))
518 goto out;
519 if (nfs_same_file(dentry, entry)) {
513 if (filename.name[0] == '.') {
514 if (filename.len == 1)
515 return;
516 if (filename.len == 2 && filename.name[1] == '.')
517 return;
518 }
519 filename.hash = full_name_hash(parent, filename.name, filename.len);
520

--- 5 unchanged lines hidden (view full) ---

526 return;
527 }
528 if (!d_in_lookup(dentry)) {
529 /* Is there a mountpoint here? If so, just exit */
530 if (!nfs_fsid_equal(&NFS_SB(dentry->d_sb)->fsid,
531 &entry->fattr->fsid))
532 goto out;
533 if (nfs_same_file(dentry, entry)) {
534 if (!entry->fh->size)
535 goto out;
520 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
521 status = nfs_refresh_inode(d_inode(dentry), entry->fattr);
522 if (!status)
523 nfs_setsecurity(d_inode(dentry), entry->fattr, entry->label);
524 goto out;
525 } else {
526 d_invalidate(dentry);
527 dput(dentry);
528 dentry = NULL;
529 goto again;
530 }
531 }
536 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
537 status = nfs_refresh_inode(d_inode(dentry), entry->fattr);
538 if (!status)
539 nfs_setsecurity(d_inode(dentry), entry->fattr, entry->label);
540 goto out;
541 } else {
542 d_invalidate(dentry);
543 dput(dentry);
544 dentry = NULL;
545 goto again;
546 }
547 }
548 if (!entry->fh->size) {
549 d_lookup_done(dentry);
550 goto out;
551 }
532
533 inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr, entry->label);
534 alias = d_splice_alias(inode, dentry);
535 d_lookup_done(dentry);
536 if (alias) {
537 if (IS_ERR(alias))
538 goto out;
539 dput(dentry);

--- 327 unchanged lines hidden (view full) ---

867 dfprintk(DIRCACHE, "NFS: %s: returns %d\n",
868 __func__, status);
869 return status;
870 out_release:
871 cache_page_release(desc);
872 goto out;
873}
874
552
553 inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr, entry->label);
554 alias = d_splice_alias(inode, dentry);
555 d_lookup_done(dentry);
556 if (alias) {
557 if (IS_ERR(alias))
558 goto out;
559 dput(dentry);

--- 327 unchanged lines hidden (view full) ---

887 dfprintk(DIRCACHE, "NFS: %s: returns %d\n",
888 __func__, status);
889 return status;
890 out_release:
891 cache_page_release(desc);
892 goto out;
893}
894
875static bool nfs_dir_mapping_need_revalidate(struct inode *dir)
876{
877 struct nfs_inode *nfsi = NFS_I(dir);
878
879 if (nfs_attribute_cache_expired(dir))
880 return true;
881 if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
882 return true;
883 return false;
884}
885
886/* The file offset position represents the dirent entry number. A
887 last cookie cache takes care of the common case of reading the
888 whole directory.
889 */
890static int nfs_readdir(struct file *file, struct dir_context *ctx)
891{
892 struct dentry *dentry = file_dentry(file);
893 struct inode *inode = d_inode(dentry);

--- 15 unchanged lines hidden (view full) ---

909 memset(desc, 0, sizeof(*desc));
910
911 desc->file = file;
912 desc->ctx = ctx;
913 desc->dir_cookie = &dir_ctx->dir_cookie;
914 desc->decode = NFS_PROTO(inode)->decode_dirent;
915 desc->plus = nfs_use_readdirplus(inode, ctx) ? 1 : 0;
916
895/* The file offset position represents the dirent entry number. A
896 last cookie cache takes care of the common case of reading the
897 whole directory.
898 */
899static int nfs_readdir(struct file *file, struct dir_context *ctx)
900{
901 struct dentry *dentry = file_dentry(file);
902 struct inode *inode = d_inode(dentry);

--- 15 unchanged lines hidden (view full) ---

918 memset(desc, 0, sizeof(*desc));
919
920 desc->file = file;
921 desc->ctx = ctx;
922 desc->dir_cookie = &dir_ctx->dir_cookie;
923 desc->decode = NFS_PROTO(inode)->decode_dirent;
924 desc->plus = nfs_use_readdirplus(inode, ctx) ? 1 : 0;
925
917 if (ctx->pos == 0 || nfs_dir_mapping_need_revalidate(inode))
926 if (ctx->pos == 0 || nfs_attribute_cache_expired(inode))
918 res = nfs_revalidate_mapping(inode, file->f_mapping);
919 if (res < 0)
920 goto out;
921
922 do {
923 res = readdir_search_pagecache(desc);
924
925 if (res == -EBADCOOKIE) {

--- 90 unchanged lines hidden (view full) ---

1016 * A check for whether or not the parent directory has changed.
1017 * In the case it has, we assume that the dentries are untrustworthy
1018 * and may need to be looked up again.
1019 * If rcu_walk prevents us from performing a full check, return 0.
1020 */
1021static int nfs_check_verifier(struct inode *dir, struct dentry *dentry,
1022 int rcu_walk)
1023{
927 res = nfs_revalidate_mapping(inode, file->f_mapping);
928 if (res < 0)
929 goto out;
930
931 do {
932 res = readdir_search_pagecache(desc);
933
934 if (res == -EBADCOOKIE) {

--- 90 unchanged lines hidden (view full) ---

1025 * A check for whether or not the parent directory has changed.
1026 * In the case it has, we assume that the dentries are untrustworthy
1027 * and may need to be looked up again.
1028 * If rcu_walk prevents us from performing a full check, return 0.
1029 */
1030static int nfs_check_verifier(struct inode *dir, struct dentry *dentry,
1031 int rcu_walk)
1032{
1024 int ret;
1025
1026 if (IS_ROOT(dentry))
1027 return 1;
1028 if (NFS_SERVER(dir)->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
1029 return 0;
1030 if (!nfs_verify_change_attribute(dir, dentry->d_time))
1031 return 0;
1032 /* Revalidate nfsi->cache_change_attribute before we declare a match */
1033 if (IS_ROOT(dentry))
1034 return 1;
1035 if (NFS_SERVER(dir)->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
1036 return 0;
1037 if (!nfs_verify_change_attribute(dir, dentry->d_time))
1038 return 0;
1039 /* Revalidate nfsi->cache_change_attribute before we declare a match */
1033 if (rcu_walk)
1034 ret = nfs_revalidate_inode_rcu(NFS_SERVER(dir), dir);
1035 else
1036 ret = nfs_revalidate_inode(NFS_SERVER(dir), dir);
1037 if (ret < 0)
1038 return 0;
1040 if (nfs_mapping_need_revalidate_inode(dir)) {
1041 if (rcu_walk)
1042 return 0;
1043 if (__nfs_revalidate_inode(NFS_SERVER(dir), dir) < 0)
1044 return 0;
1045 }
1039 if (!nfs_verify_change_attribute(dir, dentry->d_time))
1040 return 0;
1041 return 1;
1042}
1043
1044/*
1045 * Use intent information to check whether or not we're going to do
1046 * an O_EXCL create using this path component.

--- 95 unchanged lines hidden (view full) ---

1142 inode = d_inode(dentry);
1143
1144 if (!inode) {
1145 if (nfs_neg_need_reval(dir, dentry, flags)) {
1146 if (flags & LOOKUP_RCU)
1147 return -ECHILD;
1148 goto out_bad;
1149 }
1046 if (!nfs_verify_change_attribute(dir, dentry->d_time))
1047 return 0;
1048 return 1;
1049}
1050
1051/*
1052 * Use intent information to check whether or not we're going to do
1053 * an O_EXCL create using this path component.

--- 95 unchanged lines hidden (view full) ---

1149 inode = d_inode(dentry);
1150
1151 if (!inode) {
1152 if (nfs_neg_need_reval(dir, dentry, flags)) {
1153 if (flags & LOOKUP_RCU)
1154 return -ECHILD;
1155 goto out_bad;
1156 }
1150 goto out_valid_noent;
1157 goto out_valid;
1151 }
1152
1153 if (is_bad_inode(inode)) {
1154 if (flags & LOOKUP_RCU)
1155 return -ECHILD;
1156 dfprintk(LOOKUPCACHE, "%s: %pd2 has dud inode\n",
1157 __func__, dentry);
1158 goto out_bad;

--- 6 unchanged lines hidden (view full) ---

1165 if (!nfs_is_exclusive_create(dir, flags) &&
1166 nfs_check_verifier(dir, dentry, flags & LOOKUP_RCU)) {
1167
1168 if (nfs_lookup_verify_inode(inode, flags)) {
1169 if (flags & LOOKUP_RCU)
1170 return -ECHILD;
1171 goto out_zap_parent;
1172 }
1158 }
1159
1160 if (is_bad_inode(inode)) {
1161 if (flags & LOOKUP_RCU)
1162 return -ECHILD;
1163 dfprintk(LOOKUPCACHE, "%s: %pd2 has dud inode\n",
1164 __func__, dentry);
1165 goto out_bad;

--- 6 unchanged lines hidden (view full) ---

1172 if (!nfs_is_exclusive_create(dir, flags) &&
1173 nfs_check_verifier(dir, dentry, flags & LOOKUP_RCU)) {
1174
1175 if (nfs_lookup_verify_inode(inode, flags)) {
1176 if (flags & LOOKUP_RCU)
1177 return -ECHILD;
1178 goto out_zap_parent;
1179 }
1180 nfs_advise_use_readdirplus(dir);
1173 goto out_valid;
1174 }
1175
1176 if (flags & LOOKUP_RCU)
1177 return -ECHILD;
1178
1179 if (NFS_STALE(inode))
1180 goto out_bad;

--- 19 unchanged lines hidden (view full) ---

1200 goto out_bad;
1201
1202 nfs_setsecurity(inode, fattr, label);
1203
1204 nfs_free_fattr(fattr);
1205 nfs_free_fhandle(fhandle);
1206 nfs4_label_free(label);
1207
1181 goto out_valid;
1182 }
1183
1184 if (flags & LOOKUP_RCU)
1185 return -ECHILD;
1186
1187 if (NFS_STALE(inode))
1188 goto out_bad;

--- 19 unchanged lines hidden (view full) ---

1208 goto out_bad;
1209
1210 nfs_setsecurity(inode, fattr, label);
1211
1212 nfs_free_fattr(fattr);
1213 nfs_free_fhandle(fhandle);
1214 nfs4_label_free(label);
1215
1216 /* set a readdirplus hint that we had a cache miss */
1217 nfs_force_use_readdirplus(dir);
1218
1208out_set_verifier:
1209 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1210 out_valid:
1219out_set_verifier:
1220 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1221 out_valid:
1211 /* Success: notify readdir to use READDIRPLUS */
1212 nfs_advise_use_readdirplus(dir);
1213 out_valid_noent:
1214 if (flags & LOOKUP_RCU) {
1215 if (parent != ACCESS_ONCE(dentry->d_parent))
1216 return -ECHILD;
1217 } else
1218 dput(parent);
1219 dfprintk(LOOKUPCACHE, "NFS: %s(%pd2) is valid\n",
1220 __func__, dentry);
1221 return 1;

--- 38 unchanged lines hidden (view full) ---

1260 * pathwalk ends on a dentry that was not found via a normal lookup in the
1261 * parent dir (e.g.: ".", "..", procfs symlinks or mountpoint traversals).
1262 *
1263 * In this situation, we just want to verify that the inode itself is OK
1264 * since the dentry might have changed on the server.
1265 */
1266static int nfs_weak_revalidate(struct dentry *dentry, unsigned int flags)
1267{
1222 if (flags & LOOKUP_RCU) {
1223 if (parent != ACCESS_ONCE(dentry->d_parent))
1224 return -ECHILD;
1225 } else
1226 dput(parent);
1227 dfprintk(LOOKUPCACHE, "NFS: %s(%pd2) is valid\n",
1228 __func__, dentry);
1229 return 1;

--- 38 unchanged lines hidden (view full) ---

1268 * pathwalk ends on a dentry that was not found via a normal lookup in the
1269 * parent dir (e.g.: ".", "..", procfs symlinks or mountpoint traversals).
1270 *
1271 * In this situation, we just want to verify that the inode itself is OK
1272 * since the dentry might have changed on the server.
1273 */
1274static int nfs_weak_revalidate(struct dentry *dentry, unsigned int flags)
1275{
1268 int error;
1269 struct inode *inode = d_inode(dentry);
1276 struct inode *inode = d_inode(dentry);
1277 int error = 0;
1270
1271 /*
1272 * I believe we can only get a negative dentry here in the case of a
1273 * procfs-style symlink. Just assume it's correct for now, but we may
1274 * eventually need to do something more here.
1275 */
1276 if (!inode) {
1277 dfprintk(LOOKUPCACHE, "%s: %pd2 has negative inode\n",
1278 __func__, dentry);
1279 return 1;
1280 }
1281
1282 if (is_bad_inode(inode)) {
1283 dfprintk(LOOKUPCACHE, "%s: %pd2 has dud inode\n",
1284 __func__, dentry);
1285 return 0;
1286 }
1287
1278
1279 /*
1280 * I believe we can only get a negative dentry here in the case of a
1281 * procfs-style symlink. Just assume it's correct for now, but we may
1282 * eventually need to do something more here.
1283 */
1284 if (!inode) {
1285 dfprintk(LOOKUPCACHE, "%s: %pd2 has negative inode\n",
1286 __func__, dentry);
1287 return 1;
1288 }
1289
1290 if (is_bad_inode(inode)) {
1291 dfprintk(LOOKUPCACHE, "%s: %pd2 has dud inode\n",
1292 __func__, dentry);
1293 return 0;
1294 }
1295
1288 error = nfs_revalidate_inode(NFS_SERVER(inode), inode);
1296 if (nfs_mapping_need_revalidate_inode(inode))
1297 error = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
1289 dfprintk(LOOKUPCACHE, "NFS: %s: inode %lu is %s\n",
1290 __func__, inode->i_ino, error ? "invalid" : "valid");
1291 return !error;
1292}
1293
1294/*
1295 * This is called from dput() when d_count is going to 0.
1296 */

--- 108 unchanged lines hidden (view full) ---

1405 res = ERR_PTR(error);
1406 goto out_label;
1407 }
1408 inode = nfs_fhget(dentry->d_sb, fhandle, fattr, label);
1409 res = ERR_CAST(inode);
1410 if (IS_ERR(res))
1411 goto out_label;
1412
1298 dfprintk(LOOKUPCACHE, "NFS: %s: inode %lu is %s\n",
1299 __func__, inode->i_ino, error ? "invalid" : "valid");
1300 return !error;
1301}
1302
1303/*
1304 * This is called from dput() when d_count is going to 0.
1305 */

--- 108 unchanged lines hidden (view full) ---

1414 res = ERR_PTR(error);
1415 goto out_label;
1416 }
1417 inode = nfs_fhget(dentry->d_sb, fhandle, fattr, label);
1418 res = ERR_CAST(inode);
1419 if (IS_ERR(res))
1420 goto out_label;
1421
1413 /* Success: notify readdir to use READDIRPLUS */
1414 nfs_advise_use_readdirplus(dir);
1422 /* Notify readdir to use READDIRPLUS */
1423 nfs_force_use_readdirplus(dir);
1415
1416no_entry:
1417 res = d_splice_alias(inode, dentry);
1418 if (res != NULL) {
1419 if (IS_ERR(res))
1420 goto out_label;
1421 dentry = res;
1422 }

--- 25 unchanged lines hidden (view full) ---

1448 fmode_t res = (__force fmode_t)flags & FMODE_EXEC;
1449 if ((flags & O_ACCMODE) != O_WRONLY)
1450 res |= FMODE_READ;
1451 if ((flags & O_ACCMODE) != O_RDONLY)
1452 res |= FMODE_WRITE;
1453 return res;
1454}
1455
1424
1425no_entry:
1426 res = d_splice_alias(inode, dentry);
1427 if (res != NULL) {
1428 if (IS_ERR(res))
1429 goto out_label;
1430 dentry = res;
1431 }

--- 25 unchanged lines hidden (view full) ---

1457 fmode_t res = (__force fmode_t)flags & FMODE_EXEC;
1458 if ((flags & O_ACCMODE) != O_WRONLY)
1459 res |= FMODE_READ;
1460 if ((flags & O_ACCMODE) != O_RDONLY)
1461 res |= FMODE_WRITE;
1462 return res;
1463}
1464
1456static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags)
1465static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags, struct file *filp)
1457{
1466{
1458 return alloc_nfs_open_context(dentry, flags_to_mode(open_flags));
1467 return alloc_nfs_open_context(dentry, flags_to_mode(open_flags), filp);
1459}
1460
1461static int do_open(struct inode *inode, struct file *filp)
1462{
1463 nfs_fscache_open_file(inode, filp);
1464 return 0;
1465}
1466

--- 49 unchanged lines hidden (view full) ---

1516 lookup_flags = LOOKUP_OPEN|LOOKUP_DIRECTORY;
1517 goto no_open;
1518 }
1519
1520 if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
1521 return -ENAMETOOLONG;
1522
1523 if (open_flags & O_CREAT) {
1468}
1469
1470static int do_open(struct inode *inode, struct file *filp)
1471{
1472 nfs_fscache_open_file(inode, filp);
1473 return 0;
1474}
1475

--- 49 unchanged lines hidden (view full) ---

1525 lookup_flags = LOOKUP_OPEN|LOOKUP_DIRECTORY;
1526 goto no_open;
1527 }
1528
1529 if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
1530 return -ENAMETOOLONG;
1531
1532 if (open_flags & O_CREAT) {
1533 struct nfs_server *server = NFS_SERVER(dir);
1534
1535 if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK))
1536 mode &= ~current_umask();
1537
1524 attr.ia_valid |= ATTR_MODE;
1538 attr.ia_valid |= ATTR_MODE;
1525 attr.ia_mode = mode & ~current_umask();
1539 attr.ia_mode = mode;
1526 }
1527 if (open_flags & O_TRUNC) {
1528 attr.ia_valid |= ATTR_SIZE;
1529 attr.ia_size = 0;
1530 }
1531
1532 if (!(open_flags & O_CREAT) && !d_in_lookup(dentry)) {
1533 d_drop(dentry);
1534 switched = true;
1535 dentry = d_alloc_parallel(dentry->d_parent,
1536 &dentry->d_name, &wq);
1537 if (IS_ERR(dentry))
1538 return PTR_ERR(dentry);
1539 if (unlikely(!d_in_lookup(dentry)))
1540 return finish_no_open(file, dentry);
1541 }
1542
1540 }
1541 if (open_flags & O_TRUNC) {
1542 attr.ia_valid |= ATTR_SIZE;
1543 attr.ia_size = 0;
1544 }
1545
1546 if (!(open_flags & O_CREAT) && !d_in_lookup(dentry)) {
1547 d_drop(dentry);
1548 switched = true;
1549 dentry = d_alloc_parallel(dentry->d_parent,
1550 &dentry->d_name, &wq);
1551 if (IS_ERR(dentry))
1552 return PTR_ERR(dentry);
1553 if (unlikely(!d_in_lookup(dentry)))
1554 return finish_no_open(file, dentry);
1555 }
1556
1543 ctx = create_nfs_open_context(dentry, open_flags);
1557 ctx = create_nfs_open_context(dentry, open_flags, file);
1544 err = PTR_ERR(ctx);
1545 if (IS_ERR(ctx))
1546 goto out;
1547
1548 trace_nfs_atomic_open_enter(dir, ctx, open_flags);
1549 inode = NFS_PROTO(dir)->open_context(dir, ctx, open_flags, &attr, opened);
1550 if (IS_ERR(inode)) {
1551 err = PTR_ERR(inode);

--- 456 unchanged lines hidden (view full) ---

2008 * Unfortunately, things are a little more complicated than indicated
2009 * above. For a cross-directory move, we want to make sure we can get
2010 * rid of the old inode after the operation. This means there must be
2011 * no pending writes (if it's a file), and the use count must be 1.
2012 * If these conditions are met, we can drop the dentries before doing
2013 * the rename.
2014 */
2015int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1558 err = PTR_ERR(ctx);
1559 if (IS_ERR(ctx))
1560 goto out;
1561
1562 trace_nfs_atomic_open_enter(dir, ctx, open_flags);
1563 inode = NFS_PROTO(dir)->open_context(dir, ctx, open_flags, &attr, opened);
1564 if (IS_ERR(inode)) {
1565 err = PTR_ERR(inode);

--- 456 unchanged lines hidden (view full) ---

2022 * Unfortunately, things are a little more complicated than indicated
2023 * above. For a cross-directory move, we want to make sure we can get
2024 * rid of the old inode after the operation. This means there must be
2025 * no pending writes (if it's a file), and the use count must be 1.
2026 * If these conditions are met, we can drop the dentries before doing
2027 * the rename.
2028 */
2029int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2016 struct inode *new_dir, struct dentry *new_dentry)
2030 struct inode *new_dir, struct dentry *new_dentry,
2031 unsigned int flags)
2017{
2018 struct inode *old_inode = d_inode(old_dentry);
2019 struct inode *new_inode = d_inode(new_dentry);
2020 struct dentry *dentry = NULL, *rehash = NULL;
2021 struct rpc_task *task;
2022 int error = -EBUSY;
2023
2032{
2033 struct inode *old_inode = d_inode(old_dentry);
2034 struct inode *new_inode = d_inode(new_dentry);
2035 struct dentry *dentry = NULL, *rehash = NULL;
2036 struct rpc_task *task;
2037 int error = -EBUSY;
2038
2039 if (flags)
2040 return -EINVAL;
2041
2024 dfprintk(VFS, "NFS: rename(%pd2 -> %pd2, ct=%d)\n",
2025 old_dentry, new_dentry,
2026 d_count(new_dentry));
2027
2028 trace_nfs_rename_enter(old_dir, old_dentry, new_dir, new_dentry);
2029 /*
2030 * For non-directories, check whether the target is busy and if so,
2031 * make a copy of the dentry and then do a silly-rename. If the

--- 531 unchanged lines hidden ---
2042 dfprintk(VFS, "NFS: rename(%pd2 -> %pd2, ct=%d)\n",
2043 old_dentry, new_dentry,
2044 d_count(new_dentry));
2045
2046 trace_nfs_rename_enter(old_dir, old_dentry, new_dir, new_dentry);
2047 /*
2048 * For non-directories, check whether the target is busy and if so,
2049 * make a copy of the dentry and then do a silly-rename. If the

--- 531 unchanged lines hidden ---