vfs_inode.c (f69999b5f9b444a2443ca2b9e5976e78bb5b7c69) vfs_inode.c (be2ca3825372085d669d322dccd0542a90e5b434)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * This file contains vfs inode ops for the 9P2000 protocol.
4 *
5 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
6 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
7 */
8

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

251 */
252void v9fs_set_netfs_context(struct inode *inode)
253{
254 struct v9fs_inode *v9inode = V9FS_I(inode);
255 netfs_inode_init(&v9inode->netfs, &v9fs_req_ops, true);
256}
257
258int v9fs_init_inode(struct v9fs_session_info *v9ses,
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * This file contains vfs inode ops for the 9P2000 protocol.
4 *
5 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
6 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
7 */
8

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

251 */
252void v9fs_set_netfs_context(struct inode *inode)
253{
254 struct v9fs_inode *v9inode = V9FS_I(inode);
255 netfs_inode_init(&v9inode->netfs, &v9fs_req_ops, true);
256}
257
258int v9fs_init_inode(struct v9fs_session_info *v9ses,
259 struct inode *inode, struct p9_qid *qid, umode_t mode, dev_t rdev)
259 struct inode *inode, umode_t mode, dev_t rdev)
260{
261 int err = 0;
260{
261 int err = 0;
262 struct v9fs_inode *v9inode = V9FS_I(inode);
263
262
264 memcpy(&v9inode->qid, qid, sizeof(struct p9_qid));
265
266 inode_init_owner(&nop_mnt_idmap, inode, NULL, mode);
267 inode->i_blocks = 0;
268 inode->i_rdev = rdev;
269 simple_inode_init_ts(inode);
270 inode->i_mapping->a_ops = &v9fs_addr_operations;
271 inode->i_private = NULL;
272
273 switch (mode & S_IFMT) {

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

361#ifdef CONFIG_9P_FSCACHE
362 if (v9fs_inode_cookie(v9inode))
363 fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false);
364#endif
365 } else
366 clear_inode(inode);
367}
368
263 inode_init_owner(&nop_mnt_idmap, inode, NULL, mode);
264 inode->i_blocks = 0;
265 inode->i_rdev = rdev;
266 simple_inode_init_ts(inode);
267 inode->i_mapping->a_ops = &v9fs_addr_operations;
268 inode->i_private = NULL;
269
270 switch (mode & S_IFMT) {

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

358#ifdef CONFIG_9P_FSCACHE
359 if (v9fs_inode_cookie(v9inode))
360 fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false);
361#endif
362 } else
363 clear_inode(inode);
364}
365
369struct inode *v9fs_fid_iget(struct super_block *sb, struct p9_fid *fid)
366static int v9fs_test_inode(struct inode *inode, void *data)
370{
367{
368 int umode;
371 dev_t rdev;
369 dev_t rdev;
370 struct v9fs_inode *v9inode = V9FS_I(inode);
371 struct p9_wstat *st = (struct p9_wstat *)data;
372 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
373
374 umode = p9mode2unixmode(v9ses, st, &rdev);
375 /* don't match inode of different type */
376 if (inode_wrong_type(inode, umode))
377 return 0;
378
379 /* compare qid details */
380 if (memcmp(&v9inode->qid.version,
381 &st->qid.version, sizeof(v9inode->qid.version)))
382 return 0;
383
384 if (v9inode->qid.type != st->qid.type)
385 return 0;
386
387 if (v9inode->qid.path != st->qid.path)
388 return 0;
389 return 1;
390}
391
392static int v9fs_test_new_inode(struct inode *inode, void *data)
393{
394 return 0;
395}
396
397static int v9fs_set_inode(struct inode *inode, void *data)
398{
399 struct v9fs_inode *v9inode = V9FS_I(inode);
400 struct p9_wstat *st = (struct p9_wstat *)data;
401
402 memcpy(&v9inode->qid, &st->qid, sizeof(st->qid));
403 return 0;
404}
405
406static struct inode *v9fs_qid_iget(struct super_block *sb,
407 struct p9_qid *qid,
408 struct p9_wstat *st,
409 int new)
410{
411 dev_t rdev;
372 int retval;
373 umode_t umode;
374 struct inode *inode;
412 int retval;
413 umode_t umode;
414 struct inode *inode;
375 struct p9_wstat *st;
376 struct v9fs_session_info *v9ses = sb->s_fs_info;
415 struct v9fs_session_info *v9ses = sb->s_fs_info;
416 int (*test)(struct inode *inode, void *data);
377
417
378 inode = iget_locked(sb, QID2INO(&fid->qid));
379 if (unlikely(!inode))
418 if (new)
419 test = v9fs_test_new_inode;
420 else
421 test = v9fs_test_inode;
422
423 inode = iget5_locked(sb, QID2INO(qid), test, v9fs_set_inode, st);
424 if (!inode)
380 return ERR_PTR(-ENOMEM);
381 if (!(inode->i_state & I_NEW))
382 return inode;
425 return ERR_PTR(-ENOMEM);
426 if (!(inode->i_state & I_NEW))
427 return inode;
383
384 /*
385 * initialize the inode with the stat info
386 * FIXME!! we may need support for stale inodes
387 * later.
388 */
428 /*
429 * initialize the inode with the stat info
430 * FIXME!! we may need support for stale inodes
431 * later.
432 */
389 st = p9_client_stat(fid);
390 if (IS_ERR(st)) {
391 retval = PTR_ERR(st);
392 goto error;
393 }
394
433 inode->i_ino = QID2INO(qid);
395 umode = p9mode2unixmode(v9ses, st, &rdev);
434 umode = p9mode2unixmode(v9ses, st, &rdev);
396 retval = v9fs_init_inode(v9ses, inode, &fid->qid, umode, rdev);
397 v9fs_stat2inode(st, inode, sb, 0);
398 p9stat_free(st);
399 kfree(st);
435 retval = v9fs_init_inode(v9ses, inode, umode, rdev);
400 if (retval)
401 goto error;
402
436 if (retval)
437 goto error;
438
439 v9fs_stat2inode(st, inode, sb, 0);
403 v9fs_set_netfs_context(inode);
404 v9fs_cache_inode_get_cookie(inode);
405 unlock_new_inode(inode);
406 return inode;
407error:
408 iget_failed(inode);
409 return ERR_PTR(retval);
410
411}
412
440 v9fs_set_netfs_context(inode);
441 v9fs_cache_inode_get_cookie(inode);
442 unlock_new_inode(inode);
443 return inode;
444error:
445 iget_failed(inode);
446 return ERR_PTR(retval);
447
448}
449
450struct inode *
451v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
452 struct super_block *sb, int new)
453{
454 struct p9_wstat *st;
455 struct inode *inode = NULL;
456
457 st = p9_client_stat(fid);
458 if (IS_ERR(st))
459 return ERR_CAST(st);
460
461 inode = v9fs_qid_iget(sb, &st->qid, st, new);
462 p9stat_free(st);
463 kfree(st);
464 return inode;
465}
466
413/**
414 * v9fs_at_to_dotl_flags- convert Linux specific AT flags to
415 * plan 9 AT flag.
416 * @flags: flags to convert
417 */
418static int v9fs_at_to_dotl_flags(int flags)
419{
420 int rflags = 0;

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

551 err = PTR_ERR(fid);
552 p9_debug(P9_DEBUG_VFS,
553 "p9_client_walk failed %d\n", err);
554 goto error;
555 }
556 /*
557 * instantiate inode and assign the unopened fid to the dentry
558 */
467/**
468 * v9fs_at_to_dotl_flags- convert Linux specific AT flags to
469 * plan 9 AT flag.
470 * @flags: flags to convert
471 */
472static int v9fs_at_to_dotl_flags(int flags)
473{
474 int rflags = 0;

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

605 err = PTR_ERR(fid);
606 p9_debug(P9_DEBUG_VFS,
607 "p9_client_walk failed %d\n", err);
608 goto error;
609 }
610 /*
611 * instantiate inode and assign the unopened fid to the dentry
612 */
559 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
613 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
560 if (IS_ERR(inode)) {
561 err = PTR_ERR(inode);
562 p9_debug(P9_DEBUG_VFS,
563 "inode creation failed %d\n", err);
564 goto error;
565 }
566 v9fs_fid_add(dentry, &fid);
567 d_instantiate(dentry, inode);

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

679 */
680 name = dentry->d_name.name;
681 fid = p9_client_walk(dfid, 1, &name, 1);
682 p9_fid_put(dfid);
683 if (fid == ERR_PTR(-ENOENT))
684 inode = NULL;
685 else if (IS_ERR(fid))
686 inode = ERR_CAST(fid);
614 if (IS_ERR(inode)) {
615 err = PTR_ERR(inode);
616 p9_debug(P9_DEBUG_VFS,
617 "inode creation failed %d\n", err);
618 goto error;
619 }
620 v9fs_fid_add(dentry, &fid);
621 d_instantiate(dentry, inode);

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

733 */
734 name = dentry->d_name.name;
735 fid = p9_client_walk(dfid, 1, &name, 1);
736 p9_fid_put(dfid);
737 if (fid == ERR_PTR(-ENOENT))
738 inode = NULL;
739 else if (IS_ERR(fid))
740 inode = ERR_CAST(fid);
687 else
741 else if (v9ses->cache & (CACHE_META|CACHE_LOOSE))
688 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
742 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
743 else
744 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
689 /*
690 * If we had a rename on the server and a parallel lookup
691 * for the new name, then make sure we instantiate with
692 * the new name. ie look up for a/b, while on server somebody
693 * moved b under k and client parallely did a lookup for
694 * k/b.
695 */
696 res = d_splice_alias(inode, dentry);

--- 656 unchanged lines hidden ---
745 /*
746 * If we had a rename on the server and a parallel lookup
747 * for the new name, then make sure we instantiate with
748 * the new name. ie look up for a/b, while on server somebody
749 * moved b under k and client parallely did a lookup for
750 * k/b.
751 */
752 res = d_splice_alias(inode, dentry);

--- 656 unchanged lines hidden ---