mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update K8s packages to v0.32.1
Update K8s packages in go.mod to v0.32.1 Signed-off-by: Praveen M <m.praveen@ibm.com>
This commit is contained in:
8
vendor/k8s.io/utils/cpuset/OWNERS
generated
vendored
Normal file
8
vendor/k8s.io/utils/cpuset/OWNERS
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
approvers:
|
||||
- dchen1107
|
||||
- derekwaynecarr
|
||||
- ffromani
|
||||
- klueska
|
||||
- SergeyKanzhelev
|
256
vendor/k8s.io/utils/cpuset/cpuset.go
generated
vendored
Normal file
256
vendor/k8s.io/utils/cpuset/cpuset.go
generated
vendored
Normal file
@ -0,0 +1,256 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Package cpuset represents a collection of CPUs in a 'set' data structure.
|
||||
//
|
||||
// It can be used to represent core IDs, hyper thread siblings, CPU nodes, or processor IDs.
|
||||
//
|
||||
// The only special thing about this package is that
|
||||
// methods are provided to convert back and forth from Linux 'list' syntax.
|
||||
// See http://man7.org/linux/man-pages/man7/cpuset.7.html#FORMATS for details.
|
||||
//
|
||||
// Future work can migrate this to use a 'set' library, and relax the dubious 'immutable' property.
|
||||
//
|
||||
// This package was originally developed in the 'kubernetes' repository.
|
||||
package cpuset
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CPUSet is a thread-safe, immutable set-like data structure for CPU IDs.
|
||||
type CPUSet struct {
|
||||
elems map[int]struct{}
|
||||
}
|
||||
|
||||
// New returns a new CPUSet containing the supplied elements.
|
||||
func New(cpus ...int) CPUSet {
|
||||
s := CPUSet{
|
||||
elems: map[int]struct{}{},
|
||||
}
|
||||
for _, c := range cpus {
|
||||
s.add(c)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// add adds the supplied elements to the CPUSet.
|
||||
// It is intended for internal use only, since it mutates the CPUSet.
|
||||
func (s CPUSet) add(elems ...int) {
|
||||
for _, elem := range elems {
|
||||
s.elems[elem] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// Size returns the number of elements in this set.
|
||||
func (s CPUSet) Size() int {
|
||||
return len(s.elems)
|
||||
}
|
||||
|
||||
// IsEmpty returns true if there are zero elements in this set.
|
||||
func (s CPUSet) IsEmpty() bool {
|
||||
return s.Size() == 0
|
||||
}
|
||||
|
||||
// Contains returns true if the supplied element is present in this set.
|
||||
func (s CPUSet) Contains(cpu int) bool {
|
||||
_, found := s.elems[cpu]
|
||||
return found
|
||||
}
|
||||
|
||||
// Equals returns true if the supplied set contains exactly the same elements
|
||||
// as this set (s IsSubsetOf s2 and s2 IsSubsetOf s).
|
||||
func (s CPUSet) Equals(s2 CPUSet) bool {
|
||||
return reflect.DeepEqual(s.elems, s2.elems)
|
||||
}
|
||||
|
||||
// filter returns a new CPU set that contains all of the elements from this
|
||||
// set that match the supplied predicate, without mutating the source set.
|
||||
func (s CPUSet) filter(predicate func(int) bool) CPUSet {
|
||||
r := New()
|
||||
for cpu := range s.elems {
|
||||
if predicate(cpu) {
|
||||
r.add(cpu)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// IsSubsetOf returns true if the supplied set contains all the elements
|
||||
func (s CPUSet) IsSubsetOf(s2 CPUSet) bool {
|
||||
result := true
|
||||
for cpu := range s.elems {
|
||||
if !s2.Contains(cpu) {
|
||||
result = false
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Union returns a new CPU set that contains all of the elements from this
|
||||
// set and all of the elements from the supplied sets, without mutating
|
||||
// either source set.
|
||||
func (s CPUSet) Union(s2 ...CPUSet) CPUSet {
|
||||
r := New()
|
||||
for cpu := range s.elems {
|
||||
r.add(cpu)
|
||||
}
|
||||
for _, cs := range s2 {
|
||||
for cpu := range cs.elems {
|
||||
r.add(cpu)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// Intersection returns a new CPU set that contains all of the elements
|
||||
// that are present in both this set and the supplied set, without mutating
|
||||
// either source set.
|
||||
func (s CPUSet) Intersection(s2 CPUSet) CPUSet {
|
||||
return s.filter(func(cpu int) bool { return s2.Contains(cpu) })
|
||||
}
|
||||
|
||||
// Difference returns a new CPU set that contains all of the elements that
|
||||
// are present in this set and not the supplied set, without mutating either
|
||||
// source set.
|
||||
func (s CPUSet) Difference(s2 CPUSet) CPUSet {
|
||||
return s.filter(func(cpu int) bool { return !s2.Contains(cpu) })
|
||||
}
|
||||
|
||||
// List returns a slice of integers that contains all elements from
|
||||
// this set. The list is sorted.
|
||||
func (s CPUSet) List() []int {
|
||||
result := s.UnsortedList()
|
||||
sort.Ints(result)
|
||||
return result
|
||||
}
|
||||
|
||||
// UnsortedList returns a slice of integers that contains all elements from
|
||||
// this set.
|
||||
func (s CPUSet) UnsortedList() []int {
|
||||
result := make([]int, 0, len(s.elems))
|
||||
for cpu := range s.elems {
|
||||
result = append(result, cpu)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// String returns a new string representation of the elements in this CPU set
|
||||
// in canonical linux CPU list format.
|
||||
//
|
||||
// See: http://man7.org/linux/man-pages/man7/cpuset.7.html#FORMATS
|
||||
func (s CPUSet) String() string {
|
||||
if s.IsEmpty() {
|
||||
return ""
|
||||
}
|
||||
|
||||
elems := s.List()
|
||||
|
||||
type rng struct {
|
||||
start int
|
||||
end int
|
||||
}
|
||||
|
||||
ranges := []rng{{elems[0], elems[0]}}
|
||||
|
||||
for i := 1; i < len(elems); i++ {
|
||||
lastRange := &ranges[len(ranges)-1]
|
||||
// if this element is adjacent to the high end of the last range
|
||||
if elems[i] == lastRange.end+1 {
|
||||
// then extend the last range to include this element
|
||||
lastRange.end = elems[i]
|
||||
continue
|
||||
}
|
||||
// otherwise, start a new range beginning with this element
|
||||
ranges = append(ranges, rng{elems[i], elems[i]})
|
||||
}
|
||||
|
||||
// construct string from ranges
|
||||
var result bytes.Buffer
|
||||
for _, r := range ranges {
|
||||
if r.start == r.end {
|
||||
result.WriteString(strconv.Itoa(r.start))
|
||||
} else {
|
||||
result.WriteString(fmt.Sprintf("%d-%d", r.start, r.end))
|
||||
}
|
||||
result.WriteString(",")
|
||||
}
|
||||
return strings.TrimRight(result.String(), ",")
|
||||
}
|
||||
|
||||
// Parse CPUSet constructs a new CPU set from a Linux CPU list formatted string.
|
||||
//
|
||||
// See: http://man7.org/linux/man-pages/man7/cpuset.7.html#FORMATS
|
||||
func Parse(s string) (CPUSet, error) {
|
||||
// Handle empty string.
|
||||
if s == "" {
|
||||
return New(), nil
|
||||
}
|
||||
|
||||
result := New()
|
||||
|
||||
// Split CPU list string:
|
||||
// "0-5,34,46-48" => ["0-5", "34", "46-48"]
|
||||
ranges := strings.Split(s, ",")
|
||||
|
||||
for _, r := range ranges {
|
||||
boundaries := strings.SplitN(r, "-", 2)
|
||||
if len(boundaries) == 1 {
|
||||
// Handle ranges that consist of only one element like "34".
|
||||
elem, err := strconv.Atoi(boundaries[0])
|
||||
if err != nil {
|
||||
return New(), err
|
||||
}
|
||||
result.add(elem)
|
||||
} else if len(boundaries) == 2 {
|
||||
// Handle multi-element ranges like "0-5".
|
||||
start, err := strconv.Atoi(boundaries[0])
|
||||
if err != nil {
|
||||
return New(), err
|
||||
}
|
||||
end, err := strconv.Atoi(boundaries[1])
|
||||
if err != nil {
|
||||
return New(), err
|
||||
}
|
||||
if start > end {
|
||||
return New(), fmt.Errorf("invalid range %q (%d > %d)", r, start, end)
|
||||
}
|
||||
// start == end is acceptable (1-1 -> 1)
|
||||
|
||||
// Add all elements to the result.
|
||||
// e.g. "0-5", "46-48" => [0, 1, 2, 3, 4, 5, 46, 47, 48].
|
||||
for e := start; e <= end; e++ {
|
||||
result.add(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Clone returns a copy of this CPU set.
|
||||
func (s CPUSet) Clone() CPUSet {
|
||||
r := New()
|
||||
for elem := range s.elems {
|
||||
r.add(elem)
|
||||
}
|
||||
return r
|
||||
}
|
27
vendor/k8s.io/utils/inotify/LICENSE
generated
vendored
Normal file
27
vendor/k8s.io/utils/inotify/LICENSE
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
vendor/k8s.io/utils/inotify/PATENTS
generated
vendored
Normal file
22
vendor/k8s.io/utils/inotify/PATENTS
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
Additional IP Rights Grant (Patents)
|
||||
|
||||
"This implementation" means the copyrightable works distributed by
|
||||
Google as part of the Go project.
|
||||
|
||||
Google 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,
|
||||
transfer and otherwise run, modify and propagate the contents of this
|
||||
implementation of Go, where such license applies only to those patent
|
||||
claims, both currently owned or controlled by Google and acquired in
|
||||
the future, licensable by Google that are necessarily infringed by this
|
||||
implementation of Go. This grant does not include claims that would be
|
||||
infringed only as a consequence of further modification of this
|
||||
implementation. If you or your agent or exclusive licensee institute or
|
||||
order or agree to the institution of patent litigation against any
|
||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that this implementation of Go or any code incorporated within this
|
||||
implementation of Go constitutes direct or contributory patent
|
||||
infringement, or inducement of patent infringement, then any patent
|
||||
rights granted to you under this License for this implementation of Go
|
||||
shall terminate as of the date such litigation is filed.
|
5
vendor/k8s.io/utils/inotify/README.md
generated
vendored
Normal file
5
vendor/k8s.io/utils/inotify/README.md
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
This is a fork of golang.org/x/exp/inotify before it was deleted.
|
||||
|
||||
Please use gopkg.in/fsnotify.v1 instead.
|
||||
|
||||
For updates, see: https://github.com/fsnotify/fsnotify
|
45
vendor/k8s.io/utils/inotify/inotify.go
generated
vendored
Normal file
45
vendor/k8s.io/utils/inotify/inotify.go
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package inotify // import "k8s.io/utils/inotify"
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Event represents a notification
|
||||
type Event struct {
|
||||
Mask uint32 // Mask of events
|
||||
Cookie uint32 // Unique cookie associating related events (for rename(2))
|
||||
Name string // File name (optional)
|
||||
}
|
||||
|
||||
type watch struct {
|
||||
wd uint32 // Watch descriptor (as returned by the inotify_add_watch() syscall)
|
||||
flags uint32 // inotify flags of this watch (see inotify(7) for the list of valid flags)
|
||||
}
|
||||
|
||||
// Watcher represents an inotify instance
|
||||
type Watcher struct {
|
||||
mu sync.Mutex
|
||||
fd int // File descriptor (as returned by the inotify_init() syscall)
|
||||
watches map[string]*watch // Map of inotify watches (key: path)
|
||||
paths map[int]string // Map of watched paths (key: watch descriptor)
|
||||
Error chan error // Errors are sent on this channel
|
||||
Event chan *Event // Events are returned on this channel
|
||||
done chan bool // Channel for sending a "quit message" to the reader goroutine
|
||||
isClosed bool // Set to true when Close() is first called
|
||||
}
|
315
vendor/k8s.io/utils/inotify/inotify_linux.go
generated
vendored
Normal file
315
vendor/k8s.io/utils/inotify/inotify_linux.go
generated
vendored
Normal file
@ -0,0 +1,315 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
// Copyright 2010 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
Package inotify implements a wrapper for the Linux inotify system.
|
||||
|
||||
Example:
|
||||
|
||||
watcher, err := inotify.NewWatcher()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = watcher.Watch("/tmp")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case ev := <-watcher.Event:
|
||||
log.Println("event:", ev)
|
||||
case err := <-watcher.Error:
|
||||
log.Println("error:", err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
package inotify // import "k8s.io/utils/inotify"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// NewWatcher creates and returns a new inotify instance using inotify_init(2)
|
||||
func NewWatcher() (*Watcher, error) {
|
||||
fd, errno := syscall.InotifyInit1(syscall.IN_CLOEXEC)
|
||||
if fd == -1 {
|
||||
return nil, os.NewSyscallError("inotify_init", errno)
|
||||
}
|
||||
w := &Watcher{
|
||||
fd: fd,
|
||||
watches: make(map[string]*watch),
|
||||
paths: make(map[int]string),
|
||||
Event: make(chan *Event),
|
||||
Error: make(chan error),
|
||||
done: make(chan bool, 1),
|
||||
}
|
||||
|
||||
go w.readEvents()
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// Close closes an inotify watcher instance
|
||||
// It sends a message to the reader goroutine to quit and removes all watches
|
||||
// associated with the inotify instance
|
||||
func (w *Watcher) Close() error {
|
||||
if w.isClosed {
|
||||
return nil
|
||||
}
|
||||
w.isClosed = true
|
||||
|
||||
// Send "quit" message to the reader goroutine
|
||||
w.done <- true
|
||||
for path := range w.watches {
|
||||
w.RemoveWatch(path)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddWatch adds path to the watched file set.
|
||||
// The flags are interpreted as described in inotify_add_watch(2).
|
||||
func (w *Watcher) AddWatch(path string, flags uint32) error {
|
||||
if w.isClosed {
|
||||
return errors.New("inotify instance already closed")
|
||||
}
|
||||
|
||||
watchEntry, found := w.watches[path]
|
||||
if found {
|
||||
watchEntry.flags |= flags
|
||||
flags |= syscall.IN_MASK_ADD
|
||||
}
|
||||
|
||||
w.mu.Lock() // synchronize with readEvents goroutine
|
||||
|
||||
wd, err := syscall.InotifyAddWatch(w.fd, path, flags)
|
||||
if err != nil {
|
||||
w.mu.Unlock()
|
||||
return &os.PathError{
|
||||
Op: "inotify_add_watch",
|
||||
Path: path,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
w.watches[path] = &watch{wd: uint32(wd), flags: flags}
|
||||
w.paths[wd] = path
|
||||
}
|
||||
w.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Watch adds path to the watched file set, watching all events.
|
||||
func (w *Watcher) Watch(path string) error {
|
||||
return w.AddWatch(path, InAllEvents)
|
||||
}
|
||||
|
||||
// RemoveWatch removes path from the watched file set.
|
||||
func (w *Watcher) RemoveWatch(path string) error {
|
||||
watch, ok := w.watches[path]
|
||||
if !ok {
|
||||
return fmt.Errorf("can't remove non-existent inotify watch for: %s", path)
|
||||
}
|
||||
success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
|
||||
if success == -1 {
|
||||
// when file descriptor or watch descriptor not found, InotifyRmWatch syscall return EINVAL error
|
||||
// if return error, it may lead this path remain in watches and paths map, and no other event can trigger remove action.
|
||||
if errno != syscall.EINVAL {
|
||||
return os.NewSyscallError("inotify_rm_watch", errno)
|
||||
}
|
||||
}
|
||||
delete(w.watches, path)
|
||||
// Locking here to protect the read from paths in readEvents.
|
||||
w.mu.Lock()
|
||||
delete(w.paths, int(watch.wd))
|
||||
w.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// readEvents reads from the inotify file descriptor, converts the
|
||||
// received events into Event objects and sends them via the Event channel
|
||||
func (w *Watcher) readEvents() {
|
||||
var buf [syscall.SizeofInotifyEvent * 4096]byte
|
||||
|
||||
for {
|
||||
n, err := syscall.Read(w.fd, buf[:])
|
||||
// See if there is a message on the "done" channel
|
||||
var done bool
|
||||
select {
|
||||
case done = <-w.done:
|
||||
default:
|
||||
}
|
||||
|
||||
// If EOF or a "done" message is received
|
||||
if n == 0 || done {
|
||||
// The syscall.Close can be slow. Close
|
||||
// w.Event first.
|
||||
close(w.Event)
|
||||
err := syscall.Close(w.fd)
|
||||
if err != nil {
|
||||
w.Error <- os.NewSyscallError("close", err)
|
||||
}
|
||||
close(w.Error)
|
||||
return
|
||||
}
|
||||
if n < 0 {
|
||||
w.Error <- os.NewSyscallError("read", err)
|
||||
continue
|
||||
}
|
||||
if n < syscall.SizeofInotifyEvent {
|
||||
w.Error <- errors.New("inotify: short read in readEvents()")
|
||||
continue
|
||||
}
|
||||
|
||||
var offset uint32
|
||||
// We don't know how many events we just read into the buffer
|
||||
// While the offset points to at least one whole event...
|
||||
for offset <= uint32(n-syscall.SizeofInotifyEvent) {
|
||||
// Point "raw" to the event in the buffer
|
||||
raw := (*syscall.InotifyEvent)(unsafe.Pointer(&buf[offset]))
|
||||
event := new(Event)
|
||||
event.Mask = uint32(raw.Mask)
|
||||
event.Cookie = uint32(raw.Cookie)
|
||||
nameLen := uint32(raw.Len)
|
||||
// If the event happened to the watched directory or the watched file, the kernel
|
||||
// doesn't append the filename to the event, but we would like to always fill the
|
||||
// the "Name" field with a valid filename. We retrieve the path of the watch from
|
||||
// the "paths" map.
|
||||
w.mu.Lock()
|
||||
name, ok := w.paths[int(raw.Wd)]
|
||||
w.mu.Unlock()
|
||||
if ok {
|
||||
event.Name = name
|
||||
if nameLen > 0 {
|
||||
// Point "bytes" at the first byte of the filename
|
||||
bytes := (*[syscall.PathMax]byte)(unsafe.Pointer(&buf[offset+syscall.SizeofInotifyEvent]))
|
||||
// The filename is padded with NUL bytes. TrimRight() gets rid of those.
|
||||
event.Name += "/" + strings.TrimRight(string(bytes[0:nameLen]), "\000")
|
||||
}
|
||||
// Send the event on the events channel
|
||||
w.Event <- event
|
||||
}
|
||||
// Move to the next event in the buffer
|
||||
offset += syscall.SizeofInotifyEvent + nameLen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// String formats the event e in the form
|
||||
// "filename: 0xEventMask = IN_ACCESS|IN_ATTRIB_|..."
|
||||
func (e *Event) String() string {
|
||||
var events string
|
||||
|
||||
m := e.Mask
|
||||
for _, b := range eventBits {
|
||||
if m&b.Value == b.Value {
|
||||
m &^= b.Value
|
||||
events += "|" + b.Name
|
||||
}
|
||||
}
|
||||
|
||||
if m != 0 {
|
||||
events += fmt.Sprintf("|%#x", m)
|
||||
}
|
||||
if len(events) > 0 {
|
||||
events = " == " + events[1:]
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%q: %#x%s", e.Name, e.Mask, events)
|
||||
}
|
||||
|
||||
const (
|
||||
// Options for inotify_init() are not exported
|
||||
// IN_CLOEXEC uint32 = syscall.IN_CLOEXEC
|
||||
// IN_NONBLOCK uint32 = syscall.IN_NONBLOCK
|
||||
|
||||
// Options for AddWatch
|
||||
|
||||
// InDontFollow : Don't dereference pathname if it is a symbolic link
|
||||
InDontFollow uint32 = syscall.IN_DONT_FOLLOW
|
||||
// InOneshot : Monitor the filesystem object corresponding to pathname for one event, then remove from watch list
|
||||
InOneshot uint32 = syscall.IN_ONESHOT
|
||||
// InOnlydir : Watch pathname only if it is a directory
|
||||
InOnlydir uint32 = syscall.IN_ONLYDIR
|
||||
|
||||
// The "IN_MASK_ADD" option is not exported, as AddWatch
|
||||
// adds it automatically, if there is already a watch for the given path
|
||||
// IN_MASK_ADD uint32 = syscall.IN_MASK_ADD
|
||||
|
||||
// Events
|
||||
|
||||
// InAccess : File was accessed
|
||||
InAccess uint32 = syscall.IN_ACCESS
|
||||
// InAllEvents : Bit mask for all notify events
|
||||
InAllEvents uint32 = syscall.IN_ALL_EVENTS
|
||||
// InAttrib : Metadata changed
|
||||
InAttrib uint32 = syscall.IN_ATTRIB
|
||||
// InClose : Equates to IN_CLOSE_WRITE | IN_CLOSE_NOWRITE
|
||||
InClose uint32 = syscall.IN_CLOSE
|
||||
// InCloseNowrite : File or directory not opened for writing was closed
|
||||
InCloseNowrite uint32 = syscall.IN_CLOSE_NOWRITE
|
||||
// InCloseWrite : File opened for writing was closed
|
||||
InCloseWrite uint32 = syscall.IN_CLOSE_WRITE
|
||||
// InCreate : File/directory created in watched directory
|
||||
InCreate uint32 = syscall.IN_CREATE
|
||||
// InDelete : File/directory deleted from watched directory
|
||||
InDelete uint32 = syscall.IN_DELETE
|
||||
// InDeleteSelf : Watched file/directory was itself deleted
|
||||
InDeleteSelf uint32 = syscall.IN_DELETE_SELF
|
||||
// InModify : File was modified
|
||||
InModify uint32 = syscall.IN_MODIFY
|
||||
// InMove : Equates to IN_MOVED_FROM | IN_MOVED_TO
|
||||
InMove uint32 = syscall.IN_MOVE
|
||||
// InMovedFrom : Generated for the directory containing the old filename when a file is renamed
|
||||
InMovedFrom uint32 = syscall.IN_MOVED_FROM
|
||||
// InMovedTo : Generated for the directory containing the new filename when a file is renamed
|
||||
InMovedTo uint32 = syscall.IN_MOVED_TO
|
||||
// InMoveSelf : Watched file/directory was itself moved
|
||||
InMoveSelf uint32 = syscall.IN_MOVE_SELF
|
||||
// InOpen : File or directory was opened
|
||||
InOpen uint32 = syscall.IN_OPEN
|
||||
|
||||
// Special events
|
||||
|
||||
// InIsdir : Subject of this event is a directory
|
||||
InIsdir uint32 = syscall.IN_ISDIR
|
||||
// InIgnored : Watch was removed explicitly or automatically
|
||||
InIgnored uint32 = syscall.IN_IGNORED
|
||||
// InQOverflow : Event queue overflowed
|
||||
InQOverflow uint32 = syscall.IN_Q_OVERFLOW
|
||||
// InUnmount : Filesystem containing watched object was unmounted
|
||||
InUnmount uint32 = syscall.IN_UNMOUNT
|
||||
)
|
||||
|
||||
var eventBits = []struct {
|
||||
Value uint32
|
||||
Name string
|
||||
}{
|
||||
{InAccess, "IN_ACCESS"},
|
||||
{InAttrib, "IN_ATTRIB"},
|
||||
{InClose, "IN_CLOSE"},
|
||||
{InCloseNowrite, "IN_CLOSE_NOWRITE"},
|
||||
{InCloseWrite, "IN_CLOSE_WRITE"},
|
||||
{InCreate, "IN_CREATE"},
|
||||
{InDelete, "IN_DELETE"},
|
||||
{InDeleteSelf, "IN_DELETE_SELF"},
|
||||
{InModify, "IN_MODIFY"},
|
||||
{InMove, "IN_MOVE"},
|
||||
{InMovedFrom, "IN_MOVED_FROM"},
|
||||
{InMovedTo, "IN_MOVED_TO"},
|
||||
{InMoveSelf, "IN_MOVE_SELF"},
|
||||
{InOpen, "IN_OPEN"},
|
||||
{InIsdir, "IN_ISDIR"},
|
||||
{InIgnored, "IN_IGNORED"},
|
||||
{InQOverflow, "IN_Q_OVERFLOW"},
|
||||
{InUnmount, "IN_UNMOUNT"},
|
||||
}
|
54
vendor/k8s.io/utils/inotify/inotify_others.go
generated
vendored
Normal file
54
vendor/k8s.io/utils/inotify/inotify_others.go
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
// +build !linux
|
||||
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package inotify // import "k8s.io/utils/inotify"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var errNotSupported = fmt.Errorf("watch not supported on %s", runtime.GOOS)
|
||||
|
||||
// NewWatcher creates and returns a new inotify instance using inotify_init(2)
|
||||
func NewWatcher() (*Watcher, error) {
|
||||
return nil, errNotSupported
|
||||
}
|
||||
|
||||
// Close closes an inotify watcher instance
|
||||
// It sends a message to the reader goroutine to quit and removes all watches
|
||||
// associated with the inotify instance
|
||||
func (w *Watcher) Close() error {
|
||||
return errNotSupported
|
||||
}
|
||||
|
||||
// AddWatch adds path to the watched file set.
|
||||
// The flags are interpreted as described in inotify_add_watch(2).
|
||||
func (w *Watcher) AddWatch(path string, flags uint32) error {
|
||||
return errNotSupported
|
||||
}
|
||||
|
||||
// Watch adds path to the watched file set, watching all events.
|
||||
func (w *Watcher) Watch(path string) error {
|
||||
return errNotSupported
|
||||
}
|
||||
|
||||
// RemoveWatch removes path from the watched file set.
|
||||
func (w *Watcher) RemoveWatch(path string) error {
|
||||
return errNotSupported
|
||||
}
|
82
vendor/k8s.io/utils/strings/slices/slices.go
generated
vendored
82
vendor/k8s.io/utils/strings/slices/slices.go
generated
vendored
@ -1,82 +0,0 @@
|
||||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// Package slices defines various functions useful with slices of string type.
|
||||
// The goal is to be as close as possible to
|
||||
// https://github.com/golang/go/issues/45955. Ideal would be if we can just
|
||||
// replace "stringslices" if the "slices" package becomes standard.
|
||||
package slices
|
||||
|
||||
// Equal reports whether two slices are equal: the same length and all
|
||||
// elements equal. If the lengths are different, Equal returns false.
|
||||
// Otherwise, the elements are compared in index order, and the
|
||||
// comparison stops at the first unequal pair.
|
||||
func Equal(s1, s2 []string) bool {
|
||||
if len(s1) != len(s2) {
|
||||
return false
|
||||
}
|
||||
for i, n := range s1 {
|
||||
if n != s2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Filter appends to d each element e of s for which keep(e) returns true.
|
||||
// It returns the modified d. d may be s[:0], in which case the kept
|
||||
// elements will be stored in the same slice.
|
||||
// if the slices overlap in some other way, the results are unspecified.
|
||||
// To create a new slice with the filtered results, pass nil for d.
|
||||
func Filter(d, s []string, keep func(string) bool) []string {
|
||||
for _, n := range s {
|
||||
if keep(n) {
|
||||
d = append(d, n)
|
||||
}
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// Contains reports whether v is present in s.
|
||||
func Contains(s []string, v string) bool {
|
||||
return Index(s, v) >= 0
|
||||
}
|
||||
|
||||
// Index returns the index of the first occurrence of v in s, or -1 if
|
||||
// not present.
|
||||
func Index(s []string, v string) int {
|
||||
// "Contains" may be replaced with "Index(s, v) >= 0":
|
||||
// https://github.com/golang/go/issues/45955#issuecomment-873377947
|
||||
for i, n := range s {
|
||||
if n == v {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// Functions below are not in https://github.com/golang/go/issues/45955
|
||||
|
||||
// Clone returns a new clone of s.
|
||||
func Clone(s []string) []string {
|
||||
// https://github.com/go101/go101/wiki/There-is-not-a-perfect-way-to-clone-slices-in-Go
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
c := make([]string, len(s))
|
||||
copy(c, s)
|
||||
return c
|
||||
}
|
Reference in New Issue
Block a user