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
3 changes: 0 additions & 3 deletions cni/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ func (plugin *Plugin) InitializeKeyValueStore(config *common.PluginConfig) error
log.Printf("[cni] Failed to create store: %v.", err)
return err
}

// Force unlock the json store if the lock file is left on the node after reboot
removeLockFileAfterReboot(plugin)
}

// Acquire store lock.
Expand Down
11 changes: 0 additions & 11 deletions cni/plugin_linux.go

This file was deleted.

22 changes: 0 additions & 22 deletions cni/plugin_windows.go

This file was deleted.

18 changes: 7 additions & 11 deletions store/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,20 @@ func (kvs *jsonFileStore) flush() error {

// Lock locks the store for exclusive access.
func (kvs *jsonFileStore) Lock(block bool) error {
var (
lockFile *os.File
err error
)

kvs.Mutex.Lock()
defer kvs.Mutex.Unlock()

if kvs.locked {
return ErrStoreLocked
}

var lockFile *os.File
var err error
lockPerm := os.FileMode(0o664) + os.FileMode(os.ModeExclusive)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this value 0o664 valid?

Copy link
Member Author

@tamilmani1989 tamilmani1989 Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i corrected it to 0664 which is valid.

Copy link
Collaborator

@rbtr rbtr Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsturtevant 0o644 is a legal (and unambiguous) representation of 0644, where the little o indicates octal
so
@tamilmani1989 you uncorrected it, 0o644 is less ambiguous and therefore preferred

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbtr oops. thanks for letting me know. i will revert this back

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rbtr thanks for the explanation!

//nolint:gomnd // 0o664 - read write mode constant
lockPerm := os.FileMode(0o644) + os.FileMode(os.ModeExclusive)

// Try to acquire the lock file.
var lockRetryCount uint
Expand Down Expand Up @@ -270,14 +274,6 @@ func (kvs *jsonFileStore) GetLockFileModificationTime() (time.Time, error) {
kvs.Mutex.Lock()
defer kvs.Mutex.Unlock()

// Check if the file exists.
file, err := os.Open(kvs.lockFileName)
if err != nil {
return time.Time{}.UTC(), err
}

defer file.Close()

info, err := os.Stat(kvs.lockFileName)
if err != nil {
log.Printf("os.stat() for file %v failed: %v", kvs.lockFileName, err)
Expand Down