Skip to content

Commit

Permalink
Merge pull request #45 from stgraber/main
Browse files Browse the repository at this point in the history
More renaming
  • Loading branch information
stgraber authored Aug 17, 2023
2 parents e30869a + e9ae811 commit c785451
Show file tree
Hide file tree
Showing 30 changed files with 357 additions and 353 deletions.
50 changes: 25 additions & 25 deletions cmd/incus-agent/api_1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func setConnectionInfo(d *Daemon, rd io.Reader) error {
return err
}

d.devlxdMu.Lock()
d.DevIncusMu.Lock()
d.serverCID = data.CID
d.serverPort = data.Port
d.serverCertificate = data.Certificate
d.devlxdEnabled = data.Devlxd
d.devlxdMu.Unlock()
d.DevIncusEnabled = data.DevIncus
d.DevIncusMu.Unlock()

return nil
}
Expand All @@ -113,10 +113,10 @@ func api10Put(d *Daemon, r *http.Request) response.Response {
// Let LXD know, we were able to connect successfully.
d.chConnected <- struct{}{}

if d.devlxdEnabled {
err = startDevlxdServer(d)
if d.DevIncusEnabled {
err = startDevIncusServer(d)
} else {
err = stopDevlxdServer(d)
err = stopDevIncusServer(d)
}

if err != nil {
Expand All @@ -126,32 +126,32 @@ func api10Put(d *Daemon, r *http.Request) response.Response {
return response.EmptySyncResponse
}

func startDevlxdServer(d *Daemon) error {
d.devlxdMu.Lock()
defer d.devlxdMu.Unlock()
func startDevIncusServer(d *Daemon) error {
d.DevIncusMu.Lock()
defer d.DevIncusMu.Unlock()

// If a devlxd server is already running, don't start a second one.
if d.devlxdRunning {
// If a DevIncus server is already running, don't start a second one.
if d.DevIncusRunning {
return nil
}

servers["devlxd"] = devLxdServer(d)
servers["DevIncus"] = devLxdServer(d)

// Prepare the devlxd server.
devlxdListener, err := createDevLxdlListener("/dev")
// Prepare the DevIncus server.
DevIncusListener, err := createDevIncuslListener("/dev")
if err != nil {
return err
}

d.devlxdRunning = true
d.DevIncusRunning = true

// Start the devlxd listener.
// Start the DevIncus listener.
go func() {
err := servers["devlxd"].Serve(devlxdListener)
err := servers["DevIncus"].Serve(DevIncusListener)
if err != nil {
d.devlxdMu.Lock()
d.devlxdRunning = false
d.devlxdMu.Unlock()
d.DevIncusMu.Lock()
d.DevIncusRunning = false
d.DevIncusMu.Unlock()

// http.ErrServerClosed can be ignored as this is returned when the server is closed intentionally.
if !errors.Is(err, http.ErrServerClosed) {
Expand All @@ -163,12 +163,12 @@ func startDevlxdServer(d *Daemon) error {
return nil
}

func stopDevlxdServer(d *Daemon) error {
d.devlxdMu.Lock()
d.devlxdRunning = false
d.devlxdMu.Unlock()
func stopDevIncusServer(d *Daemon) error {
d.DevIncusMu.Lock()
d.DevIncusRunning = false
d.DevIncusMu.Unlock()

return servers["devlxd"].Close()
return servers["DevIncus"].Close()
}

func getClient(CID uint32, port int, serverCertificate string) (*http.Client, error) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/incus-agent/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type Daemon struct {
// The channel which is used to indicate that the lxd-agent was able to connect to LXD.
chConnected chan struct{}

devlxdRunning bool
devlxdMu sync.Mutex
devlxdEnabled bool
DevIncusRunning bool
DevIncusMu sync.Mutex
DevIncusEnabled bool
}

// newDaemon returns a new Daemon object with the given configuration.
Expand Down
30 changes: 15 additions & 15 deletions cmd/incus-agent/dev_incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/lxc/incus/incusd/device/config"
"github.com/lxc/incus/incusd/util"
"github.com/lxc/incus/shared"
"github.com/lxc/incus/shared/api"
"github.com/lxc/incus/shared/api/guest"
"github.com/lxc/incus/shared/logger"
)

// DevLxdServer creates an http.Server capable of handling requests against the
// DevIncusServer creates an http.Server capable of handling requests against the
// /dev/lxd Unix socket endpoint created inside VMs.
func devLxdServer(d *Daemon) *http.Server {
return &http.Server{
Expand Down Expand Up @@ -56,7 +56,7 @@ func getVsockClient(d *Daemon) (incus.InstanceServer, error) {
return server, nil
}

var devlxdConfigGet = devLxdHandler{"/1.0/config", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
var DevIncusConfigGet = devLxdHandler{"/1.0/config", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
client, err := getVsockClient(d)
if err != nil {
return smartResponse(fmt.Errorf("Failed connecting to LXD over vsock: %w", err))
Expand Down Expand Up @@ -85,7 +85,7 @@ var devlxdConfigGet = devLxdHandler{"/1.0/config", func(d *Daemon, w http.Respon
return okResponse(filtered, "json")
}}

var devlxdConfigKeyGet = devLxdHandler{"/1.0/config/{key}", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
var DevIncusConfigKeyGet = devLxdHandler{"/1.0/config/{key}", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
key, err := url.PathUnescape(mux.Vars(r)["key"])
if err != nil {
return &devLxdResponse{"bad request", http.StatusBadRequest, "raw"}
Expand Down Expand Up @@ -117,7 +117,7 @@ var devlxdConfigKeyGet = devLxdHandler{"/1.0/config/{key}", func(d *Daemon, w ht
return okResponse(value, "raw")
}}

var devlxdMetadataGet = devLxdHandler{"/1.0/meta-data", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
var DevIncusMetadataGet = devLxdHandler{"/1.0/meta-data", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
var client incus.InstanceServer
var err error

Expand Down Expand Up @@ -160,7 +160,7 @@ var devLxdEventsGet = devLxdHandler{"/1.0/events", func(d *Daemon, w http.Respon
return okResponse("", "raw")
}}

var devlxdAPIGet = devLxdHandler{"/1.0", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
var DevIncusAPIGet = devLxdHandler{"/1.0", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
client, err := getVsockClient(d)
if err != nil {
return smartResponse(fmt.Errorf("Failed connecting to LXD over vsock: %w", err))
Expand All @@ -174,7 +174,7 @@ var devlxdAPIGet = devLxdHandler{"/1.0", func(d *Daemon, w http.ResponseWriter,
return smartResponse(err)
}

var instanceData api.DevLXDGet
var instanceData api.DevIncusGet

err = resp.MetadataAsStruct(&instanceData)
if err != nil {
Expand All @@ -194,7 +194,7 @@ var devlxdAPIGet = devLxdHandler{"/1.0", func(d *Daemon, w http.ResponseWriter,
return &devLxdResponse{fmt.Sprintf("method %q not allowed", r.Method), http.StatusBadRequest, "raw"}
}}

var devlxdDevicesGet = devLxdHandler{"/1.0/devices", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
var DevIncusDevicesGet = devLxdHandler{"/1.0/devices", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
client, err := getVsockClient(d)
if err != nil {
return smartResponse(fmt.Errorf("Failed connecting to LXD over vsock: %w", err))
Expand All @@ -221,12 +221,12 @@ var handlers = []devLxdHandler{
{"/", func(d *Daemon, w http.ResponseWriter, r *http.Request) *devLxdResponse {
return okResponse([]string{"/1.0"}, "json")
}},
devlxdAPIGet,
devlxdConfigGet,
devlxdConfigKeyGet,
devlxdMetadataGet,
DevIncusAPIGet,
DevIncusConfigGet,
DevIncusConfigKeyGet,
DevIncusMetadataGet,
devLxdEventsGet,
devlxdDevicesGet,
DevIncusDevicesGet,
}

func hoistReq(f func(*Daemon, http.ResponseWriter, *http.Request) *devLxdResponse, d *Daemon) func(http.ResponseWriter, *http.Request) {
Expand Down Expand Up @@ -261,8 +261,8 @@ func devLxdAPI(d *Daemon) http.Handler {
return m
}

// Create a new net.Listener bound to the unix socket of the devlxd endpoint.
func createDevLxdlListener(dir string) (net.Listener, error) {
// Create a new net.Listener bound to the unix socket of the DevIncus endpoint.
func createDevIncuslListener(dir string) (net.Listener, error) {
path := filepath.Join(dir, "incus", "sock")

err := os.MkdirAll(filepath.Dir(path), 0755)
Expand Down
6 changes: 3 additions & 3 deletions cmd/incus-agent/main_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *cmdAgent) Run(cmd *cobra.Command, args []string) error {
}
}()

// Check whether we should start the devlxd server in the early setup. This way, /dev/lxd/sock
// Check whether we should start the DevIncus server in the early setup. This way, /dev/lxd/sock
// will be available for any systemd services starting after the lxd-agent.
if shared.PathExists("agent.conf") {
f, err := os.Open("agent.conf")
Expand All @@ -176,8 +176,8 @@ func (c *cmdAgent) Run(cmd *cobra.Command, args []string) error {

_ = f.Close()

if d.devlxdEnabled {
err = startDevlxdServer(d)
if d.DevIncusEnabled {
err = startDevIncusServer(d)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/incus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ func (c *cmdGlobal) PreRun(cmd *cobra.Command, args []string) error {
if os.Getenv("INCUS_CONF") != "" {
configDir = os.Getenv("INCUS_CONF")
} else if os.Getenv("HOME") != "" {
configDir = path.Join(os.Getenv("HOME"), ".config", "lxc")
configDir = path.Join(os.Getenv("HOME"), ".config", "incus")
} else {
user, err := user.Current()
if err != nil {
return err
}

configDir = path.Join(user.HomeDir, ".config", "lxc")
configDir = path.Join(user.HomeDir, ".config", "incus")
}

c.confPath = os.ExpandEnv(path.Join(configDir, "config.yml"))
Expand Down
2 changes: 1 addition & 1 deletion incusd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func hoistReqVM(f func(*Daemon, instance.Instance, http.ResponseWriter, *http.Re
}

func vSockServer(d *Daemon) *http.Server {
return &http.Server{Handler: devLxdAPI(d, hoistReqVM)}
return &http.Server{Handler: devIncusAPI(d, hoistReqVM)}
}

func metricsServer(d *Daemon) *http.Server {
Expand Down
6 changes: 3 additions & 3 deletions incusd/apparmor/instance_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ profile "{{ .name }}" flags=(attach_disconnected,mediate_deleted) {
mount fstype=sysfs -> /usr/lib/*/lxc/**,
# Allow nested LXD
mount none -> /var/lib/lxd/shmounts/,
mount /var/lib/lxd/shmounts/ -> /var/lib/lxd/shmounts/,
mount options=bind /var/lib/lxd/shmounts/** -> /var/lib/lxd/**,
mount none -> /var/lib/incus/shmounts/,
mount /var/lib/incus/shmounts/ -> /var/lib/incus/shmounts/,
mount options=bind /var/lib/incus/shmounts/** -> /var/lib/incus/**,
# FIXME: There doesn't seem to be a way to ask for:
# mount options=(ro,nosuid,nodev,noexec,remount,bind),
Expand Down
1 change: 1 addition & 0 deletions incusd/apparmor/instance_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ profile "{{ .name }}" flags=(attach_disconnected,mediate_deleted) {
/tmp/lxd_sev_* r,
/{,usr/}bin/qemu* mrix,
{{ .ovmfPath }}/OVMF_CODE.fd kr,
{{ .ovmfPath }}/OVMF_CODE_*.fd kr,
{{ .ovmfPath }}/OVMF_CODE.*.fd kr,
/usr/share/qemu/** kr,
/usr/share/seabios/** kr,
Expand Down
26 changes: 13 additions & 13 deletions incusd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Daemon struct {
dns *dns.Server

// Event servers
devlxdEvents *events.DevLXDServer
devIncusEvents *events.DevIncusServer
events *events.Server
internalListener *events.InternalListener

Expand Down Expand Up @@ -154,13 +154,13 @@ type DaemonConfig struct {
// newDaemon returns a new Daemon object with the given configuration.
func newDaemon(config *DaemonConfig, os *sys.OS) *Daemon {
lxdEvents := events.NewServer(daemon.Debug, daemon.Verbose, cluster.EventHubPush)
devlxdEvents := events.NewDevLXDServer(daemon.Debug, daemon.Verbose)
devIncusEvents := events.NewDevIncusServer(daemon.Debug, daemon.Verbose)
shutdownCtx, shutdownCancel := context.WithCancel(context.Background())

d := &Daemon{
clientCerts: &certificateCache{},
config: config,
devlxdEvents: devlxdEvents,
devIncusEvents: devIncusEvents,
events: lxdEvents,
db: &db.DB{},
http01Provider: acme.NewHTTP01Provider(),
Expand Down Expand Up @@ -307,8 +307,8 @@ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request) (bool, str
return true, "", "unix", nil
}

// Devlxd unix socket credentials on main API.
if r.RemoteAddr == "@devlxd" {
// DevIncus unix socket credentials on main API.
if r.RemoteAddr == "@devIncus" {
return false, "", "", fmt.Errorf("Main API query can't come from /dev/incus socket")
}

Expand Down Expand Up @@ -381,7 +381,7 @@ func (d *Daemon) State() *state.State {
OS: d.os,
Endpoints: d.endpoints,
Events: d.events,
DevlxdEvents: d.devlxdEvents,
DevIncusEvents: d.devIncusEvents,
Firewall: d.firewall,
Proxy: d.proxy,
ServerCert: d.serverCert,
Expand Down Expand Up @@ -998,12 +998,12 @@ func (d *Daemon) init() error {
logger.Warn("Failed setting up shared mounts", logger.Ctx{"err": err})
}

// Attempt to Mount the devlxd tmpfs
devlxd := filepath.Join(d.os.VarDir, "devlxd")
if !filesystem.IsMountPoint(devlxd) {
err = unix.Mount("tmpfs", devlxd, "tmpfs", 0, "size=100k,mode=0755")
// Attempt to Mount the devIncus tmpfs
devIncus := filepath.Join(d.os.VarDir, "devIncus")
if !filesystem.IsMountPoint(devIncus) {
err = unix.Mount("tmpfs", devIncus, "tmpfs", 0, "size=100k,mode=0755")
if err != nil {
logger.Warn("Failed to mount devlxd", logger.Ctx{"err": err})
logger.Warn("Failed to mount devIncus", logger.Ctx{"err": err})
}
}
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ func (d *Daemon) init() error {
UnixSocket: d.UnixSocket(),
Cert: networkCert,
RestServer: restServer(d),
DevLxdServer: devLxdServer(d),
DevIncusServer: devIncusServer(d),
LocalUnixSocketGroup: d.config.Group,
NetworkAddress: localHTTPAddress,
ClusterAddress: localClusterAddress,
Expand Down Expand Up @@ -1650,7 +1650,7 @@ func (d *Daemon) Stop(ctx context.Context, sig os.Signal) error {
if shouldUnmount {
logger.Info("Unmounting temporary filesystems")

_ = unix.Unmount(shared.VarPath("devlxd"), unix.MNT_DETACH)
_ = unix.Unmount(shared.VarPath("devIncus"), unix.MNT_DETACH)
_ = unix.Unmount(shared.VarPath("shmounts"), unix.MNT_DETACH)

logger.Info("Done unmounting temporary filesystems")
Expand Down
2 changes: 1 addition & 1 deletion incusd/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type Cluster struct {
// - name: Basename of the database file holding the data. Typically "db.bin".
// - dialer: Function used to connect to the dqlite backend via gRPC SQL.
// - address: Network address of this node (or empty string).
// - dir: Base LXD database directory (e.g. /var/lib/lxd/database)
// - dir: Base LXD database directory (e.g. /var/lib/incus/database)
// - timeout: Give up trying to open the database after this amount of time.
// - dump: If not nil, a copy of 2.0 db data, for migrating to 3.0.
//
Expand Down
Loading

0 comments on commit c785451

Please sign in to comment.