Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/incusd/api_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestCluster_Bootstrap(t *testing.T) {
// request is issued to set both core.https_address and
// cluster.https_address to the same value.
f := clusterFixture{t: t}
f.EnableNetworkingWithClusterAddress(daemon, "")
f.EnableNetworkingWithClusterAddress(daemon)

client := f.ClientUnix(daemon)

Expand Down Expand Up @@ -74,7 +74,7 @@ func TestCluster_RenameNode(t *testing.T) {
defer cleanup()

f := clusterFixture{t: t}
f.EnableNetworking(daemon, "")
f.EnableNetworking(daemon)

client := f.ClientUnix(daemon)

Expand All @@ -101,7 +101,7 @@ type clusterFixture struct {

// Enable networking in the given daemon. The password is optional and can be
// an empty string.
func (f *clusterFixture) EnableNetworking(daemon *Daemon, password string) {
func (f *clusterFixture) EnableNetworking(daemon *Daemon) {
port, err := allocatePort()
require.NoError(f.t, err)

Expand All @@ -119,7 +119,7 @@ func (f *clusterFixture) EnableNetworking(daemon *Daemon, password string) {
// Enable networking in the given daemon, and set cluster.https_address to the
// same value as core.https address. The password is optional and can be an
// empty string.
func (f *clusterFixture) EnableNetworkingWithClusterAddress(daemon *Daemon, password string) {
func (f *clusterFixture) EnableNetworkingWithClusterAddress(daemon *Daemon) {
port, err := allocatePort()
require.NoError(f.t, err)

Expand Down
12 changes: 6 additions & 6 deletions cmd/incusd/api_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func internalOptimizeImage(d *Daemon, r *http.Request) response.Response {
return response.EmptySyncResponse
}

func internalRefreshImage(d *Daemon, r *http.Request) response.Response {
func internalRefreshImage(d *Daemon, _ *http.Request) response.Response {
s := d.State()

err := autoUpdateImages(s.ShutdownCtx, s)
Expand All @@ -275,7 +275,7 @@ func internalRefreshImage(d *Daemon, r *http.Request) response.Response {
return response.EmptySyncResponse
}

func internalWaitReady(d *Daemon, r *http.Request) response.Response {
func internalWaitReady(d *Daemon, _ *http.Request) response.Response {
// Check that we're not shutting down.
isClosing := d.State().ShutdownCtx.Err() != nil
if isClosing {
Expand Down Expand Up @@ -1089,7 +1089,7 @@ func internalImportRootDevicePopulate(instancePoolName string, localDevices map[
}
}

func internalGC(d *Daemon, r *http.Request) response.Response {
func internalGC(_ *Daemon, _ *http.Request) response.Response {
logger.Infof("Started forced garbage collection run")
runtime.GC()
runtimeDebug.FreeOSMemory()
Expand All @@ -1106,19 +1106,19 @@ func internalGC(d *Daemon, r *http.Request) response.Response {
return response.EmptySyncResponse
}

func internalRAFTSnapshot(d *Daemon, r *http.Request) response.Response {
func internalRAFTSnapshot(_ *Daemon, _ *http.Request) response.Response {
logger.Warn("Forced RAFT snapshot not supported")

return response.InternalError(fmt.Errorf("Not supported"))
}

func internalBGPState(d *Daemon, r *http.Request) response.Response {
func internalBGPState(d *Daemon, _ *http.Request) response.Response {
s := d.State()

return response.SyncResponse(true, s.BGP.Debug())
}

func internalRebalanceLoad(d *Daemon, r *http.Request) response.Response {
func internalRebalanceLoad(d *Daemon, _ *http.Request) response.Response {
err := autoRebalanceCluster(context.TODO(), d)
if err != nil {
return response.SmartError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/incusd/api_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var apiOS = APIEndpoint{
Head: APIEndpointAction{Handler: apiOSProxy, AccessHandler: allowPermission(auth.ObjectTypeServer, auth.EntitlementCanEdit)},
}

func apiOSProxy(d *Daemon, r *http.Request) response.Response {
func apiOSProxy(_ *Daemon, r *http.Request) response.Response {
// Check if this is an Incus OS system.
if !util.PathExists("/run/incus-os/unix.socket") {
return response.BadRequest(errors.New("System isn't running Incus OS"))
Expand Down
8 changes: 4 additions & 4 deletions cmd/incusd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func volumeBackupCreate(s *state.State, args db.StoragePoolVolumeBackup, project

// Write index file.
l.Debug("Adding backup index file")
err = volumeBackupWriteIndex(s, projectName, volumeName, pool, backupRow.OptimizedStorage, !backupRow.VolumeOnly, tarWriter)
err = volumeBackupWriteIndex(projectName, volumeName, pool, backupRow.OptimizedStorage, !backupRow.VolumeOnly, tarWriter)

// Check compression errors.
if compressErr != nil {
Expand Down Expand Up @@ -542,7 +542,7 @@ func volumeBackupCreate(s *state.State, args db.StoragePoolVolumeBackup, project
}

// volumeBackupWriteIndex generates an index.yaml file and then writes it to the root of the backup tarball.
func volumeBackupWriteIndex(s *state.State, projectName string, volumeName string, pool storagePools.Pool, optimized bool, snapshots bool, tarWriter *instancewriter.InstanceTarWriter) error {
func volumeBackupWriteIndex(projectName string, volumeName string, pool storagePools.Pool, optimized bool, snapshots bool, tarWriter *instancewriter.InstanceTarWriter) error {
// Indicate whether the driver will include a driver-specific optimized header.
poolDriverOptimizedHeader := false
if optimized {
Expand Down Expand Up @@ -744,7 +744,7 @@ func bucketBackupCreate(s *state.State, args db.StoragePoolBucketBackup, project

// Write index file.
l.Debug("Adding backup index file")
err = bucketBackupWriteIndex(s, projectName, bucketName, pool, tarWriter)
err = bucketBackupWriteIndex(projectName, bucketName, pool, tarWriter)

// Check compression errors.
if compressErr != nil {
Expand Down Expand Up @@ -788,7 +788,7 @@ func bucketBackupCreate(s *state.State, args db.StoragePoolBucketBackup, project
}

// bucketBackupWriteIndex generates an index.yaml file and then writes it to the root of the backup tarball.
func bucketBackupWriteIndex(s *state.State, projectName string, bucketName string, pool storagePools.Pool, tarWriter *instancewriter.InstanceTarWriter) error {
func bucketBackupWriteIndex(projectName string, bucketName string, pool storagePools.Pool, tarWriter *instancewriter.InstanceTarWriter) error {
config, err := pool.GenerateBucketBackupConfig(projectName, bucketName, nil)
if err != nil {
return fmt.Errorf("Failed generating storage backup config: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/incusd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ func (d *Daemon) init() error {

// Mount the storage pools.
logger.Infof("Initializing storage pools")
err = storageStartup(d.State(), false)
err = storageStartup(d.State())
if err != nil {
return err
}
Expand Down Expand Up @@ -1830,7 +1830,7 @@ func (d *Daemon) Stop(ctx context.Context, sig os.Signal) error {

// Full shutdown requested.
if sig == unix.SIGPWR {
instancesShutdown(s, instances)
instancesShutdown(instances)

logger.Info("Stopping networks")
networkShutdown(s)
Expand Down Expand Up @@ -2336,7 +2336,7 @@ func (d *Daemon) hasMemberStateChanged(heartbeatData *cluster.APIHeartbeat) bool
}

// heartbeatHandler handles heartbeat requests from other cluster members.
func (d *Daemon) heartbeatHandler(w http.ResponseWriter, r *http.Request, isLeader bool, hbData *cluster.APIHeartbeat) {
func (d *Daemon) heartbeatHandler(w http.ResponseWriter, _ *http.Request, isLeader bool, hbData *cluster.APIHeartbeat) {
s := d.State()

var err error
Expand Down
2 changes: 1 addition & 1 deletion cmd/incusd/dev_incus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DevIncusDialer struct {
Path string
}

func (d DevIncusDialer) DevIncusDial(ctx context.Context, network, path string) (net.Conn, error) {
func (d DevIncusDialer) DevIncusDial(context.Context, string, string) (net.Conn, error) {
addr, err := net.ResolveUnixAddr("unix", d.Path)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions cmd/incusd/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func instanceImageTransfer(s *state.State, r *http.Request, projectName string,
return nil
}

func ensureImageIsLocallyAvailable(ctx context.Context, s *state.State, r *http.Request, img *api.Image, projectName string, instanceType instancetype.Type) error {
func ensureImageIsLocallyAvailable(ctx context.Context, s *state.State, r *http.Request, img *api.Image, projectName string) error {
// Check if the image is available locally or it's on another member.
// Ensure we are the only ones operating on this image. Otherwise another instance created at the same
// time may also arrive at the conclusion that the image doesn't exist on this cluster member and then
Expand Down Expand Up @@ -134,7 +134,7 @@ func ensureImageIsLocallyAvailable(ctx context.Context, s *state.State, r *http.
}

// instanceCreateFromImage creates an instance from a rootfs image.
func instanceCreateFromImage(ctx context.Context, s *state.State, r *http.Request, img *api.Image, args db.InstanceArgs, op *operations.Operation) error {
func instanceCreateFromImage(ctx context.Context, s *state.State, img *api.Image, args db.InstanceArgs, op *operations.Operation) error {
reverter := revert.New()
defer reverter.Fail()

Expand Down Expand Up @@ -289,7 +289,7 @@ func instanceRebuildFromImage(ctx context.Context, s *state.State, r *http.Reque
return fmt.Errorf("Requested image's type %q doesn't match instance type %q", imgType, inst.Type())
}

err = ensureImageIsLocallyAvailable(ctx, s, r, img, inst.Project().Name, inst.Type())
err = ensureImageIsLocallyAvailable(ctx, s, r, img, inst.Project().Name)
if err != nil {
return err
}
Expand All @@ -302,7 +302,7 @@ func instanceRebuildFromImage(ctx context.Context, s *state.State, r *http.Reque
return nil
}

func instanceRebuildFromEmpty(s *state.State, inst instance.Instance, op *operations.Operation) error {
func instanceRebuildFromEmpty(inst instance.Instance, op *operations.Operation) error {
err := inst.Rebuild(nil, op) // Rebuild as empty.
if err != nil {
return fmt.Errorf("Failed rebuilding as an empty instance: %w", err)
Expand Down Expand Up @@ -588,7 +588,7 @@ func autoCreateInstanceSnapshots(ctx context.Context, s *state.State, instances

var instSnapshotsPruneRunning = sync.Map{}

func pruneExpiredInstanceSnapshots(ctx context.Context, s *state.State, snapshots []instance.Instance) error {
func pruneExpiredInstanceSnapshots(ctx context.Context, snapshots []instance.Instance) error {
// Find snapshots to delete
for _, snapshot := range snapshots {
err := ctx.Err()
Expand Down Expand Up @@ -736,7 +736,7 @@ func pruneExpiredAndAutoCreateInstanceSnapshotsTask(d *Daemon) (task.Func, task.
// disk space.
if len(expiredSnapshotInstances) > 0 {
opRun := func(op *operations.Operation) error {
return pruneExpiredInstanceSnapshots(ctx, s, expiredSnapshotInstances)
return pruneExpiredInstanceSnapshots(ctx, expiredSnapshotInstances)
}

op, err := operations.OperationCreate(s, "", operations.OperationClassTask, operationtype.SnapshotsExpire, nil, nil, opRun, nil, nil, nil)
Expand Down
26 changes: 13 additions & 13 deletions cmd/incusd/instance_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type consoleWs struct {
protocol string
}

func (s *consoleWs) Metadata() any {
func (s *consoleWs) metadata() any {
fds := jmap.Map{}
for fd, secret := range s.fds {
if fd == -1 {
Expand All @@ -83,18 +83,18 @@ func (s *consoleWs) Metadata() any {
return jmap.Map{"fds": fds}
}

func (s *consoleWs) Connect(op *operations.Operation, r *http.Request, w http.ResponseWriter) error {
func (s *consoleWs) connect(_ *operations.Operation, r *http.Request, w http.ResponseWriter) error {
switch s.protocol {
case instance.ConsoleTypeConsole:
return s.connectConsole(op, r, w)
return s.connectConsole(r, w)
case instance.ConsoleTypeVGA:
return s.connectVGA(op, r, w)
return s.connectVGA(r, w)
default:
return fmt.Errorf("Unknown protocol %q", s.protocol)
}
}

func (s *consoleWs) connectConsole(op *operations.Operation, r *http.Request, w http.ResponseWriter) error {
func (s *consoleWs) connectConsole(r *http.Request, w http.ResponseWriter) error {
secret := r.FormValue("secret")
if secret == "" {
return fmt.Errorf("missing secret")
Expand Down Expand Up @@ -135,7 +135,7 @@ func (s *consoleWs) connectConsole(op *operations.Operation, r *http.Request, w
return os.ErrPermission
}

func (s *consoleWs) connectVGA(op *operations.Operation, r *http.Request, w http.ResponseWriter) error {
func (s *consoleWs) connectVGA(r *http.Request, w http.ResponseWriter) error {
secret := r.FormValue("secret")
if secret == "" {
return fmt.Errorf("missing secret")
Expand Down Expand Up @@ -196,20 +196,20 @@ func (s *consoleWs) connectVGA(op *operations.Operation, r *http.Request, w http
return os.ErrPermission
}

func (s *consoleWs) Do(op *operations.Operation) error {
func (s *consoleWs) do(op *operations.Operation) error {
s.instance.SetOperation(op)

switch s.protocol {
case instance.ConsoleTypeConsole:
return s.doConsole(op)
return s.doConsole()
case instance.ConsoleTypeVGA:
return s.doVGA(op)
return s.doVGA()
default:
return fmt.Errorf("Unknown protocol %q", s.protocol)
}
}

func (s *consoleWs) doConsole(op *operations.Operation) error {
func (s *consoleWs) doConsole() error {
defer logger.Debug("Console websocket finished")
<-s.allConnected

Expand Down Expand Up @@ -342,7 +342,7 @@ func (s *consoleWs) doConsole(op *operations.Operation) error {
return nil
}

func (s *consoleWs) doVGA(op *operations.Operation) error {
func (s *consoleWs) doVGA() error {
defer logger.Debug("VGA websocket finished")

consoleDoneCh := make(chan struct{})
Expand Down Expand Up @@ -389,7 +389,7 @@ func (s *consoleWs) doVGA(op *operations.Operation) error {
}

// Cancel is responsible for closing websocket connections.
func (s *consoleWs) Cancel(op *operations.Operation) error {
func (s *consoleWs) cancel(*operations.Operation) error {
s.connsLock.Lock()
conn := s.conns[-1]
s.connsLock.Unlock()
Expand Down Expand Up @@ -570,7 +570,7 @@ func instanceConsolePost(d *Daemon, r *http.Request) response.Response {
resources := map[string][]api.URL{}
resources["instances"] = []api.URL{*api.NewURL().Path(version.APIVersion, "instances", ws.instance.Name())}

op, err := operations.OperationCreate(s, projectName, operations.OperationClassWebsocket, operationtype.ConsoleShow, resources, ws.Metadata(), ws.Do, ws.Cancel, ws.Connect, r)
op, err := operations.OperationCreate(s, projectName, operations.OperationClassWebsocket, operationtype.ConsoleShow, resources, ws.metadata(), ws.do, ws.cancel, ws.connect, r)
if err != nil {
return response.InternalError(err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/incusd/instance_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type execWs struct {
s *state.State
}

func (s *execWs) Metadata() any {
func (s *execWs) metadata() any {
fds := jmap.Map{}
for fd, secret := range s.fds {
if fd == execWSControl {
Expand All @@ -79,7 +79,7 @@ func (s *execWs) Metadata() any {
}
}

func (s *execWs) Connect(op *operations.Operation, r *http.Request, w http.ResponseWriter) error {
func (s *execWs) connect(_ *operations.Operation, r *http.Request, w http.ResponseWriter) error {
secret := r.FormValue("secret")
if secret == "" {
return fmt.Errorf("missing secret")
Expand Down Expand Up @@ -159,7 +159,7 @@ func (s *execWs) Connect(op *operations.Operation, r *http.Request, w http.Respo
return os.ErrPermission
}

func (s *execWs) Do(op *operations.Operation) error {
func (s *execWs) do(op *operations.Operation) error {
s.instance.SetOperation(op)

// Once this function ends ensure that any connected websockets are closed.
Expand Down Expand Up @@ -702,7 +702,7 @@ func instanceExecPost(d *Daemon, r *http.Request) response.Response {
resources := map[string][]api.URL{}
resources["instances"] = []api.URL{*api.NewURL().Path(version.APIVersion, "instances", ws.instance.Name())}

op, err := operations.OperationCreate(s, projectName, operations.OperationClassWebsocket, operationtype.CommandExec, resources, ws.Metadata(), ws.Do, nil, ws.Connect, r)
op, err := operations.OperationCreate(s, projectName, operations.OperationClassWebsocket, operationtype.CommandExec, resources, ws.metadata(), ws.do, nil, ws.connect, r)
if err != nil {
return response.InternalError(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/incusd/instance_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func instanceFileGet(s *state.State, inst instance.Instance, path string, r *htt
// $ref: "#/responses/NotFound"
// "500":
// $ref: "#/responses/InternalServerError"
func instanceFileHead(s *state.State, inst instance.Instance, path string, r *http.Request) response.Response {
func instanceFileHead(_ *state.State, inst instance.Instance, path string, _ *http.Request) response.Response {
reverter := revert.New()
defer reverter.Fail()

Expand Down Expand Up @@ -588,7 +588,7 @@ func instanceFilePost(s *state.State, inst instance.Instance, path string, r *ht
// $ref: "#/responses/NotFound"
// "500":
// $ref: "#/responses/InternalServerError"
func instanceFileDelete(s *state.State, inst instance.Instance, path string, r *http.Request) response.Response {
func instanceFileDelete(s *state.State, inst instance.Instance, path string, _ *http.Request) response.Response {
// Get a SFTP client.
client, err := inst.FileSFTP()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/incusd/instance_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func instancePost(d *Daemon, r *http.Request) response.Response {
resources := map[string][]api.URL{}
resources["instances"] = []api.URL{*api.NewURL().Path(version.APIVersion, "instances", name)}
run := func(op *operations.Operation) error {
return ws.Do(s, op)
return ws.do(op)
}

cancel := func(op *operations.Operation) error {
Expand Down Expand Up @@ -868,7 +868,7 @@ func migrateInstance(ctx context.Context, s *state.State, inst instance.Instance
}

run := func(op *operations.Operation) error {
return sourceMigration.Do(s, op)
return sourceMigration.do(op)
}

cancel := func(op *operations.Operation) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/incusd/instance_rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func instanceRebuildPost(d *Daemon, r *http.Request) response.Response {

run := func(op *operations.Operation) error {
if req.Source.Type == "none" {
return instanceRebuildFromEmpty(s, inst, op)
return instanceRebuildFromEmpty(inst, op)
}

if req.Source.Server != "" {
sourceImage, err = ensureDownloadedImageFitWithinBudget(context.TODO(), s, r, op, *targetProject, sourceImage, sourceImageRef, req.Source, inst.Type().String())
sourceImage, err = ensureDownloadedImageFitWithinBudget(context.TODO(), s, r, op, *targetProject, sourceImageRef, req.Source, inst.Type().String())
if err != nil {
return err
}
Expand Down
Loading