Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-ganeti
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
snf-ganeti
Commits
eb0f0ce0
Commit
eb0f0ce0
authored
16 years ago
by
Michael Hanselmann
Browse files
Options
Downloads
Patches
Plain Diff
Move watcher's LockFile function to utils
Reviewed-by: iustinp
parent
307149a8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
daemons/ganeti-watcher
+2
-14
2 additions, 14 deletions
daemons/ganeti-watcher
lib/utils.py
+12
-0
12 additions, 0 deletions
lib/utils.py
with
14 additions
and
14 deletions
daemons/ganeti-watcher
+
2
−
14
View file @
eb0f0ce0
...
...
@@ -90,18 +90,6 @@ def DoCmd(cmd):
return
res
def
LockFile
(
fd
):
"""
Locks a file using POSIX locks.
"""
try
:
fcntl
.
flock
(
fd
,
fcntl
.
LOCK_EX
|
fcntl
.
LOCK_NB
)
except
IOError
,
err
:
if
err
.
errno
==
errno
.
EAGAIN
:
raise
errors
.
LockError
(
"
File already locked
"
)
raise
class
WatcherState
(
object
):
"""
Interface to a state file recording restart attempts.
...
...
@@ -118,7 +106,7 @@ class WatcherState(object):
fd
=
os
.
open
(
constants
.
WATCHER_STATEFILE
,
os
.
O_RDWR
|
os
.
O_CREAT
)
self
.
statefile
=
os
.
fdopen
(
fd
,
'
w+
'
)
LockFile
(
self
.
statefile
.
fileno
())
utils
.
LockFile
(
self
.
statefile
.
fileno
())
try
:
self
.
_data
=
serializer
.
Load
(
self
.
statefile
.
read
())
...
...
@@ -151,7 +139,7 @@ class WatcherState(object):
# starting ganeti-watcher again at the same time will create a conflict.
fd
=
utils
.
WriteFile
(
constants
.
WATCHER_STATEFILE
,
data
=
serialized_form
,
prewrite
=
LockFile
,
close
=
False
)
prewrite
=
utils
.
LockFile
,
close
=
False
)
self
.
statefile
=
os
.
fdopen
(
fd
,
'
w+
'
)
def
Close
(
self
):
...
...
This diff is collapsed.
Click to expand it.
lib/utils.py
+
12
−
0
View file @
eb0f0ce0
...
...
@@ -1082,3 +1082,15 @@ def LockedMethod(fn):
lock
.
release
()
return
result
return
wrapper
def
LockFile
(
fd
):
"""
Locks a file using POSIX locks.
"""
try
:
fcntl
.
flock
(
fd
,
fcntl
.
LOCK_EX
|
fcntl
.
LOCK_NB
)
except
IOError
,
err
:
if
err
.
errno
==
errno
.
EAGAIN
:
raise
errors
.
LockError
(
"
File already locked
"
)
raise
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment