Merge git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
  jfs: Fix 32bit build warning
  Remove obsolete comment in fs.h
  Sanitize f_flags helpers
  Fix f_flags/f_mode in case of lookup_instantiate_filp() from open(pathname, 3)
  anonfd: Allow making anon files read-only
  fs/compat_ioctl.c: fix build error when !BLOCK
  pohmelfs needs I_LOCK
  alloc_file(): simplify handling of mnt_clone_write() errors
This commit is contained in:
Linus Torvalds 2009-12-22 14:20:48 -08:00
commit fe35d4a028
18 changed files with 31 additions and 34 deletions

View File

@ -722,8 +722,6 @@ static int pohmelfs_remove_entry(struct inode *dir, struct dentry *dentry)
if (inode->i_nlink) if (inode->i_nlink)
inode_dec_link_count(inode); inode_dec_link_count(inode);
} }
dprintk("%s: inode: %p, lock: %ld, unhashed: %d.\n",
__func__, pi, inode->i_state & I_LOCK, hlist_unhashed(&inode->i_hash));
return err; return err;
} }

View File

@ -121,13 +121,13 @@ struct file *anon_inode_getfile(const char *name,
d_instantiate(path.dentry, anon_inode_inode); d_instantiate(path.dentry, anon_inode_inode);
error = -ENFILE; error = -ENFILE;
file = alloc_file(&path, FMODE_READ | FMODE_WRITE, fops); file = alloc_file(&path, OPEN_FMODE(flags), fops);
if (!file) if (!file)
goto err_dput; goto err_dput;
file->f_mapping = anon_inode_inode->i_mapping; file->f_mapping = anon_inode_inode->i_mapping;
file->f_pos = 0; file->f_pos = 0;
file->f_flags = O_RDWR | (flags & O_NONBLOCK); file->f_flags = flags & (O_ACCMODE | O_NONBLOCK);
file->f_version = 0; file->f_version = 0;
file->private_data = priv; file->private_data = priv;

View File

@ -1600,8 +1600,6 @@ static long do_ioctl_trans(int fd, unsigned int cmd,
case KDSKBMETA: case KDSKBMETA:
case KDSKBLED: case KDSKBLED:
case KDSETLED: case KDSETLED:
/* SG stuff */
case SG_SET_TRANSFORM:
/* AUTOFS */ /* AUTOFS */
case AUTOFS_IOC_READY: case AUTOFS_IOC_READY:
case AUTOFS_IOC_FAIL: case AUTOFS_IOC_FAIL:

View File

@ -339,7 +339,7 @@ struct file *eventfd_file_create(unsigned int count, int flags)
ctx->flags = flags; ctx->flags = flags;
file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx,
flags & EFD_SHARED_FCNTL_FLAGS); O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS));
if (IS_ERR(file)) if (IS_ERR(file))
eventfd_free_ctx(ctx); eventfd_free_ctx(ctx);

View File

@ -1206,7 +1206,7 @@ SYSCALL_DEFINE1(epoll_create1, int, flags)
* a file structure and a free file descriptor. * a file structure and a free file descriptor.
*/ */
error = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep, error = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep,
flags & O_CLOEXEC); O_RDWR | (flags & O_CLOEXEC));
if (error < 0) if (error < 0)
ep_free(ep); ep_free(ep);

View File

@ -186,10 +186,8 @@ struct file *alloc_file(struct path *path, fmode_t mode,
* that we can do debugging checks at __fput() * that we can do debugging checks at __fput()
*/ */
if ((mode & FMODE_WRITE) && !special_file(path->dentry->d_inode->i_mode)) { if ((mode & FMODE_WRITE) && !special_file(path->dentry->d_inode->i_mode)) {
int error = 0;
file_take_write(file); file_take_write(file);
error = mnt_clone_write(path->mnt); WARN_ON(mnt_clone_write(path->mnt));
WARN_ON(error);
} }
ima_counts_get(file); ima_counts_get(file);
return file; return file;

View File

@ -85,3 +85,10 @@ extern struct file *get_empty_filp(void);
* super.c * super.c
*/ */
extern int do_remount_sb(struct super_block *, int, void *, int); extern int do_remount_sb(struct super_block *, int, void *, int);
/*
* open.c
*/
struct nameidata;
extern struct file *nameidata_to_filp(struct nameidata *);
extern void release_open_intent(struct nameidata *);

View File

@ -524,7 +524,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
* Page cache is indexed by long. * Page cache is indexed by long.
* I would use MAX_LFS_FILESIZE, but it's only half as big * I would use MAX_LFS_FILESIZE, but it's only half as big
*/ */
sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, sb->s_maxbytes); sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes);
#endif #endif
sb->s_time_gran = 1; sb->s_time_gran = 1;
return 0; return 0;

View File

@ -37,8 +37,6 @@
#include "internal.h" #include "internal.h"
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
/* [Feb-1997 T. Schoebel-Theuer] /* [Feb-1997 T. Schoebel-Theuer]
* Fundamental changes in the pathname lookup mechanisms (namei) * Fundamental changes in the pathname lookup mechanisms (namei)
* were necessary because of omirr. The reason is that omirr needs * were necessary because of omirr. The reason is that omirr needs
@ -1640,6 +1638,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
if (filp == NULL) if (filp == NULL)
return ERR_PTR(-ENFILE); return ERR_PTR(-ENFILE);
nd.intent.open.file = filp; nd.intent.open.file = filp;
filp->f_flags = open_flag;
nd.intent.open.flags = flag; nd.intent.open.flags = flag;
nd.intent.open.create_mode = 0; nd.intent.open.create_mode = 0;
error = do_path_lookup(dfd, pathname, error = do_path_lookup(dfd, pathname,
@ -1685,6 +1684,7 @@ struct file *do_filp_open(int dfd, const char *pathname,
if (filp == NULL) if (filp == NULL)
goto exit_parent; goto exit_parent;
nd.intent.open.file = filp; nd.intent.open.file = filp;
filp->f_flags = open_flag;
nd.intent.open.flags = flag; nd.intent.open.flags = flag;
nd.intent.open.create_mode = mode; nd.intent.open.create_mode = mode;
dir = nd.path.dentry; dir = nd.path.dentry;
@ -1725,7 +1725,7 @@ do_last:
mnt_drop_write(nd.path.mnt); mnt_drop_write(nd.path.mnt);
goto exit; goto exit;
} }
filp = nameidata_to_filp(&nd, open_flag); filp = nameidata_to_filp(&nd);
mnt_drop_write(nd.path.mnt); mnt_drop_write(nd.path.mnt);
if (nd.root.mnt) if (nd.root.mnt)
path_put(&nd.root); path_put(&nd.root);
@ -1789,7 +1789,7 @@ ok:
mnt_drop_write(nd.path.mnt); mnt_drop_write(nd.path.mnt);
goto exit; goto exit;
} }
filp = nameidata_to_filp(&nd, open_flag); filp = nameidata_to_filp(&nd);
if (!IS_ERR(filp)) { if (!IS_ERR(filp)) {
error = ima_path_check(&filp->f_path, filp->f_mode & error = ima_path_check(&filp->f_path, filp->f_mode &
(MAY_READ | MAY_WRITE | MAY_EXEC)); (MAY_READ | MAY_WRITE | MAY_EXEC));

View File

@ -821,15 +821,14 @@ static inline int __get_file_write_access(struct inode *inode,
} }
static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
int flags, struct file *f, struct file *f,
int (*open)(struct inode *, struct file *), int (*open)(struct inode *, struct file *),
const struct cred *cred) const struct cred *cred)
{ {
struct inode *inode; struct inode *inode;
int error; int error;
f->f_flags = flags; f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK |
f->f_mode = (__force fmode_t)((flags+1) & O_ACCMODE) | FMODE_LSEEK |
FMODE_PREAD | FMODE_PWRITE; FMODE_PREAD | FMODE_PWRITE;
inode = dentry->d_inode; inode = dentry->d_inode;
if (f->f_mode & FMODE_WRITE) { if (f->f_mode & FMODE_WRITE) {
@ -930,7 +929,6 @@ struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry
if (IS_ERR(dentry)) if (IS_ERR(dentry))
goto out_err; goto out_err;
nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->path.mnt), nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->path.mnt),
nd->intent.open.flags - 1,
nd->intent.open.file, nd->intent.open.file,
open, cred); open, cred);
out: out:
@ -949,7 +947,7 @@ EXPORT_SYMBOL_GPL(lookup_instantiate_filp);
* *
* Note that this function destroys the original nameidata * Note that this function destroys the original nameidata
*/ */
struct file *nameidata_to_filp(struct nameidata *nd, int flags) struct file *nameidata_to_filp(struct nameidata *nd)
{ {
const struct cred *cred = current_cred(); const struct cred *cred = current_cred();
struct file *filp; struct file *filp;
@ -958,7 +956,7 @@ struct file *nameidata_to_filp(struct nameidata *nd, int flags)
filp = nd->intent.open.file; filp = nd->intent.open.file;
/* Has the filesystem initialised the file for us? */ /* Has the filesystem initialised the file for us? */
if (filp->f_path.dentry == NULL) if (filp->f_path.dentry == NULL)
filp = __dentry_open(nd->path.dentry, nd->path.mnt, flags, filp, filp = __dentry_open(nd->path.dentry, nd->path.mnt, filp,
NULL, cred); NULL, cred);
else else
path_put(&nd->path); path_put(&nd->path);
@ -997,7 +995,8 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags,
return ERR_PTR(error); return ERR_PTR(error);
} }
return __dentry_open(dentry, mnt, flags, f, NULL, cred); f->f_flags = flags;
return __dentry_open(dentry, mnt, f, NULL, cred);
} }
EXPORT_SYMBOL(dentry_open); EXPORT_SYMBOL(dentry_open);

View File

@ -236,7 +236,7 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
* anon_inode_getfd() will install the fd. * anon_inode_getfd() will install the fd.
*/ */
ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx, ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx,
flags & (O_CLOEXEC | O_NONBLOCK)); O_RDWR | (flags & (O_CLOEXEC | O_NONBLOCK)));
if (ufd < 0) if (ufd < 0)
kfree(ctx); kfree(ctx);
} else { } else {

View File

@ -200,7 +200,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS); hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS);
ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx, ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx,
flags & TFD_SHARED_FCNTL_FLAGS); O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS));
if (ufd < 0) if (ufd < 0)
kfree(ctx); kfree(ctx);

View File

@ -1624,8 +1624,6 @@ struct super_operations {
* on the bit address once it is done. * on the bit address once it is done.
* *
* Q: What is the difference between I_WILL_FREE and I_FREEING? * Q: What is the difference between I_WILL_FREE and I_FREEING?
* Q: igrab() only checks on (I_FREEING|I_WILL_FREE). Should it also check on
* I_CLEAR? If not, why?
*/ */
#define I_DIRTY_SYNC 1 #define I_DIRTY_SYNC 1
#define I_DIRTY_DATASYNC 2 #define I_DIRTY_DATASYNC 2
@ -2464,5 +2462,8 @@ int proc_nr_files(struct ctl_table *table, int write,
int __init get_filesystem_list(char *buf); int __init get_filesystem_list(char *buf);
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
#define OPEN_FMODE(flag) ((__force fmode_t)((flag + 1) & O_ACCMODE))
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
#endif /* _LINUX_FS_H */ #endif /* _LINUX_FS_H */

View File

@ -72,8 +72,6 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry, extern struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
int (*open)(struct inode *, struct file *)); int (*open)(struct inode *, struct file *));
extern struct file *nameidata_to_filp(struct nameidata *nd, int flags);
extern void release_open_intent(struct nameidata *);
extern struct dentry *lookup_one_len(const char *, struct dentry *, int); extern struct dentry *lookup_one_len(const char *, struct dentry *, int);

View File

@ -250,7 +250,6 @@ struct audit_context {
#endif #endif
}; };
#define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
static inline int open_arg(int flags, int mask) static inline int open_arg(int flags, int mask)
{ {
int n = ACC_MODE(flags); int n = ACC_MODE(flags);

View File

@ -4724,7 +4724,7 @@ SYSCALL_DEFINE5(perf_event_open,
if (IS_ERR(event)) if (IS_ERR(event))
goto err_put_context; goto err_put_context;
err = anon_inode_getfd("[perf_event]", &perf_fops, event, 0); err = anon_inode_getfd("[perf_event]", &perf_fops, event, O_RDWR);
if (err < 0) if (err < 0)
goto err_free_put_context; goto err_free_put_context;

View File

@ -12,7 +12,6 @@
#include "common.h" #include "common.h"
#include "tomoyo.h" #include "tomoyo.h"
#include "realpath.h" #include "realpath.h"
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
/* /*
* tomoyo_globally_readable_file_entry is a structure which is used for holding * tomoyo_globally_readable_file_entry is a structure which is used for holding

View File

@ -1177,7 +1177,7 @@ static struct file_operations kvm_vcpu_fops = {
*/ */
static int create_vcpu_fd(struct kvm_vcpu *vcpu) static int create_vcpu_fd(struct kvm_vcpu *vcpu)
{ {
return anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops, vcpu, 0); return anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops, vcpu, O_RDWR);
} }
/* /*
@ -1638,7 +1638,7 @@ static int kvm_dev_ioctl_create_vm(void)
kvm = kvm_create_vm(); kvm = kvm_create_vm();
if (IS_ERR(kvm)) if (IS_ERR(kvm))
return PTR_ERR(kvm); return PTR_ERR(kvm);
fd = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm, 0); fd = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
if (fd < 0) if (fd < 0)
kvm_put_kvm(kvm); kvm_put_kvm(kvm);