aboutsummaryrefslogtreecommitdiff
path: root/libpod/sql_state.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-24 13:39:29 -0500
committerMatthew Heon <matthew.heon@gmail.com>2017-12-04 13:39:44 -0500
commitabfd18b0db8cb0ea331d90d702eab19e2157b973 (patch)
treefb0c9c3e941d0b647af9fe701e535d5db816c41f /libpod/sql_state.go
parent750fc239b5da8e3f2792ae33f46a671ddf4622e3 (diff)
downloadpodman-abfd18b0db8cb0ea331d90d702eab19e2157b973.tar.gz
podman-abfd18b0db8cb0ea331d90d702eab19e2157b973.tar.bz2
podman-abfd18b0db8cb0ea331d90d702eab19e2157b973.zip
Move containers to file locks from c/storage
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/sql_state.go')
-rw-r--r--libpod/sql_state.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/libpod/sql_state.go b/libpod/sql_state.go
index fb6be85d7..8640ca9c3 100644
--- a/libpod/sql_state.go
+++ b/libpod/sql_state.go
@@ -22,13 +22,14 @@ const DBSchema = 2
type SQLState struct {
db *sql.DB
specsDir string
+ locksDir string
runtime *Runtime
lock storage.Locker
valid bool
}
// NewSQLState initializes a SQL-backed state, created the database if necessary
-func NewSQLState(dbPath, lockPath, specsDir string, runtime *Runtime) (State, error) {
+func NewSQLState(dbPath, lockPath, specsDir, locksDir string, runtime *Runtime) (State, error) {
state := new(SQLState)
state.runtime = runtime
@@ -49,6 +50,15 @@ func NewSQLState(dbPath, lockPath, specsDir string, runtime *Runtime) (State, er
}
state.specsDir = specsDir
+ // Make the directory that will hold container lockfiles
+ if err := os.MkdirAll(locksDir, 0750); err != nil {
+ // The directory is allowed to exist
+ if !os.IsExist(err) {
+ return nil, errors.Wrapf(err, "error creating lockfiles dir %s", locksDir)
+ }
+ }
+ state.locksDir = locksDir
+
// Acquire the lock while we open the database and perform initial setup
state.lock.Lock()
defer state.lock.Unlock()
@@ -130,7 +140,7 @@ func (s *SQLState) Container(id string) (*Container, error) {
row := s.db.QueryRow(query, id)
- ctr, err := ctrFromScannable(row, s.runtime, s.specsDir)
+ ctr, err := ctrFromScannable(row, s.runtime, s.specsDir, s.locksDir)
if err != nil {
return nil, errors.Wrapf(err, "error retrieving container %s from database", id)
}
@@ -177,7 +187,7 @@ func (s *SQLState) LookupContainer(idOrName string) (*Container, error) {
}
var err error
- ctr, err = ctrFromScannable(rows, s.runtime, s.specsDir)
+ ctr, err = ctrFromScannable(rows, s.runtime, s.specsDir, s.locksDir)
if err != nil {
return nil, errors.Wrapf(err, "error retrieving container %s from database", idOrName)
}
@@ -576,7 +586,7 @@ func (s *SQLState) AllContainers() ([]*Container, error) {
containers := []*Container{}
for rows.Next() {
- ctr, err := ctrFromScannable(rows, s.runtime, s.specsDir)
+ ctr, err := ctrFromScannable(rows, s.runtime, s.specsDir, s.locksDir)
if err != nil {
return nil, err
}