Skip to content

Commit 5ef50c3

Browse files
author
Sage Weil
committed
ceph: simplify+fix atomic_open
The initial ->atomic_open op was carried over from the old intent code, which was incomplete and didn't really work. Replace it with a fresh method. In particular: * always attempt to do an atomic open+lookup, both for the create case and for lookups of existing files. * fix symlink handling by returning 1 to the VFS so that we can follow the link to its destination. This fixes a longstanding ceph bug (raspberrypi#2392). Signed-off-by: Sage Weil <sage@inktank.com>
1 parent 1a9b499 commit 5ef50c3

3 files changed

Lines changed: 40 additions & 66 deletions

File tree

‎fs/ceph/dir.c‎

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -633,44 +633,6 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
633633
return dentry;
634634
}
635635

636-
int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
637-
struct file *file, unsigned flags, umode_t mode,
638-
int *opened)
639-
{
640-
int err;
641-
struct dentry *res = NULL;
642-
643-
if (!(flags & O_CREAT)) {
644-
if (dentry->d_name.len > NAME_MAX)
645-
return -ENAMETOOLONG;
646-
647-
err = ceph_init_dentry(dentry);
648-
if (err < 0)
649-
return err;
650-
651-
return ceph_lookup_open(dir, dentry, file, flags, mode, opened);
652-
}
653-
654-
if (d_unhashed(dentry)) {
655-
res = ceph_lookup(dir, dentry, 0);
656-
if (IS_ERR(res))
657-
return PTR_ERR(res);
658-
659-
if (res)
660-
dentry = res;
661-
}
662-
663-
/* We don't deal with positive dentries here */
664-
if (dentry->d_inode)
665-
return finish_no_open(file, res);
666-
667-
*opened |= FILE_CREATED;
668-
err = ceph_lookup_open(dir, dentry, file, flags, mode, opened);
669-
dput(res);
670-
671-
return err;
672-
}
673-
674636
/*
675637
* If we do a create but get no trace back from the MDS, follow up with
676638
* a lookup (the VFS expects us to link up the provided dentry).

‎fs/ceph/file.c‎

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/sched.h>
55
#include <linux/slab.h>
66
#include <linux/file.h>
7+
#include <linux/mount.h>
78
#include <linux/namei.h>
89
#include <linux/writeback.h>
910

@@ -106,9 +107,6 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
106107
}
107108

108109
/*
109-
* If the filp already has private_data, that means the file was
110-
* already opened by intent during lookup, and we do nothing.
111-
*
112110
* If we already have the requisite capabilities, we can satisfy
113111
* the open request locally (no need to request new caps from the
114112
* MDS). We do, however, need to inform the MDS (asynchronously)
@@ -207,24 +205,29 @@ int ceph_open(struct inode *inode, struct file *file)
207205

208206

209207
/*
210-
* Do a lookup + open with a single request.
211-
*
212-
* If this succeeds, but some subsequent check in the vfs
213-
* may_open() fails, the struct *file gets cleaned up (i.e.
214-
* ceph_release gets called). So fear not!
208+
* Do a lookup + open with a single request. If we get a non-existent
209+
* file or symlink, return 1 so the VFS can retry.
215210
*/
216-
int ceph_lookup_open(struct inode *dir, struct dentry *dentry,
211+
int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
217212
struct file *file, unsigned flags, umode_t mode,
218213
int *opened)
219214
{
220215
struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
221216
struct ceph_mds_client *mdsc = fsc->mdsc;
222217
struct ceph_mds_request *req;
223-
struct dentry *ret;
218+
struct dentry *dn;
224219
int err;
225220

226-
dout("ceph_lookup_open dentry %p '%.*s' flags %d mode 0%o\n",
227-
dentry, dentry->d_name.len, dentry->d_name.name, flags, mode);
221+
dout("atomic_open %p dentry %p '%.*s' %s flags %d mode 0%o\n",
222+
dir, dentry, dentry->d_name.len, dentry->d_name.name,
223+
d_unhashed(dentry) ? "unhashed" : "hashed", flags, mode);
224+
225+
if (dentry->d_name.len > NAME_MAX)
226+
return -ENAMETOOLONG;
227+
228+
err = ceph_init_dentry(dentry);
229+
if (err < 0)
230+
return err;
228231

229232
/* do the open */
230233
req = prepare_open_request(dir->i_sb, flags, mode);
@@ -241,22 +244,31 @@ int ceph_lookup_open(struct inode *dir, struct dentry *dentry,
241244
(flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
242245
req);
243246
err = ceph_handle_snapdir(req, dentry, err);
244-
if (err)
245-
goto out;
246-
if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
247+
if (err == 0 && (flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
247248
err = ceph_handle_notrace_create(dir, dentry);
248-
if (err)
249-
goto out;
250-
err = finish_open(file, req->r_dentry, ceph_open, opened);
251-
out:
252-
ret = ceph_finish_lookup(req, dentry, err);
253-
ceph_mdsc_put_request(req);
254-
dout("ceph_lookup_open result=%p\n", ret);
255249

256-
if (IS_ERR(ret))
257-
return PTR_ERR(ret);
250+
if (d_unhashed(dentry)) {
251+
dn = ceph_finish_lookup(req, dentry, err);
252+
if (IS_ERR(dn))
253+
err = PTR_ERR(dn);
254+
} else {
255+
/* we were given a hashed negative dentry */
256+
dn = NULL;
257+
}
258+
if (err)
259+
goto out_err;
260+
if (dn || dentry->d_inode == NULL || S_ISLNK(dentry->d_inode->i_mode)) {
261+
/* make vfs retry on splice, ENOENT, or symlink */
262+
dout("atomic_open finish_no_open on dn %p\n", dn);
263+
err = finish_no_open(file, dn);
264+
} else {
265+
dout("atomic_open finish_open on dn %p\n", dn);
266+
err = finish_open(file, dentry, ceph_open, opened);
267+
}
258268

259-
dput(ret);
269+
out_err:
270+
ceph_mdsc_put_request(req);
271+
dout("atomic_open result=%d\n", err);
260272
return err;
261273
}
262274

‎fs/ceph/super.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,9 @@ extern int ceph_copy_from_page_vector(struct page **pages,
806806
loff_t off, size_t len);
807807
extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
808808
extern int ceph_open(struct inode *inode, struct file *file);
809-
extern int ceph_lookup_open(struct inode *dir, struct dentry *dentry,
810-
struct file *od, unsigned flags,
811-
umode_t mode, int *opened);
809+
extern int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
810+
struct file *file, unsigned flags, umode_t mode,
811+
int *opened);
812812
extern int ceph_release(struct inode *inode, struct file *filp);
813813

814814
/* dir.c */

0 commit comments

Comments
 (0)