Improve documentation, remove dead code plus some minor refactorings
This improves our code-to-comments ratio by a lot.
On the refactorings:
- Simplify the cluster join mode to just a single protobuf message -
a node can either join an existing cluster or bootstrap a new one.
All of the node-level setup like hostname and trust backend is done
using the setup call, since those are identical for both cases.
- We don't need a node name separate from the hostname. Ideally, we would
get rid of IP addresses for etcd as well.
- Google API design guidelines suggest the `List` term (vs. `Get`).
- Add username to comments for consistency. I think the names provide
useful context, but git blame is a thing. What do you think?
- Fixed or silenced some ignored error checks in preparation of using
an errcheck linter. Especially during early boot, many errors are
obviously not recoverable, but logging them can provide useful debugging info.
- Split up the common package into smaller subpackages.
- Remove the audit package (this will be a separate service that probably
uses it own database, rather than etcd).
- Move storage constants to storage package.
- Remove the unused KV type.
I also added a bunch of TODO comments with discussion points.
Added both of you as blocking reviewers - please comment if I
misunderstood any of your code.
Test Plan: Everything compiles and scripts:launch works (for whatever that's worth).
X-Origin-Diff: phab/D235
GitOrigin-RevId: 922fec5076e8d683e1138f26d2cb490de64a9777
diff --git a/core/pkg/devicemapper/devicemapper.go b/core/pkg/devicemapper/devicemapper.go
index dec6260..2687e3a 100644
--- a/core/pkg/devicemapper/devicemapper.go
+++ b/core/pkg/devicemapper/devicemapper.go
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// package devicemapper is a thin wrapper for the devicemapper ioctl API.
+// See: https://github.com/torvalds/linux/blob/master/include/uapi/linux/dm-ioctl.h
package devicemapper
import (
@@ -120,13 +122,15 @@
}
}
+// stringToDelimitedBuf copies src to dst and returns an error if len(src) > len(dst),
+// or when the string contains a null byte.
func stringToDelimitedBuf(dst []byte, src string) error {
if len(src) > len(dst)-1 {
- return fmt.Errorf("String longer than target buffer (%v > %v)", len(src), len(dst)-1)
+ return fmt.Errorf("string longer than target buffer (%v > %v)", len(src), len(dst)-1)
}
for i := 0; i < len(src); i++ {
if src[i] == 0x00 {
- return errors.New("String contains null byte, this is unsupported by DM")
+ return errors.New("string contains null byte, this is unsupported by DM")
}
dst[i] = src[i]
}
@@ -139,7 +143,7 @@
if fd == 0 {
f, err := os.Open("/dev/mapper/control")
if os.IsNotExist(err) {
- os.MkdirAll("/dev/mapper", 0755)
+ _ = os.MkdirAll("/dev/mapper", 0755)
if err := unix.Mknod("/dev/mapper/control", unix.S_IFCHR|0600, int(unix.Mkdev(10, 236))); err != nil {
return 0, err
}
@@ -283,11 +287,11 @@
return 0, fmt.Errorf("DM_DEV_CREATE failed: %w", err)
}
if err := LoadTable(name, targets); err != nil {
- RemoveDevice(name)
+ _ = RemoveDevice(name)
return 0, fmt.Errorf("DM_TABLE_LOAD failed: %w", err)
}
if err := Resume(name); err != nil {
- RemoveDevice(name)
+ _ = RemoveDevice(name)
return 0, fmt.Errorf("DM_DEV_SUSPEND failed: %w", err)
}
return dev, nil