ckpt-files: error out on file locks and leases
Subsystems (2)
RFC PATCH 1/1 ckpt-files: error out on file locks and leases
We do not currently handle the holding of any file locks. If a process being checkpointed is holding one, error out of the checkpoint process.
--- checkpoint/files.c | 12 ++++++++++++ fs/locks.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/fs.h | 6 ++++++ 3 files changed, 53 insertions(+), 0 deletions(-)
checkpoint/files.c +12 -0
@@ -272,6 +272,18 @@ static int checkpoint_file_desc(struct ckpt_ctx *ctx, }rcu_read_unlock (); + ret =find_locks_with_owner (file, files); +/* +* find_locks_with_owner() returns an error when there +* are no locks found, so we *want* it to return an error +* code. Its success means we have to fail the checkpoint. +*/ +if (!ret) { + ret = -EBADF ; +ckpt_err (ctx, ret,"%(T)fd %d has file lock or lease\n" , fd); + goto out; + } +/* sanity check (although this shouldn't happen) */ ret = -EBADF ;if (!file) {
fs/locks.c +35 -0
@@ -1994,6 +1994,41 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)EXPORT_SYMBOL (locks_remove_posix); +int find_locks_with_owner (struct file *filp,fl_owner_t owner) +{ +struct inode *inode = filp->f_path.dentry->d_inode; +struct file_lock **inode_fl; +int ret = -EEXIST ; + +lock_kernel (); +for_each_lock (inode, inode_fl) { +struct file_lock *fl = *inode_fl; +/* +* We could use posix_same_owner() along with a 'fake' +* file_lock. But, the fake file will never have the +* same fl_lmops as the fl that we are looking for and +* posix_same_owner() would just fall back to this +* check anyway. +*/ +if (IS_POSIX (fl)) { +if (fl->fl_owner == owner) { + ret =0 ; +break ; + } + }else if (IS_FLOCK (fl) ||IS_LEASE (fl)) { +if (fl->fl_file == filp) { + ret =0 ; +break ; + } + }else { +WARN (1 ,"unknown file lock type, fl_flags: %x" , + fl->fl_flags); + } + } +unlock_kernel (); +return ret; +} +/* * This function is called on the last close of an open file. */
include/linux/fs.h +6 -0
@@ -1122,6 +1122,7 @@ extern void locks_remove_posix(struct file *, fl_owner_t);extern void locks_remove_flock (struct file *);extern void locks_release_private (struct file_lock *);extern void posix_test_lock (struct file *,struct file_lock *); +extern int find_locks_with_owner (struct file *filp,fl_owner_t owner);extern int posix_lock_file (struct file *,struct file_lock *,struct file_lock *);extern int posix_lock_file_wait (struct file *,struct file_lock *);extern int posix_unblock_lock (struct file *,struct file_lock *);
@@ -1190,6 +1191,11 @@ static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)return ; } +static inline int find_locks_with_owner (struct file *filp,fl_owner_t owner) +{ +return -ENOENT ; +} +static inline void locks_remove_flock (struct file *filp) {return ;
Signature · 1 line
1.6.6.rc3
A message that is not in the archive (sent off-list or not yet received): 1261071313-14162-1-git-send-email-dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org
Serge E. Hallyn
Acked-byQuoted 5 lines · Dave Hansen
We do not currently handle the holding of any file locks. If a process being checkpointed is holding one, error out of the checkpoint process.
Signed-off-by Dave Hansen <[email protected]>
Thanks, Dave. Applied to branch cr-next atgit://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux-cr.git
(as soon as it mirrors)
So, I think that as of the unimplemented features listed on
http://ckpt.wiki.kernel.org/index.php/Checklist, my cr-next branch properly refuses to checkpoint all of them except for sysvipc semaphore undos (which are supposed to be trivial to implement?) and hardware devices - for which we can claim that any controls through an fs interface will cause checkpoint refusal.
So are we happy at this point?
thanks,
-serge
Quoted 106 lines
--- checkpoint/files.c | 12 ++++++++++++ fs/locks.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/fs.h | 6 ++++++ 3 files changed, 53 insertions(+), 0 deletions(-)checkpoint/files.c +12
-0@@ -272,6 +272,18 @@ static int checkpoint_file_desc(struct ckpt_ctx *ctx, }rcu_read_unlock (); + ret =find_locks_with_owner (file, files); +/* +* find_locks_with_owner() returns an error when there +* are no locks found, so we *want* it to return an error +* code. Its success means we have to fail the checkpoint. +*/ +if (!ret) { + ret = -EBADF ; +ckpt_err (ctx, ret,"%(T)fd %d has file lock or lease\n" , fd); + goto out; + } +/* sanity check (although this shouldn't happen) */ ret = -EBADF ;if (!file) {fs/locks.c +35
-0@@ -1994,6 +1994,41 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)EXPORT_SYMBOL (locks_remove_posix); +int find_locks_with_owner (struct file *filp,fl_owner_t owner) +{ +struct inode *inode = filp->f_path.dentry->d_inode; +struct file_lock **inode_fl; +int ret = -EEXIST ; + +lock_kernel (); +for_each_lock (inode, inode_fl) { +struct file_lock *fl = *inode_fl; +/* +* We could use posix_same_owner() along with a 'fake' +* file_lock. But, the fake file will never have the +* same fl_lmops as the fl that we are looking for and +* posix_same_owner() would just fall back to this +* check anyway. +*/ +if (IS_POSIX (fl)) { +if (fl->fl_owner == owner) { + ret =0 ; +break ; + } + }else if (IS_FLOCK (fl) ||IS_LEASE (fl)) { +if (fl->fl_file == filp) { + ret =0 ; +break ; + } + }else { +WARN (1 ,"unknown file lock type, fl_flags: %x" , + fl->fl_flags); + } + } +unlock_kernel (); +return ret; +} +/* * This function is called on the last close of an open file. */ include/linux/fs.h +6
-0@@ -1122,6 +1122,7 @@ extern void locks_remove_posix(struct file *, fl_owner_t);extern void locks_remove_flock (struct file *);extern void locks_release_private (struct file_lock *);extern void posix_test_lock (struct file *,struct file_lock *); +extern int find_locks_with_owner (struct file *filp,fl_owner_t owner);extern int posix_lock_file (struct file *,struct file_lock *,struct file_lock *);extern int posix_lock_file_wait (struct file *,struct file_lock *);extern int posix_unblock_lock (struct file *,struct file_lock *);@@ -1190,6 +1191,11 @@ static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)return ; } +static inline int find_locks_with_owner (struct file *filp,fl_owner_t owner) +{ +return -ENOENT ; +} +static inline void locks_remove_flock (struct file *filp) {return ;Signature · 6 lines
1.6.6.rc3 _______________________________________________ Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org https://lists.linux-foundation.org/mailman/listinfo/containers