^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/nfs/symlink.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1992 Rick Sladkey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Optimization changes Copyright (C) 1994 Florian La Roche
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Jun 7 1999, cache symlink lookups in the page cache. -DaveM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * nfs symlink handling code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/nfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/nfs2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* Symlink caching in the page cache is even more simplistic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * and straight-forward than readdir caching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int nfs_symlink_filler(void *data, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct inode *inode = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) error = NFS_PROTO(inode)->readlink(inode, page, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) SetPageError(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static const char *nfs_get_link(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct delayed_call *done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) void *err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (!dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) err = ERR_PTR(nfs_revalidate_mapping_rcu(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) page = find_get_page(inode->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return ERR_PTR(-ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (!PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return ERR_PTR(-ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) page = read_cache_page(&inode->i_data, 0, nfs_symlink_filler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return ERR_CAST(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) set_delayed_call(done, page_put_link, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * symlinks can't do much...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) const struct inode_operations nfs_symlink_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .get_link = nfs_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .getattr = nfs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .setattr = nfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) };