Skip to content

Commit 4a25220

Browse files
dhowellsAl Viro
authored andcommitted
hugetlbfs: Implement show_options
Implement the show_options superblock op for hugetlbfs as part of a bid to get rid of s_options and generic_show_options() to make it easier to implement a context-based mount where the mount options can be passed individually over a file descriptor. Note that the uid and gid should possibly be displayed relative to the viewer's user namespace. Signed-off-by: David Howells <[email protected]> cc: Nadia Yvette Chambers <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent c3d98ea commit 4a25220

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

fs/hugetlbfs/inode.c

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ static const struct inode_operations hugetlbfs_dir_inode_operations;
4646
static const struct inode_operations hugetlbfs_inode_operations;
4747

4848
struct hugetlbfs_config {
49-
kuid_t uid;
50-
kgid_t gid;
51-
umode_t mode;
52-
long max_hpages;
53-
long nr_inodes;
54-
struct hstate *hstate;
55-
long min_hpages;
49+
struct hstate *hstate;
50+
long max_hpages;
51+
long nr_inodes;
52+
long min_hpages;
53+
kuid_t uid;
54+
kgid_t gid;
55+
umode_t mode;
5656
};
5757

5858
struct hugetlbfs_inode_info {
@@ -851,6 +851,46 @@ static int hugetlbfs_migrate_page(struct address_space *mapping,
851851
return MIGRATEPAGE_SUCCESS;
852852
}
853853

854+
/*
855+
* Display the mount options in /proc/mounts.
856+
*/
857+
static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root)
858+
{
859+
struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(root->d_sb);
860+
struct hugepage_subpool *spool = sbinfo->spool;
861+
unsigned long hpage_size = huge_page_size(sbinfo->hstate);
862+
unsigned hpage_shift = huge_page_shift(sbinfo->hstate);
863+
char mod;
864+
865+
if (!uid_eq(sbinfo->uid, GLOBAL_ROOT_UID))
866+
seq_printf(m, ",uid=%u",
867+
from_kuid_munged(&init_user_ns, sbinfo->uid));
868+
if (!gid_eq(sbinfo->gid, GLOBAL_ROOT_GID))
869+
seq_printf(m, ",gid=%u",
870+
from_kgid_munged(&init_user_ns, sbinfo->gid));
871+
if (sbinfo->mode != 0755)
872+
seq_printf(m, ",mode=%o", sbinfo->mode);
873+
if (sbinfo->max_inodes != -1)
874+
seq_printf(m, ",nr_inodes=%lu", sbinfo->max_inodes);
875+
876+
hpage_size /= 1024;
877+
mod = 'K';
878+
if (hpage_size >= 1024) {
879+
hpage_size /= 1024;
880+
mod = 'M';
881+
}
882+
seq_printf(m, ",pagesize=%lu%c", hpage_size, mod);
883+
if (spool) {
884+
if (spool->max_hpages != -1)
885+
seq_printf(m, ",size=%llu",
886+
(unsigned long long)spool->max_hpages << hpage_shift);
887+
if (spool->min_hpages != -1)
888+
seq_printf(m, ",min_size=%llu",
889+
(unsigned long long)spool->min_hpages << hpage_shift);
890+
}
891+
return 0;
892+
}
893+
854894
static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf)
855895
{
856896
struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(dentry->d_sb);
@@ -1008,19 +1048,19 @@ static const struct super_operations hugetlbfs_ops = {
10081048
.evict_inode = hugetlbfs_evict_inode,
10091049
.statfs = hugetlbfs_statfs,
10101050
.put_super = hugetlbfs_put_super,
1011-
.show_options = generic_show_options,
1051+
.show_options = hugetlbfs_show_options,
10121052
};
10131053

1014-
enum { NO_SIZE, SIZE_STD, SIZE_PERCENT };
1054+
enum hugetlbfs_size_type { NO_SIZE, SIZE_STD, SIZE_PERCENT };
10151055

10161056
/*
10171057
* Convert size option passed from command line to number of huge pages
10181058
* in the pool specified by hstate. Size option could be in bytes
10191059
* (val_type == SIZE_STD) or percentage of the pool (val_type == SIZE_PERCENT).
10201060
*/
1021-
static long long
1061+
static long
10221062
hugetlbfs_size_to_hpages(struct hstate *h, unsigned long long size_opt,
1023-
int val_type)
1063+
enum hugetlbfs_size_type val_type)
10241064
{
10251065
if (val_type == NO_SIZE)
10261066
return -1;
@@ -1042,7 +1082,7 @@ hugetlbfs_parse_options(char *options, struct hugetlbfs_config *pconfig)
10421082
substring_t args[MAX_OPT_ARGS];
10431083
int option;
10441084
unsigned long long max_size_opt = 0, min_size_opt = 0;
1045-
int max_val_type = NO_SIZE, min_val_type = NO_SIZE;
1085+
enum hugetlbfs_size_type max_val_type = NO_SIZE, min_val_type = NO_SIZE;
10461086

10471087
if (!options)
10481088
return 0;
@@ -1156,8 +1196,6 @@ hugetlbfs_fill_super(struct super_block *sb, void *data, int silent)
11561196
struct hugetlbfs_config config;
11571197
struct hugetlbfs_sb_info *sbinfo;
11581198

1159-
save_mount_options(sb, data);
1160-
11611199
config.max_hpages = -1; /* No limit on size by default */
11621200
config.nr_inodes = -1; /* No limit on number of inodes by default */
11631201
config.uid = current_fsuid();
@@ -1178,6 +1216,10 @@ hugetlbfs_fill_super(struct super_block *sb, void *data, int silent)
11781216
sbinfo->max_inodes = config.nr_inodes;
11791217
sbinfo->free_inodes = config.nr_inodes;
11801218
sbinfo->spool = NULL;
1219+
sbinfo->uid = config.uid;
1220+
sbinfo->gid = config.gid;
1221+
sbinfo->mode = config.mode;
1222+
11811223
/*
11821224
* Allocate and initialize subpool if maximum or minimum size is
11831225
* specified. Any needed reservations (for minimim size) are taken

include/linux/hugetlb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ struct hugetlbfs_sb_info {
262262
spinlock_t stat_lock;
263263
struct hstate *hstate;
264264
struct hugepage_subpool *spool;
265+
kuid_t uid;
266+
kgid_t gid;
267+
umode_t mode;
265268
};
266269

267270
static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)

0 commit comments

Comments
 (0)