Skip to content

Commit

Permalink
Merge pull request #4014 from stgraber/master
Browse files Browse the repository at this point in the history
Typos and unchecked variables
  • Loading branch information
Christian Brauner committed Nov 9, 2017
2 parents 1d67e94 + 9112b45 commit 044bad7
Show file tree
Hide file tree
Showing 35 changed files with 121 additions and 47 deletions.
2 changes: 1 addition & 1 deletion doc/api-extensions.md
Expand Up @@ -291,7 +291,7 @@ map auto-selection process for isolated containers and specify what host
uid/gid to use as the base.

## file\_symlinks
This adds support for transfering symlinks through the file API.
This adds support for transferring symlinks through the file API.
X-LXD-type can now be "symlink" with the request content being the target path.

## container\_push\_target
Expand Down
4 changes: 2 additions & 2 deletions doc/container-environment.md
Expand Up @@ -76,7 +76,7 @@ privileged containers.

## Network
LXD containers may have any number of network devices attached to them.
The naming for those unless overriden by the user is ethX where X is an incrementing number.
The naming for those unless overridden by the user is ethX where X is an incrementing number.

## Container to host communication
LXD sets up a socket at `/dev/lxd/sock` which root in the container can use to communicate with LXD on the host.
Expand All @@ -86,5 +86,5 @@ The API is [documented here](dev-lxd.md).
## LXCFS
If LXCFS is present on the host, it will automatically be setup for the container.

This normally results in a number of `/proc` files being overriden through bind-mounts.
This normally results in a number of `/proc` files being overridden through bind-mounts.
On older kernels a virtual version of `/sys/fs/cgroup` may also be setup by LXCFS.
6 changes: 3 additions & 3 deletions doc/containers.md
Expand Up @@ -102,7 +102,7 @@ and should whenever possible be avoided.
# Devices configuration
LXD will always provide the container with the basic devices which are required
for a standard POSIX system to work. These aren't visible in container or
profile configuration and may not be overriden.
profile configuration and may not be overridden.

Those includes:

Expand All @@ -128,7 +128,7 @@ Devices may be added or removed while the container is running.

Every device entry is identified by a unique name. If the same name is used in
a subsequent profile or in the container's own configuration, the whole entry
is overriden by the new definition.
is overridden by the new definition.

Device entries are added to a container through:

Expand Down Expand Up @@ -212,7 +212,7 @@ The `sriov` interface type supports SR-IOV enabled network devices. These
devices associate a set of virtual functions (VFs) with the single physical
function (PF) of the network device. PFs are standard PCIe functions. VFs on
the other hand are very lightweight PCIe functions that are optimized for data
movement. They come with a limited set of configuration capabilites to prevent
movement. They come with a limited set of configuration capabilities to prevent
changing properties of the PF. Given that VFs appear as regular PCIe devices to
the system they can be passed to containers just like a regular physical
device. The `sriov` interface type expects to be passed the name of an SR-IOV
Expand Down
2 changes: 1 addition & 1 deletion doc/index.md
Expand Up @@ -228,7 +228,7 @@ Note that LXD containers cannot load kernel modules, so depending on your
Docker configuration you may need to have the needed extra kernel modules
loaded by the host.

You can do so by setting a comma seperate list of kernel modules that your container needs with:
You can do so by setting a comma separate list of kernel modules that your container needs with:

```bash
lxc config set <container> linux.kernel_modules <modules>
Expand Down
2 changes: 1 addition & 1 deletion doc/preseed.md
Expand Up @@ -68,7 +68,7 @@ preseed.

Differently from the interactive init mode, the `lxd init --preseed`
command line will not modify the default profile in any particular
way, unless you explicitely express that in the provided YAML payload.
way, unless you explicitly express that in the provided YAML payload.

For instance, you will typically want to attach a root disk device and
a network interface to your default profile. See below for an example.
Expand Down
4 changes: 4 additions & 0 deletions lxc/config/file.go
Expand Up @@ -78,6 +78,10 @@ func (c *Config) SaveConfig(path string) error {

// Write the new config
data, err := yaml.Marshal(c)
if err != nil {
return fmt.Errorf("Unable to marshal the configuration: %v", err)
}

_, err = f.Write(data)
if err != nil {
return fmt.Errorf("Unable to write the configuration: %v", err)
Expand Down
3 changes: 3 additions & 0 deletions lxc/file.go
Expand Up @@ -563,6 +563,9 @@ func (c *fileCmd) edit(conf *config.Config, args []string) error {

// Create temp file
f, err := ioutil.TempFile("", "lxd_file_edit_")
if err != nil {
return fmt.Errorf("Unable to create a temporary file: %v", err)
}
fname := f.Name()
f.Close()
os.Remove(fname)
Expand Down
20 changes: 17 additions & 3 deletions lxd/container_lxc.go
Expand Up @@ -5153,9 +5153,15 @@ func (c *containerLXC) cpuState() api.ContainerStateCPU {

// CPU usage in seconds
value, err := c.CGroupGet("cpuacct.usage")
if err != nil {
cpu.Usage = -1
return cpu
}

valueInt, err := strconv.ParseInt(value, 10, 64)
if err != nil {
valueInt = -1
cpu.Usage = -1
return cpu
}

cpu.Usage = valueInt
Expand Down Expand Up @@ -5283,6 +5289,10 @@ func (c *containerLXC) processesState() int64 {

if c.state.OS.CGroupPidsController {
value, err := c.CGroupGet("pids.current")
if err != nil {
return -1
}

valueInt, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return -1
Expand Down Expand Up @@ -5431,7 +5441,7 @@ func (c *containerLXC) StorageStartSensitive() (bool, error) {
return false, err
}

isOurOperation := false
var isOurOperation bool
if c.IsSnapshot() {
isOurOperation, err = c.storage.ContainerSnapshotStart(c)
} else {
Expand All @@ -5448,7 +5458,7 @@ func (c *containerLXC) StorageStop() (bool, error) {
return false, err
}

isOurOperation := false
var isOurOperation bool
if c.IsSnapshot() {
isOurOperation, err = c.storage.ContainerSnapshotStop(c)
} else {
Expand Down Expand Up @@ -6314,6 +6324,10 @@ func (c *containerLXC) createNetworkFilter(name string, bridge string, hwaddr st

func (c *containerLXC) removeNetworkFilter(hwaddr string, bridge string) error {
out, err := shared.RunCommand("ebtables", "-L", "--Lmac2", "--Lx")
if err != nil {
return err
}

for _, line := range strings.Split(out, "\n") {
line = strings.TrimSpace(line)
fields := strings.Fields(line)
Expand Down
3 changes: 1 addition & 2 deletions lxd/container_put.go
Expand Up @@ -45,8 +45,7 @@ func containerPut(d *Daemon, r *http.Request) Response {
architecture = 0
}

var do = func(*operation) error { return nil }

var do func(*operation) error
if configRaw.Restore == "" {
// Update container configuration
do = func(op *operation) error {
Expand Down
4 changes: 2 additions & 2 deletions lxd/db/containers.go
Expand Up @@ -136,7 +136,7 @@ func (n *Node) ContainerGet(name string) (ContainerArgs, error) {
}

func (n *Node) ContainerCreate(args ContainerArgs) (int, error) {
id, err := n.ContainerId(args.Name)
_, err := n.ContainerId(args.Name)
if err == nil {
return 0, DbErrAlreadyDefined
}
Expand Down Expand Up @@ -178,7 +178,7 @@ func (n *Node) ContainerCreate(args ContainerArgs) (int, error) {
return 0, fmt.Errorf("Error inserting %s into database", args.Name)
}
// TODO: is this really int64? we should fix it everywhere if so
id = int(id64)
id := int(id64)
if err := ContainerConfigInsert(tx, id, args.Config); err != nil {
tx.Rollback()
return 0, err
Expand Down
1 change: 1 addition & 0 deletions lxd/db/db_internal_test.go
Expand Up @@ -124,6 +124,7 @@ func (s *dbTestSuite) Test_deleting_a_profile_cascades_on_related_tables() {
// Make sure there are 0 container_profiles entries left.
statements = `SELECT count(*) FROM containers_profiles WHERE profile_id = 2;`
err = s.db.DB().QueryRow(statements).Scan(&count)
s.Nil(err)
s.Equal(count, 0, "Deleting a profile didn't delete the container association!")

// Make sure there are 0 profiles_devices entries left.
Expand Down
4 changes: 4 additions & 0 deletions lxd/db/images.go
Expand Up @@ -435,6 +435,10 @@ func (n *Node) ImageUpdate(id int, fname string, sz int64, public bool, autoUpda
}

_, err = tx.Exec(`DELETE FROM images_properties WHERE image_id=?`, id)
if err != nil {
tx.Rollback()
return err
}

stmt, err = tx.Prepare(`INSERT INTO images_properties (image_id, type, key, value) VALUES (?, ?, ?, ?)`)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions lxd/db/networks.go
Expand Up @@ -215,6 +215,9 @@ func NetworkConfigAdd(tx *sql.Tx, id int64, config map[string]string) error {
str := fmt.Sprintf("INSERT INTO networks_config (network_id, key, value) VALUES(?, ?, ?)")
stmt, err := tx.Prepare(str)
defer stmt.Close()
if err != nil {
return err
}

for k, v := range config {
if v == "" {
Expand Down
1 change: 1 addition & 0 deletions lxd/db/node/open_test.go
Expand Up @@ -27,6 +27,7 @@ func TestEnsureSchema(t *testing.T) {
defer cleanup()

db, err := node.Open(dir)
require.NoError(t, err)
defer db.Close()

hookHasRun := false
Expand Down
3 changes: 3 additions & 0 deletions lxd/db/profiles.go
Expand Up @@ -222,6 +222,9 @@ func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error {
str := fmt.Sprintf("INSERT INTO profiles_config (profile_id, key, value) VALUES(?, ?, ?)")
stmt, err := tx.Prepare(str)
defer stmt.Close()
if err != nil {
return err
}

for k, v := range config {
_, err = stmt.Exec(id, k, v)
Expand Down
1 change: 1 addition & 0 deletions lxd/db/schema/schema_test.go
Expand Up @@ -71,6 +71,7 @@ func TestSchemaEnsure_MissingVersion(t *testing.T) {
assert.NoError(t, err)

_, err = db.Exec(`INSERT INTO schema (version, updated_at) VALUES (3, strftime("%s"))`)
assert.NoError(t, err)

schema.Add(updateNoop)
schema.Add(updateNoop)
Expand Down
3 changes: 3 additions & 0 deletions lxd/db/storage_pools.go
Expand Up @@ -169,6 +169,9 @@ func StoragePoolConfigAdd(tx *sql.Tx, poolID int64, poolConfig map[string]string
str := "INSERT INTO storage_pools_config (storage_pool_id, key, value) VALUES(?, ?, ?)"
stmt, err := tx.Prepare(str)
defer stmt.Close()
if err != nil {
return err
}

for k, v := range poolConfig {
if v == "" {
Expand Down
3 changes: 3 additions & 0 deletions lxd/db/storage_volumes.go
Expand Up @@ -58,6 +58,9 @@ func StorageVolumeConfigAdd(tx *sql.Tx, volumeID int64, volumeConfig map[string]
str := "INSERT INTO storage_volumes_config (storage_volume_id, key, value) VALUES(?, ?, ?)"
stmt, err := tx.Prepare(str)
defer stmt.Close()
if err != nil {
return err
}

for k, v := range volumeConfig {
if v == "" {
Expand Down
3 changes: 3 additions & 0 deletions lxd/devices.go
Expand Up @@ -442,6 +442,9 @@ func deviceNetlinkListener() (chan []string, chan []string, chan usbDevice, erro
}

devname, ok := props["DEVNAME"]
if !ok {
continue
}

busnum, ok := props["BUSNUM"]
if !ok {
Expand Down
4 changes: 4 additions & 0 deletions lxd/main_forkmigrate.go
Expand Up @@ -28,7 +28,11 @@ func cmdForkMigrate(args *Args) error {
lxcpath := args.Params[1]
configPath := args.Params[2]
imagesDir := args.Params[3]

preservesInodes, err := strconv.ParseBool(args.Params[4])
if err != nil {
return err
}

c, err := lxc.NewContainer(name, lxcpath)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions lxd/networks_utils.go
Expand Up @@ -183,8 +183,7 @@ func networkGetIP(subnet *net.IPNet, host int64) net.IP {

// Generate an IPv6
if subnet.IP.To4() == nil {
newIp := make(net.IP, 16)
newIp = bigIP.Bytes()
newIp := bigIP.Bytes()
return newIp
}

Expand Down Expand Up @@ -300,7 +299,7 @@ func networkInRoutingTable(subnet *net.IPNet) bool {
fields := strings.Fields(string(line))

// Get the IP
ip := net.IP{}
var ip net.IP
if filename == "ipv6_route" {
ip, err = hex.DecodeString(fields[0])
if err != nil {
Expand All @@ -316,7 +315,7 @@ func networkInRoutingTable(subnet *net.IPNet) bool {
}

// Get the mask
mask := net.IPMask{}
var mask net.IPMask
if filename == "ipv6_route" {
size, err := strconv.ParseInt(fmt.Sprintf("0x%s", fields[1]), 0, 64)
if err != nil {
Expand Down Expand Up @@ -751,7 +750,7 @@ func networkUpdateStatic(s *state.State, networkName string) error {
}

// Get all the networks
networks := []string{}
var networks []string
if networkName == "" {
var err error
networks, err = s.DB.Networks()
Expand Down
9 changes: 3 additions & 6 deletions lxd/patches.go
Expand Up @@ -717,7 +717,7 @@ func upgradeFromStorageTypeDir(name string, d *Daemon, defaultPoolName string, d

// If the snapshots directory for that container is empty,
// remove it.
isEmpty, err := shared.PathIsEmpty(oldSnapshotMntPoint)
isEmpty, _ := shared.PathIsEmpty(oldSnapshotMntPoint)
if isEmpty {
os.Remove(oldSnapshotMntPoint)
continue
Expand Down Expand Up @@ -841,13 +841,10 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
poolConfig["volume.block.mount_options"] = fsMntOpts
}

thinPoolName := "LXDPool"
poolConfig["lvm.thinpool_name"] = daemonConfig["storage.lvm_thinpool_name"].Get()
if poolConfig["lvm.thinpool_name"] != "" {
thinPoolName = poolConfig["lvm.thinpool_name"]
} else {
if poolConfig["lvm.thinpool_name"] == "" {
// If empty we need to set it to the old default.
poolConfig["lvm.thinpool_name"] = thinPoolName
poolConfig["lvm.thinpool_name"] = "LXDPool"
}

poolConfig["lvm.vg_name"] = daemonConfig["storage.lvm_vg_name"].Get()
Expand Down
5 changes: 5 additions & 0 deletions lxd/profiles_test.go
Expand Up @@ -17,7 +17,12 @@ func Test_removing_a_profile_deletes_associated_configuration_entries(t *testing
t.Fatal(err)
}
defer os.RemoveAll(d.os.VarDir)

err = initializeDbObject(d)
if err != nil {
t.Fatal(err)
}

db = d.db.DB()

// Insert a container and a related profile. Dont't forget that the profile
Expand Down
2 changes: 1 addition & 1 deletion lxd/storage_ceph_utils.go
Expand Up @@ -783,7 +783,7 @@ func (s *storageCeph) copyWithoutSnapshotsSparse(target container,
sourceContainerName := source.Name()
targetContainerName := target.Name()
sourceContainerOnlyName := sourceContainerName
sourceSnapshotOnlyName := sourceContainerName
sourceSnapshotOnlyName := ""
snapshotName := fmt.Sprintf("zombie_snapshot_%s",
uuid.NewRandom().String())
if sourceIsSnapshot {
Expand Down
4 changes: 2 additions & 2 deletions lxd/storage_lvm.go
Expand Up @@ -111,9 +111,9 @@ func (s *storageLvm) StoragePoolCreate() error {
s.pool.Config["volatile.initial_source"] = s.pool.Config["source"]

var globalErr error
var pvExisted bool
var vgExisted bool
tryUndo := true
pvExisted := false
vgExisted := false
poolName := s.getOnDiskPoolName()
source := s.pool.Config["source"]
// must be initialized
Expand Down
3 changes: 1 addition & 2 deletions lxd/storage_lvm_utils.go
Expand Up @@ -783,10 +783,9 @@ func lvmCreateLv(vgName string, thinPoolName string, lvName string, lvFsType str
var output string
var err error

targetVg := vgName
lvmPoolVolumeName := getPrefixedLvName(volumeType, lvName)
if makeThinLv {
targetVg = fmt.Sprintf("%s/%s", vgName, thinPoolName)
targetVg := fmt.Sprintf("%s/%s", vgName, thinPoolName)
output, err = shared.TryRunCommand("lvcreate", "--thin", "-n", lvmPoolVolumeName, "--virtualsize", lvSize+"B", targetVg)
} else {
output, err = shared.TryRunCommand("lvcreate", "-n", lvmPoolVolumeName, "--size", lvSize+"B", vgName)
Expand Down
5 changes: 5 additions & 0 deletions lxd/storage_pools.go
Expand Up @@ -211,6 +211,10 @@ func storagePoolDelete(d *Daemon, r *http.Request) Response {
// Check if the storage pool has any volumes associated with it, if so
// error out.
volumeCount, err := d.db.StoragePoolVolumesGetNames(poolID)
if err != nil {
return InternalError(err)
}

if volumeCount > 0 {
return BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName))
}
Expand All @@ -220,6 +224,7 @@ func storagePoolDelete(d *Daemon, r *http.Request) Response {
if err != nil {
return SmartError(err)
}

if len(profiles) > 0 {
return BadRequest(fmt.Errorf("Storage pool \"%s\" has profiles using it:\n%s", poolName, strings.Join(profiles, "\n")))
}
Expand Down

0 comments on commit 044bad7

Please sign in to comment.