@@ -13,18 +13,21 @@ import (
1313 "github.com/hanwen/go-fuse/v2/fuse"
1414)
1515
16- // MountOptions options to mount
17- type MountOptions struct {
16+ // Mounter options to mount
17+ type Mounter struct {
1818 MountPoint string
1919 Config * dmConfig.Config
2020 Libdm * libdatamanager.LibDM
2121 Debug bool
2222 DebugFS bool
23+
24+ server * fuse.Server
25+ doneChan chan bool
2326}
2427
2528// Mount the fs
26- func (mopt * MountOptions ) Mount () {
27- mountDir := filepath .Clean (mopt .MountPoint )
29+ func (mounter * Mounter ) Mount () {
30+ mountDir := filepath .Clean (mounter .MountPoint )
2831 fmt .Printf ("Mounting on %s\n " , mountDir )
2932
3033 // Create mount dir if not exists
@@ -33,52 +36,65 @@ func (mopt *MountOptions) Mount() {
3336 }
3437
3538 // Test server availability
36- if ! mopt .testServer () {
39+ if ! mounter .testServer () {
3740 return
3841 }
3942
40- root := & dmanagerFilesystem {}
43+ // Init exit channels
44+ exitChan := make (chan bool , 1 )
45+ mounter .doneChan = make (chan bool , 1 )
46+
47+ // Create the fs
48+ root := & dmanagerFilesystem {
49+ mounter : mounter ,
50+ config : mounter .Config ,
51+ libdm : mounter .Libdm ,
52+ }
53+
54+ var err error
4155
4256 // Mount fs
43- server , err : = fs .Mount (mountDir , root , mopt .getMountOptions ())
57+ mounter . server , err = fs .Mount (mountDir , root , mounter .getMountOptions ())
4458 if err != nil {
4559 log .Fatal (err )
4660 }
4761
4862 // Umount fs on interrupt
49- exitChan := make (chan bool , 1 )
50- doneChan := make (chan bool , 1 )
5163 sigChan := make (chan os.Signal , 1 )
5264 go (func () {
5365 signal .Notify (sigChan , os .Interrupt , os .Kill )
66+
5467 // Await signal
5568 sig := <- sigChan
5669
5770 // Debug & Umount
5871 fmt .Println ("\r Received" , sig ) // Print \r to overwrite the ugly ^C
5972
6073 exitChan <- true
61-
62- server .Unmount ()
63-
64- fmt .Println ("Umounted" )
65- doneChan <- true
74+ mounter .umount ()
6675 })()
6776
6877 // Exit if mountpoint was
6978 // unmounted or process was interrupted
70- server .Wait ()
79+ mounter . server .Wait ()
7180 select {
7281 case <- exitChan :
73- <- doneChan
82+ <- mounter . doneChan
7483 default :
7584 fmt .Println ("umounted externally\n exiting" )
7685 }
7786}
7887
88+ // Umount fs
89+ func (mounter * Mounter ) umount () {
90+ mounter .server .Unmount ()
91+ fmt .Println ("Umounted" )
92+ mounter .doneChan <- true
93+ }
94+
7995// tests if server can be accessed and user is authorized
80- func (mopt * MountOptions ) testServer () bool {
81- _ , err := mopt .Libdm .GetNamespaces ()
96+ func (mounter * Mounter ) testServer () bool {
97+ _ , err := mounter .Libdm .GetNamespaces ()
8298 if err != nil {
8399 fmt .Println ("Can't mount:" , err )
84100 return false
@@ -88,10 +104,10 @@ func (mopt *MountOptions) testServer() bool {
88104}
89105
90106// Get the mountoptions for the mount operation
91- func (mopt * MountOptions ) getMountOptions () * fs.Options {
107+ func (mounter * Mounter ) getMountOptions () * fs.Options {
92108 return & fs.Options {
93109 MountOptions : fuse.MountOptions {
94- Debug : mopt .DebugFS ,
110+ Debug : mounter .DebugFS ,
95111 AllowOther : false ,
96112 FsName : "Datamanager mount" ,
97113 Name : "dmanager" ,
0 commit comments