Add vendoring to containerd master
Initial vendor list validated with empty $GOPATH and only master checked out; followed by `make` and verified that all binaries build properly. Updates require github.com/LK4D4/vndr tool. Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
This commit is contained in:
parent
286ea04591
commit
dd9309c15e
407 changed files with 113562 additions and 0 deletions
201
vendor/github.com/stevvooe/go-btrfs/LICENSE
generated
vendored
Normal file
201
vendor/github.com/stevvooe/go-btrfs/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
17
vendor/github.com/stevvooe/go-btrfs/btrfs.c
generated
vendored
Normal file
17
vendor/github.com/stevvooe/go-btrfs/btrfs.c
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <stddef.h>
|
||||
#include <linux/magic.h>
|
||||
#include <btrfs/ioctl.h>
|
||||
#include <btrfs/ctree.h>
|
||||
|
||||
#include "btrfs.h"
|
||||
|
||||
void unpack_root_item(struct gosafe_btrfs_root_item* dst, struct btrfs_root_item* src) {
|
||||
memcpy(dst->uuid, src->uuid, BTRFS_UUID_SIZE);
|
||||
memcpy(dst->parent_uuid, src->parent_uuid, BTRFS_UUID_SIZE);
|
||||
memcpy(dst->received_uuid, src->received_uuid, BTRFS_UUID_SIZE);
|
||||
dst->gen = btrfs_root_generation(src);
|
||||
dst->ogen = btrfs_root_otransid(src);
|
||||
dst->flags = btrfs_root_flags(src);
|
||||
}
|
||||
|
||||
/* unpack_root_ref(struct gosafe_btrfs_root_ref* dst, struct btrfs_root_ref* src) { */
|
387
vendor/github.com/stevvooe/go-btrfs/btrfs.go
generated
vendored
Normal file
387
vendor/github.com/stevvooe/go-btrfs/btrfs.go
generated
vendored
Normal file
|
@ -0,0 +1,387 @@
|
|||
package btrfs
|
||||
|
||||
import "sort"
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -lbtrfs
|
||||
|
||||
#include <stddef.h>
|
||||
#include <btrfs/ioctl.h>
|
||||
#include "btrfs.h"
|
||||
|
||||
// Required because Go has struct casting rules for negative numbers
|
||||
const __u64 u64_BTRFS_LAST_FREE_OBJECTID = (__u64)BTRFS_LAST_FREE_OBJECTID;
|
||||
const __u64 negative_one = (__u64)-1;
|
||||
|
||||
static char* get_name_btrfs_ioctl_vol_args_v2(struct btrfs_ioctl_vol_args_v2* btrfs_struct) {
|
||||
return btrfs_struct->name;
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// IsSubvolume returns nil if the path is a valid subvolume. An error is
|
||||
// returned if the path does not exist or the path is not a valid subvolume.
|
||||
func IsSubvolume(path string) error {
|
||||
fi, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := isFileInfoSubvol(fi); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var statfs syscall.Statfs_t
|
||||
if err := syscall.Statfs(path, &statfs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return isStatfsSubvol(&statfs)
|
||||
}
|
||||
|
||||
// SubvolInfo returns information about the subvolume at the provided path.
|
||||
func SubvolInfo(path string) (info Info, err error) {
|
||||
path, err = filepath.EvalSymlinks(path)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
fp, err := openSubvolDir(path)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
id, err := subvolID(fp.Fd())
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
subvolsByID, err := subvolMap(path)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
if info, ok := subvolsByID[id]; ok {
|
||||
return info, nil
|
||||
}
|
||||
|
||||
return info, errors.Errorf("%q not found", path)
|
||||
}
|
||||
|
||||
func subvolMap(path string) (map[uint64]Info, error) {
|
||||
fp, err := openSubvolDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
var args C.struct_btrfs_ioctl_search_args
|
||||
|
||||
args.key.tree_id = C.BTRFS_ROOT_TREE_OBJECTID
|
||||
args.key.min_type = C.BTRFS_ROOT_ITEM_KEY
|
||||
args.key.max_type = C.BTRFS_ROOT_BACKREF_KEY
|
||||
args.key.min_objectid = C.BTRFS_FS_TREE_OBJECTID
|
||||
args.key.max_objectid = C.u64_BTRFS_LAST_FREE_OBJECTID
|
||||
args.key.max_offset = C.negative_one
|
||||
args.key.max_transid = C.negative_one
|
||||
|
||||
subvolsByID := map[uint64]Info{}
|
||||
|
||||
for {
|
||||
args.key.nr_items = 4096
|
||||
if err := ioctl(fp.Fd(), C.BTRFS_IOC_TREE_SEARCH, uintptr(unsafe.Pointer(&args))); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if args.key.nr_items == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
var (
|
||||
sh C.struct_btrfs_ioctl_search_header
|
||||
shSize = unsafe.Sizeof(sh)
|
||||
buf = (*[1<<31 - 1]byte)(unsafe.Pointer(&args.buf[0]))[:C.BTRFS_SEARCH_ARGS_BUFSIZE]
|
||||
)
|
||||
|
||||
for i := 0; i < int(args.key.nr_items); i++ {
|
||||
sh = (*(*C.struct_btrfs_ioctl_search_header)(unsafe.Pointer(&buf[0])))
|
||||
buf = buf[shSize:]
|
||||
|
||||
info := subvolsByID[uint64(sh.objectid)]
|
||||
info.ID = uint64(sh.objectid)
|
||||
|
||||
if sh._type == C.BTRFS_ROOT_BACKREF_KEY {
|
||||
rr := (*(*C.struct_btrfs_root_ref)(unsafe.Pointer(&buf[0])))
|
||||
|
||||
// This branch processes the backrefs from the root object. We
|
||||
// get an entry of the objectid, with name, but the parent is
|
||||
// the offset.
|
||||
|
||||
nname := C.btrfs_stack_root_ref_name_len(&rr)
|
||||
name := string(buf[C.sizeof_struct_btrfs_root_ref : C.sizeof_struct_btrfs_root_ref+uintptr(nname)])
|
||||
|
||||
info.ID = uint64(sh.objectid)
|
||||
info.ParentID = uint64(sh.offset)
|
||||
info.Name = name
|
||||
info.DirID = uint64(C.btrfs_stack_root_ref_dirid(&rr))
|
||||
|
||||
subvolsByID[uint64(sh.objectid)] = info
|
||||
} else if sh._type == C.BTRFS_ROOT_ITEM_KEY &&
|
||||
(sh.objectid >= C.BTRFS_ROOT_ITEM_KEY ||
|
||||
sh.objectid == C.BTRFS_FS_TREE_OBJECTID) {
|
||||
|
||||
var (
|
||||
ri = (*C.struct_btrfs_root_item)(unsafe.Pointer(&buf[0]))
|
||||
gri C.struct_gosafe_btrfs_root_item
|
||||
)
|
||||
|
||||
C.unpack_root_item(&gri, ri)
|
||||
|
||||
if gri.flags&C.BTRFS_ROOT_SUBVOL_RDONLY != 0 {
|
||||
info.Readonly = true
|
||||
}
|
||||
|
||||
// in this case, the offset is the actual offset.
|
||||
info.Offset = uint64(sh.offset)
|
||||
|
||||
info.UUID = uuidString(&gri.uuid)
|
||||
info.ParentUUID = uuidString(&gri.parent_uuid)
|
||||
info.ReceivedUUID = uuidString(&gri.received_uuid)
|
||||
|
||||
info.Generation = uint64(gri.gen)
|
||||
info.OriginalGeneration = uint64(gri.ogen)
|
||||
|
||||
subvolsByID[uint64(sh.objectid)] = info
|
||||
}
|
||||
|
||||
args.key.min_objectid = sh.objectid
|
||||
args.key.min_offset = sh.offset
|
||||
args.key.min_type = sh._type // this is very questionable.
|
||||
|
||||
buf = buf[sh.len:]
|
||||
}
|
||||
|
||||
args.key.min_offset++
|
||||
if args.key.min_offset == 0 {
|
||||
args.key.min_type++
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
if args.key.min_type > C.BTRFS_ROOT_BACKREF_KEY {
|
||||
args.key.min_type = C.BTRFS_ROOT_ITEM_KEY
|
||||
args.key.min_objectid++
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
if args.key.min_objectid > args.key.max_objectid {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
mnt, err := findMountPoint(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, sv := range subvolsByID {
|
||||
path := sv.Name
|
||||
parentID := sv.ParentID
|
||||
|
||||
for parentID != 0 {
|
||||
parent, ok := subvolsByID[parentID]
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
|
||||
parentID = parent.ParentID
|
||||
path = filepath.Join(parent.Name, path)
|
||||
}
|
||||
|
||||
sv.Path = filepath.Join(mnt, path)
|
||||
}
|
||||
return subvolsByID, nil
|
||||
}
|
||||
|
||||
// SubvolList will return the information for all subvolumes corresponding to
|
||||
// the provided path.
|
||||
func SubvolList(path string) ([]Info, error) {
|
||||
subvolsByID, err := subvolMap(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
subvols := make([]Info, 0, len(subvolsByID))
|
||||
for _, sv := range subvolsByID {
|
||||
subvols = append(subvols, sv)
|
||||
}
|
||||
|
||||
sort.Sort(infosByID(subvols))
|
||||
|
||||
return subvols, nil
|
||||
}
|
||||
|
||||
// SubvolCreate creates a subvolume at the provided path.
|
||||
func SubvolCreate(path string) error {
|
||||
dir, name := filepath.Split(path)
|
||||
|
||||
fp, err := os.Open(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
var args C.struct_btrfs_ioctl_vol_args
|
||||
args.fd = C.__s64(fp.Fd())
|
||||
|
||||
if len(name) > C.BTRFS_PATH_NAME_MAX {
|
||||
return errors.Errorf("%q too long for subvolume", name)
|
||||
}
|
||||
nameptr := (*[1<<31 - 1]byte)(unsafe.Pointer(&args.name[0]))
|
||||
copy(nameptr[:C.BTRFS_PATH_NAME_MAX], []byte(name))
|
||||
|
||||
if err := ioctl(fp.Fd(), C.BTRFS_IOC_SUBVOL_CREATE, uintptr(unsafe.Pointer(&args))); err != nil {
|
||||
return errors.Wrap(err, "btrfs subvolume create failed")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SubvolSnapshot creates a snapshot in dst from src. If readonly is true, the
|
||||
// snapshot will be readonly.
|
||||
func SubvolSnapshot(dst, src string, readonly bool) error {
|
||||
dstdir, dstname := filepath.Split(dst)
|
||||
|
||||
dstfp, err := openSubvolDir(dstdir)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "opening snapshot desination subvolume failed")
|
||||
}
|
||||
defer dstfp.Close()
|
||||
|
||||
srcfp, err := openSubvolDir(src)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "opening snapshot source subvolume failed")
|
||||
}
|
||||
defer srcfp.Close()
|
||||
|
||||
// dstdir is the ioctl arg, wile srcdir gets set on the args
|
||||
var args C.struct_btrfs_ioctl_vol_args_v2
|
||||
args.fd = C.__s64(srcfp.Fd())
|
||||
name := C.get_name_btrfs_ioctl_vol_args_v2(&args)
|
||||
|
||||
if len(dstname) > C.BTRFS_SUBVOL_NAME_MAX {
|
||||
return errors.Errorf("%q too long for subvolume", dstname)
|
||||
}
|
||||
|
||||
nameptr := (*[1<<31 - 1]byte)(unsafe.Pointer(name))
|
||||
copy(nameptr[:C.BTRFS_SUBVOL_NAME_MAX], []byte(dstname))
|
||||
|
||||
if readonly {
|
||||
args.flags |= C.BTRFS_SUBVOL_RDONLY
|
||||
}
|
||||
|
||||
if err := ioctl(dstfp.Fd(), C.BTRFS_IOC_SNAP_CREATE_V2, uintptr(unsafe.Pointer(&args))); err != nil {
|
||||
return errors.Wrapf(err, "snapshot create failed")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SubvolDelete deletes the subvolumes under the given path.
|
||||
func SubvolDelete(path string) error {
|
||||
fmt.Println("delete", path)
|
||||
dir, name := filepath.Split(path)
|
||||
fp, err := openSubvolDir(dir)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed opening %v", path)
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
// remove child subvolumes
|
||||
if err := filepath.Walk(path, func(p string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) || p == path {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.Wrapf(err, "failed walking subvolume %v", p)
|
||||
}
|
||||
|
||||
if !fi.IsDir() {
|
||||
return nil // just ignore it!
|
||||
}
|
||||
|
||||
if p == path {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := isFileInfoSubvol(fi); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := SubvolDelete(p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return filepath.SkipDir // children get walked by call above.
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var args C.struct_btrfs_ioctl_vol_args
|
||||
if len(name) > C.BTRFS_SUBVOL_NAME_MAX {
|
||||
return errors.Errorf("%q too long for subvolume", name)
|
||||
}
|
||||
|
||||
nameptr := (*[1<<31 - 1]byte)(unsafe.Pointer(&args.name[0]))
|
||||
copy(nameptr[:C.BTRFS_SUBVOL_NAME_MAX], []byte(name))
|
||||
|
||||
if err := ioctl(fp.Fd(), C.BTRFS_IOC_SNAP_DESTROY, uintptr(unsafe.Pointer(&args))); err != nil {
|
||||
return errors.Wrapf(err, "failed removing subvolume %v", path)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func openSubvolDir(path string) (*os.File, error) {
|
||||
fp, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "opening %v as subvolume failed", path)
|
||||
}
|
||||
|
||||
return fp, nil
|
||||
}
|
||||
|
||||
func isStatfsSubvol(statfs *syscall.Statfs_t) error {
|
||||
if statfs.Type != C.BTRFS_SUPER_MAGIC {
|
||||
return errors.Errorf("not a btrfs filesystem")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func isFileInfoSubvol(fi os.FileInfo) error {
|
||||
if !fi.IsDir() {
|
||||
errors.Errorf("must be a directory")
|
||||
}
|
||||
|
||||
stat := fi.Sys().(*syscall.Stat_t)
|
||||
|
||||
if stat.Ino != C.BTRFS_FIRST_FREE_OBJECTID {
|
||||
return errors.Errorf("incorrect inode type")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
21
vendor/github.com/stevvooe/go-btrfs/btrfs.h
generated
vendored
Normal file
21
vendor/github.com/stevvooe/go-btrfs/btrfs.h
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stddef.h>
|
||||
#include <linux/magic.h>
|
||||
#include <btrfs/ioctl.h>
|
||||
#include <btrfs/ctree.h>
|
||||
|
||||
// unfortunately, we need to define "alignment safe" C structs to populate for
|
||||
// packed structs that aren't handled by cgo. Fields will be added here, as
|
||||
// needed.
|
||||
|
||||
struct gosafe_btrfs_root_item {
|
||||
u8 uuid[BTRFS_UUID_SIZE];
|
||||
u8 parent_uuid[BTRFS_UUID_SIZE];
|
||||
u8 received_uuid[BTRFS_UUID_SIZE];
|
||||
|
||||
u64 gen;
|
||||
u64 ogen;
|
||||
u64 flags;
|
||||
};
|
||||
|
||||
void unpack_root_item(struct gosafe_btrfs_root_item* dst, struct btrfs_root_item* src);
|
||||
/* void unpack_root_ref(struct gosafe_btrfs_root_ref* dst, struct btrfs_root_ref* src); */
|
86
vendor/github.com/stevvooe/go-btrfs/helpers.go
generated
vendored
Normal file
86
vendor/github.com/stevvooe/go-btrfs/helpers.go
generated
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
package btrfs
|
||||
|
||||
/*
|
||||
#include <stddef.h>
|
||||
#include <btrfs/ioctl.h>
|
||||
#include <btrfs/ctree.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func subvolID(fd uintptr) (uint64, error) {
|
||||
var args C.struct_btrfs_ioctl_ino_lookup_args
|
||||
args.objectid = C.BTRFS_FIRST_FREE_OBJECTID
|
||||
|
||||
if err := ioctl(fd, C.BTRFS_IOC_INO_LOOKUP, uintptr(unsafe.Pointer(&args))); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return uint64(args.treeid), nil
|
||||
}
|
||||
|
||||
var (
|
||||
zeroArray = [16]byte{}
|
||||
zeros = zeroArray[:]
|
||||
)
|
||||
|
||||
func uuidString(uuid *[C.BTRFS_UUID_SIZE]C.u8) string {
|
||||
b := (*[1<<31 - 1]byte)(unsafe.Pointer(uuid))[:C.BTRFS_UUID_SIZE]
|
||||
|
||||
if bytes.Equal(b, zeros) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%x-%x-%x-%x-%x", b[:4], b[4:4+2], b[6:6+2], b[8:8+2], b[10:16])
|
||||
}
|
||||
|
||||
func findMountPoint(path string) (string, error) {
|
||||
fp, err := os.Open("/proc/self/mounts")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer fp.Close()
|
||||
|
||||
const (
|
||||
deviceIdx = 0
|
||||
pathIdx = 1
|
||||
typeIdx = 2
|
||||
options = 3
|
||||
)
|
||||
|
||||
var (
|
||||
mount string
|
||||
scanner = bufio.NewScanner(fp)
|
||||
)
|
||||
|
||||
for scanner.Scan() {
|
||||
fields := strings.Fields(scanner.Text())
|
||||
if fields[typeIdx] != "btrfs" {
|
||||
continue // skip non-btrfs
|
||||
}
|
||||
|
||||
if strings.HasPrefix(path, fields[pathIdx]) {
|
||||
mount = fields[pathIdx]
|
||||
}
|
||||
}
|
||||
|
||||
if scanner.Err() != nil {
|
||||
return "", scanner.Err()
|
||||
}
|
||||
|
||||
if mount == "" {
|
||||
return "", errors.Errorf("mount point of %v not found", path)
|
||||
}
|
||||
|
||||
return mount, nil
|
||||
}
|
29
vendor/github.com/stevvooe/go-btrfs/info.go
generated
vendored
Normal file
29
vendor/github.com/stevvooe/go-btrfs/info.go
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
package btrfs
|
||||
|
||||
// Info describes metadata about a btrfs subvolume.
|
||||
type Info struct {
|
||||
ID uint64 // subvolume id
|
||||
ParentID uint64 // aka ref_tree
|
||||
TopLevelID uint64 // not actually clear what this is, not set for now.
|
||||
Offset uint64 // key offset for root
|
||||
DirID uint64
|
||||
|
||||
Generation uint64
|
||||
OriginalGeneration uint64
|
||||
|
||||
UUID string
|
||||
ParentUUID string
|
||||
ReceivedUUID string
|
||||
|
||||
Name string
|
||||
Path string // absolute path of subvolume
|
||||
Root string // path of root mount point
|
||||
|
||||
Readonly bool // true if the snaps hot is readonly, extracted from flags
|
||||
}
|
||||
|
||||
type infosByID []Info
|
||||
|
||||
func (b infosByID) Len() int { return len(b) }
|
||||
func (b infosByID) Less(i, j int) bool { return b[i].ID < b[j].ID }
|
||||
func (b infosByID) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
11
vendor/github.com/stevvooe/go-btrfs/ioctl.go
generated
vendored
Normal file
11
vendor/github.com/stevvooe/go-btrfs/ioctl.go
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
package btrfs
|
||||
|
||||
import "syscall"
|
||||
|
||||
func ioctl(fd, request, args uintptr) error {
|
||||
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, fd, request, args)
|
||||
if errno != 0 {
|
||||
return errno
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue