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.
36 "git.fd.io/govpp.git/adapter/statsclient"
37 "git.fd.io/govpp.git/core"
38 "github.com/hanwen/go-fuse/v2/fs"
41 func LogMsg(msg string) {
42 fmt.Fprint(os.Stderr, msg)
47 syslogger, err := syslog.New(syslog.LOG_ERR|syslog.LOG_DAEMON, "statsfs")
51 log.SetOutput(syslogger)
53 statsSocket := flag.String("socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
54 debug := flag.Bool("debug", false, "print debugging messages.")
58 LogMsg(fmt.Sprintf("usage: %s MOUNTPOINT\n", os.Args[0]))
61 //Conection to the stat segment socket.
62 sc := statsclient.NewStatsClient(*statsSocket)
63 fmt.Println("Waiting for the VPP socket to be available. Be sure a VPP instance is running.")
64 c, err := core.ConnectStats(sc)
66 LogMsg(fmt.Sprintf("Failed to connect to the stats socket: %v\n", err))
70 fmt.Printf("Connected to the socket\n")
71 //Creating the filesystem instance
72 root, err := NewStatsFileSystem(sc)
74 LogMsg(fmt.Sprintf("NewStatsFileSystem failed: %v\n", err))
78 //Mounting the filesystem.
81 opts.AllowOther = true
82 server, err := fs.Mount(flag.Arg(0), root, opts)
84 LogMsg(fmt.Sprintf("Mount fail: %v\n", err))
88 sigs := make(chan os.Signal)
89 signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
91 fmt.Printf("Successfully mounted the file system in directory: %s\n", flag.Arg(0))
98 fmt.Println("Unmounting...")
99 err := server.Unmount()
100 if err == nil || !strings.Contains(err.Error(), "Device or resource busy") {
103 LogMsg(fmt.Sprintf("Unmount fail: %v\n", err))