2 * Overlayfs NFS export support.
4 * Amir Goldstein <amir73il@gmail.com>
6 * Copyright (C) 2017-2018 CTERA Networks. All Rights Reserved.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
14 #include <linux/cred.h>
15 #include <linux/mount.h>
16 #include <linux/namei.h>
17 #include <linux/xattr.h>
18 #include <linux/exportfs.h>
19 #include <linux/ratelimit.h>
20 #include "overlayfs.h"
22 static int ovl_d_to_fh(struct dentry *dentry, char *buf, int buflen)
24 struct dentry *upper = ovl_dentry_upper(dentry);
25 struct dentry *origin = ovl_dentry_lower(dentry);
26 struct ovl_fh *fh = NULL;
30 * On overlay with an upper layer, overlay root inode is encoded as
31 * an upper file handle, because upper root dir is not indexed.
33 if (dentry == dentry->d_sb->s_root && upper)
40 /* TODO: encode non pure-upper by origin */
41 fh = ovl_encode_fh(upper, true);
47 memcpy(buf, (char *)fh, fh->len);
55 pr_warn_ratelimited("overlayfs: failed to encode file handle (%pd2, err=%i, buflen=%d, len=%d, type=%d)\n",
56 dentry, err, buflen, fh ? (int)fh->len : 0,
61 static int ovl_dentry_to_fh(struct dentry *dentry, u32 *fid, int *max_len)
63 int res, len = *max_len << 2;
65 res = ovl_d_to_fh(dentry, (char *)fid, len);
67 return FILEID_INVALID;
71 /* Round up to dwords */
72 *max_len = (len + 3) >> 2;
76 static int ovl_encode_inode_fh(struct inode *inode, u32 *fid, int *max_len,
79 struct dentry *dentry;
82 /* TODO: encode connectable file handles */
84 return FILEID_INVALID;
86 dentry = d_find_any_alias(inode);
88 return FILEID_INVALID;
90 type = ovl_dentry_to_fh(dentry, fid, max_len);
96 const struct export_operations ovl_export_operations = {
97 .encode_fh = ovl_encode_inode_fh,