Advertisement
ffilz

dbus-cmds.sh

Jan 20th, 2022
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Try loading the config from any of the distro
  4. # specific configuration locations
  5. if [ -f /etc/sysconfig/ganesha ]
  6.         then
  7.         . /etc/sysconfig/ganesha
  8. fi
  9. if [ -f /etc/conf.d/ganesha ]
  10.         then
  11.         . /etc/conf.d/ganesha
  12. fi
  13. if [ -f /etc/default/ganesha ]
  14.         then
  15.         . /etc/default/ganesha
  16. fi
  17.  
  18. GANESHA_DIR=${1%/}
  19. OPTION=$2
  20. VOL=$3
  21. CONF=$GANESHA_DIR"/ganesha.conf"
  22.  
  23. function check_cmd_status()
  24. {
  25.         if [ "$1" != "0" ]
  26.         then
  27.                 logger "dynamic export failed on node :${hostname -s}"
  28.         fi
  29. }
  30.  
  31. #This function keeps track of export IDs and increments it with every new entry
  32. function dynamic_export_add()
  33. {
  34.         dbus-send  --system \
  35.         --dest=org.ganesha.nfsd  /org/ganesha/nfsd/ExportMgr \
  36.         org.ganesha.nfsd.exportmgr.AddExport  string:$GANESHA_DIR/exports/export.$VOL.conf \
  37.         string:"EXPORT(Path=/$VOL)"
  38.         check_cmd_status `echo $?`
  39. }
  40.  
  41. #This function removes an export dynamically(uses the export_id of the export)
  42. function dynamic_export_remove()
  43. {
  44.         # Below bash fetch all the export from ShowExport command and search
  45.         # export entry based on path and then get its export entry.
  46.         # There are two possiblities for path, either entire volume will be
  47.         # exported or subdir. It handles both cases. But it remove only first
  48.         # entry from the list based on assumption that entry exported via cli
  49.         # has lowest export id value
  50.     removed_id=$(dbus-send --type=method_call --print-reply --system \
  51.                     --dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr \
  52.                     org.ganesha.nfsd.exportmgr.ShowExports | grep -B 1 -we \
  53.                     "/"$VOL -e "/"$VOL"/" | grep uint16 | awk '{print $2}' \
  54.             | head -1)
  55.  
  56.         dbus-send --print-reply --system \
  57.         --dest=org.ganesha.nfsd /org/ganesha/nfsd/ExportMgr \
  58.         org.ganesha.nfsd.exportmgr.RemoveExport uint16:$removed_id
  59.         check_cmd_status `echo $?`
  60. }
  61.  
  62. #this function displays the mdcache stats and oc
  63. grep utilization
  64. function show_mdcache()
  65. {
  66.         dbus-send --print-reply  --system \
  67.         --dest=org.ganesha.nfsd  /org/ganesha/nfsd/ExportMgr \
  68.         org.ganesha.nfsd.exportstats.ShowCacheInode"
  69.        check_cmd_status `echo $?`
  70. }
  71.  
  72. if [ "$OPTION" = "on" ];
  73. then
  74.        dynamic_export_add $@
  75. fi
  76.  
  77. if [ "$OPTION" = "off" ];
  78. then
  79.        dynamic_export_remove $@
  80. fi
  81.  
  82. if [ "$OPTION" = "cache" ];
  83. then
  84.     show_mdcache()
  85. fi
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement