2 * Copyright (c) 2021 Cisco Systems and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * Copyright 2016 the Go-FUSE Authors. All rights reserved.
18 * Use of this source code is governed by a BSD-style
19 * license that can be found in the LICENSE file.
22 // This file is the main program driver to mount the stats segment filesystem.
34 "git.fd.io/govpp.git/adapter/statsclient"
35 "git.fd.io/govpp.git/core"
36 "github.com/hanwen/go-fuse/v2/fs"
40 statsSocket := flag.String("socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
41 debug := flag.Bool("debug", false, "print debugging messages.")
44 fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT\n", os.Args[0])
47 //Conection to the stat segment socket.
48 sc := statsclient.NewStatsClient(*statsSocket)
49 fmt.Printf("Waiting for the VPP socket to be available. Be sure a VPP instance is running.\n")
50 c, err := core.ConnectStats(sc)
52 fmt.Fprintf(os.Stderr, "Failed to connect to the stats socket: %v\n", err)
56 fmt.Printf("Connected to the socket\n")
57 //Creating the filesystem instance
58 root, err := NewStatsFileSystem(sc)
60 fmt.Fprintf(os.Stderr, "NewStatsFileSystem failed: %v\n", err)
64 //Mounting the filesystem.
67 opts.AllowOther = true
68 server, err := fs.Mount(flag.Arg(0), root, opts)
70 fmt.Fprintf(os.Stderr, "Mount fail: %v\n", err)
74 sigs := make(chan os.Signal)
75 signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
77 fmt.Printf("Successfully mounted the file system in directory: %s\n", flag.Arg(0))
84 fmt.Println("Unmounting...")
85 err := server.Unmount()
86 if err == nil || !strings.Contains(err.Error(), "Device or resource busy") {
89 fmt.Fprintf(os.Stderr, "Unmount fail: %v\n", err)