[2/4] usertools: add option to change mount point owner

Message ID 20220607234949.2311884-3-dkozlyuk@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Improve documentation for running as non-root |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dmitry Kozlyuk June 7, 2022, 11:49 p.m. UTC
  Per mount(8), the previous owner and mode of the mount point
become invisible as long as this filesystem remains mounted.
Because dpdk-hugepages.py must be run as root,
the new owner would be root.
This is undesirable if the hugepage directory is being set up
by the administrator for an unprivileged user.
Add --owner/-o option to set the owner after mounting.
The benefit over calling chown directly after the script
is that the user does not need to care about this detail
of mount command operation.

Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
---
 usertools/dpdk-hugepages.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger June 8, 2022, midnight UTC | #1
On Wed, 8 Jun 2022 02:49:47 +0300
Dmitry Kozlyuk <dkozlyuk@nvidia.com> wrote:

>  
> -def mount_huge(pagesize, mountpoint):
> +def mount_huge(pagesize, mountpoint, owner):
>      '''Mount the huge TLB file system'''
>      if mountpoint in get_mountpoints():
>          print(mountpoint, "already mounted")
> @@ -180,6 +180,8 @@ def mount_huge(pagesize, mountpoint):
>          cmd += ' -o pagesize={}'.format(pagesize * 1024)
>      cmd += ' nodev ' + mountpoint
>      os.system(cmd)
> +    if owner:
> +        os.system('chown {} {}'.format(owner, mountpoint))
>  

The hugetlb filesystem type already supports set owner.
Please use that instead of an additional chown command.

https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt



If the user applications are going to request huge pages using mmap system
call, then it is required that system administrator mount a file system of
type hugetlbfs:

  mount -t hugetlbfs \
	-o uid=<value>,gid=<value>,mode=<value>,pagesize=<value>,size=<value>,\
	min_size=<value>,nr_inodes=<value> none /mnt/huge
  

Patch

diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index 8bab086a2f..1e01ac3d9f 100755
--- a/usertools/dpdk-hugepages.py
+++ b/usertools/dpdk-hugepages.py
@@ -170,7 +170,7 @@  def get_mountpoints():
     return mounted
 
 
-def mount_huge(pagesize, mountpoint):
+def mount_huge(pagesize, mountpoint, owner):
     '''Mount the huge TLB file system'''
     if mountpoint in get_mountpoints():
         print(mountpoint, "already mounted")
@@ -180,6 +180,8 @@  def mount_huge(pagesize, mountpoint):
         cmd += ' -o pagesize={}'.format(pagesize * 1024)
     cmd += ' nodev ' + mountpoint
     os.system(cmd)
+    if owner:
+        os.system('chown {} {}'.format(owner, mountpoint))
 
 
 def umount_huge(mountpoint):
@@ -234,6 +236,11 @@  def main():
         metavar='DIR',
         default=HUGE_MOUNT,
         help='mount point')
+    parser.add_argument(
+        '--owner',
+        '-o',
+        metavar='USER:GROUP',
+        help='change the mounted directory owner')
     parser.add_argument(
         '--node', '-n', help='select numa node to reserve pages on')
     parser.add_argument(
@@ -279,7 +286,7 @@  def main():
         reserve_pages(
             int(reserve_kb / pagesize_kb), pagesize_kb, node=args.node)
     if args.mount:
-        mount_huge(pagesize_kb, args.directory)
+        mount_huge(pagesize_kb, args.directory, args.owner)
     if args.show:
         show_pages()
         print()