Skip to content

Commit ba5b56c

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client: (23 commits) ceph: document unlocked d_parent accesses ceph: explicitly reference rename old_dentry parent dir in request ceph: document locking for ceph_set_dentry_offset ceph: avoid d_parent in ceph_dentry_hash; fix ceph_encode_fh() hashing bug ceph: protect d_parent access in ceph_d_revalidate ceph: protect access to d_parent ceph: handle racing calls to ceph_init_dentry ceph: set dir complete frag after adding capability rbd: set blk_queue request sizes to object size ceph: set up readahead size when rsize is not passed rbd: cancel watch request when releasing the device ceph: ignore lease mask ceph: fix ceph_lookup_open intent usage ceph: only link open operations to directory unsafe list if O_CREAT|O_TRUNC ceph: fix bad parent_inode calc in ceph_lookup_open ceph: avoid carrying Fw cap during write into page cache libceph: don't time out osd requests that haven't been received ceph: report f_bfree based on kb_avail rather than diffing. ceph: only queue capsnap if caps are dirty ceph: fix snap writeback when racing with writes ...
2 parents 243dd28 + d79698d commit ba5b56c

17 files changed

Lines changed: 306 additions & 145 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,14 @@ static int rbd_get_num_segments(struct rbd_image_header *header,
629629
return end_seg - start_seg + 1;
630630
}
631631

632+
/*
633+
* returns the size of an object in the image
634+
*/
635+
static u64 rbd_obj_bytes(struct rbd_image_header *header)
636+
{
637+
return 1 << header->obj_order;
638+
}
639+
632640
/*
633641
* bio helpers
634642
*/
@@ -1253,6 +1261,35 @@ static int rbd_req_sync_watch(struct rbd_device *dev,
12531261
return ret;
12541262
}
12551263

1264+
/*
1265+
* Request sync osd unwatch
1266+
*/
1267+
static int rbd_req_sync_unwatch(struct rbd_device *dev,
1268+
const char *obj)
1269+
{
1270+
struct ceph_osd_req_op *ops;
1271+
1272+
int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_WATCH, 0);
1273+
if (ret < 0)
1274+
return ret;
1275+
1276+
ops[0].watch.ver = 0;
1277+
ops[0].watch.cookie = cpu_to_le64(dev->watch_event->cookie);
1278+
ops[0].watch.flag = 0;
1279+
1280+
ret = rbd_req_sync_op(dev, NULL,
1281+
CEPH_NOSNAP,
1282+
0,
1283+
CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
1284+
ops,
1285+
1, obj, 0, 0, NULL, NULL, NULL);
1286+
1287+
rbd_destroy_ops(ops);
1288+
ceph_osdc_cancel_event(dev->watch_event);
1289+
dev->watch_event = NULL;
1290+
return ret;
1291+
}
1292+
12561293
struct rbd_notify_info {
12571294
struct rbd_device *dev;
12581295
};
@@ -1736,6 +1773,13 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
17361773
q = blk_init_queue(rbd_rq_fn, &rbd_dev->lock);
17371774
if (!q)
17381775
goto out_disk;
1776+
1777+
/* set io sizes to object size */
1778+
blk_queue_max_hw_sectors(q, rbd_obj_bytes(&rbd_dev->header) / 512ULL);
1779+
blk_queue_max_segment_size(q, rbd_obj_bytes(&rbd_dev->header));
1780+
blk_queue_io_min(q, rbd_obj_bytes(&rbd_dev->header));
1781+
blk_queue_io_opt(q, rbd_obj_bytes(&rbd_dev->header));
1782+
17391783
blk_queue_merge_bvec(q, rbd_merge_bvec);
17401784
disk->queue = q;
17411785

@@ -2290,7 +2334,7 @@ static void rbd_dev_release(struct device *dev)
22902334
ceph_osdc_unregister_linger_request(&rbd_dev->client->osdc,
22912335
rbd_dev->watch_request);
22922336
if (rbd_dev->watch_event)
2293-
ceph_osdc_cancel_event(rbd_dev->watch_event);
2337+
rbd_req_sync_unwatch(rbd_dev, rbd_dev->obj_md_name);
22942338

22952339
rbd_put_client(rbd_dev);
22962340

‎fs/ceph/debugfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int mdsc_show(struct seq_file *s, void *p)
102102
path = NULL;
103103
spin_lock(&req->r_old_dentry->d_lock);
104104
seq_printf(s, " #%llx/%.*s (%s)",
105-
ceph_ino(req->r_old_dentry->d_parent->d_inode),
105+
ceph_ino(req->r_old_dentry_dir),
106106
req->r_old_dentry->d_name.len,
107107
req->r_old_dentry->d_name.name,
108108
path ? path : "");

‎fs/ceph/dir.c‎

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ int ceph_init_dentry(struct dentry *dentry)
4040
if (dentry->d_fsdata)
4141
return 0;
4242

43-
if (dentry->d_parent == NULL || /* nfs fh_to_dentry */
44-
ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP)
45-
d_set_d_op(dentry, &ceph_dentry_ops);
46-
else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR)
47-
d_set_d_op(dentry, &ceph_snapdir_dentry_ops);
48-
else
49-
d_set_d_op(dentry, &ceph_snap_dentry_ops);
50-
5143
di = kmem_cache_alloc(ceph_dentry_cachep, GFP_NOFS | __GFP_ZERO);
5244
if (!di)
5345
return -ENOMEM; /* oh well */
@@ -58,16 +50,42 @@ int ceph_init_dentry(struct dentry *dentry)
5850
kmem_cache_free(ceph_dentry_cachep, di);
5951
goto out_unlock;
6052
}
53+
54+
if (dentry->d_parent == NULL || /* nfs fh_to_dentry */
55+
ceph_snap(dentry->d_parent->d_inode) == CEPH_NOSNAP)
56+
d_set_d_op(dentry, &ceph_dentry_ops);
57+
else if (ceph_snap(dentry->d_parent->d_inode) == CEPH_SNAPDIR)
58+
d_set_d_op(dentry, &ceph_snapdir_dentry_ops);
59+
else
60+
d_set_d_op(dentry, &ceph_snap_dentry_ops);
61+
6162
di->dentry = dentry;
6263
di->lease_session = NULL;
63-
dentry->d_fsdata = di;
6464
dentry->d_time = jiffies;
65+
/* avoid reordering d_fsdata setup so that the check above is safe */
66+
smp_mb();
67+
dentry->d_fsdata = di;
6568
ceph_dentry_lru_add(dentry);
6669
out_unlock:
6770
spin_unlock(&dentry->d_lock);
6871
return 0;
6972
}
7073

74+
struct inode *ceph_get_dentry_parent_inode(struct dentry *dentry)
75+
{
76+
struct inode *inode = NULL;
77+
78+
if (!dentry)
79+
return NULL;
80+
81+
spin_lock(&dentry->d_lock);
82+
if (dentry->d_parent) {
83+
inode = dentry->d_parent->d_inode;
84+
ihold(inode);
85+
}
86+
spin_unlock(&dentry->d_lock);
87+
return inode;
88+
}
7189

7290

7391
/*
@@ -133,7 +151,7 @@ static int __dcache_readdir(struct file *filp,
133151
d_unhashed(dentry) ? "!hashed" : "hashed",
134152
parent->d_subdirs.prev, parent->d_subdirs.next);
135153
if (p == &parent->d_subdirs) {
136-
fi->at_end = 1;
154+
fi->flags |= CEPH_F_ATEND;
137155
goto out_unlock;
138156
}
139157
spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
@@ -234,7 +252,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
234252
const int max_bytes = fsc->mount_options->max_readdir_bytes;
235253

236254
dout("readdir %p filp %p frag %u off %u\n", inode, filp, frag, off);
237-
if (fi->at_end)
255+
if (fi->flags & CEPH_F_ATEND)
238256
return 0;
239257

240258
/* always start with . and .. */
@@ -403,7 +421,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
403421
dout("readdir next frag is %x\n", frag);
404422
goto more;
405423
}
406-
fi->at_end = 1;
424+
fi->flags |= CEPH_F_ATEND;
407425

408426
/*
409427
* if dir_release_count still matches the dir, no dentries
@@ -435,7 +453,7 @@ static void reset_readdir(struct ceph_file_info *fi)
435453
dput(fi->dentry);
436454
fi->dentry = NULL;
437455
}
438-
fi->at_end = 0;
456+
fi->flags &= ~CEPH_F_ATEND;
439457
}
440458

441459
static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin)
@@ -463,7 +481,7 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin)
463481
if (offset != file->f_pos) {
464482
file->f_pos = offset;
465483
file->f_version = 0;
466-
fi->at_end = 0;
484+
fi->flags &= ~CEPH_F_ATEND;
467485
}
468486
retval = offset;
469487

@@ -488,21 +506,13 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin)
488506
}
489507

490508
/*
491-
* Process result of a lookup/open request.
492-
*
493-
* Mainly, make sure we return the final req->r_dentry (if it already
494-
* existed) in place of the original VFS-provided dentry when they
495-
* differ.
496-
*
497-
* Gracefully handle the case where the MDS replies with -ENOENT and
498-
* no trace (which it may do, at its discretion, e.g., if it doesn't
499-
* care to issue a lease on the negative dentry).
509+
* Handle lookups for the hidden .snap directory.
500510
*/
501-
struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
502-
struct dentry *dentry, int err)
511+
int ceph_handle_snapdir(struct ceph_mds_request *req,
512+
struct dentry *dentry, int err)
503513
{
504514
struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
505-
struct inode *parent = dentry->d_parent->d_inode;
515+
struct inode *parent = dentry->d_parent->d_inode; /* we hold i_mutex */
506516

507517
/* .snap dir? */
508518
if (err == -ENOENT &&
@@ -516,7 +526,23 @@ struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
516526
d_add(dentry, inode);
517527
err = 0;
518528
}
529+
return err;
530+
}
519531

532+
/*
533+
* Figure out final result of a lookup/open request.
534+
*
535+
* Mainly, make sure we return the final req->r_dentry (if it already
536+
* existed) in place of the original VFS-provided dentry when they
537+
* differ.
538+
*
539+
* Gracefully handle the case where the MDS replies with -ENOENT and
540+
* no trace (which it may do, at its discretion, e.g., if it doesn't
541+
* care to issue a lease on the negative dentry).
542+
*/
543+
struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
544+
struct dentry *dentry, int err)
545+
{
520546
if (err == -ENOENT) {
521547
/* no trace? */
522548
err = 0;
@@ -610,6 +636,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
610636
req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
611637
req->r_locked_dir = dir;
612638
err = ceph_mdsc_do_request(mdsc, NULL, req);
639+
err = ceph_handle_snapdir(req, dentry, err);
613640
dentry = ceph_finish_lookup(req, dentry, err);
614641
ceph_mdsc_put_request(req); /* will dput(dentry) */
615642
dout("lookup result=%p\n", dentry);
@@ -789,6 +816,7 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir,
789816
req->r_dentry = dget(dentry);
790817
req->r_num_caps = 2;
791818
req->r_old_dentry = dget(old_dentry); /* or inode? hrm. */
819+
req->r_old_dentry_dir = ceph_get_dentry_parent_inode(old_dentry);
792820
req->r_locked_dir = dir;
793821
req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
794822
req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
@@ -887,6 +915,7 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
887915
req->r_dentry = dget(new_dentry);
888916
req->r_num_caps = 2;
889917
req->r_old_dentry = dget(old_dentry);
918+
req->r_old_dentry_dir = ceph_get_dentry_parent_inode(old_dentry);
890919
req->r_locked_dir = new_dir;
891920
req->r_old_dentry_drop = CEPH_CAP_FILE_SHARED;
892921
req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL;
@@ -1002,36 +1031,38 @@ static int dir_lease_is_valid(struct inode *dir, struct dentry *dentry)
10021031
*/
10031032
static int ceph_d_revalidate(struct dentry *dentry, struct nameidata *nd)
10041033
{
1034+
int valid = 0;
10051035
struct inode *dir;
10061036

10071037
if (nd && nd->flags & LOOKUP_RCU)
10081038
return -ECHILD;
10091039

1010-
dir = dentry->d_parent->d_inode;
1011-
10121040
dout("d_revalidate %p '%.*s' inode %p offset %lld\n", dentry,
10131041
dentry->d_name.len, dentry->d_name.name, dentry->d_inode,
10141042
ceph_dentry(dentry)->offset);
10151043

1044+
dir = ceph_get_dentry_parent_inode(dentry);
1045+
10161046
/* always trust cached snapped dentries, snapdir dentry */
10171047
if (ceph_snap(dir) != CEPH_NOSNAP) {
10181048
dout("d_revalidate %p '%.*s' inode %p is SNAPPED\n", dentry,
10191049
dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
1020-
goto out_touch;
1050+
valid = 1;
1051+
} else if (dentry->d_inode &&
1052+
ceph_snap(dentry->d_inode) == CEPH_SNAPDIR) {
1053+
valid = 1;
1054+
} else if (dentry_lease_is_valid(dentry) ||
1055+
dir_lease_is_valid(dir, dentry)) {
1056+
valid = 1;
10211057
}
1022-
if (dentry->d_inode && ceph_snap(dentry->d_inode) == CEPH_SNAPDIR)
1023-
goto out_touch;
1024-
1025-
if (dentry_lease_is_valid(dentry) ||
1026-
dir_lease_is_valid(dir, dentry))
1027-
goto out_touch;
10281058

1029-
dout("d_revalidate %p invalid\n", dentry);
1030-
d_drop(dentry);
1031-
return 0;
1032-
out_touch:
1033-
ceph_dentry_lru_touch(dentry);
1034-
return 1;
1059+
dout("d_revalidate %p %s\n", dentry, valid ? "valid" : "invalid");
1060+
if (valid)
1061+
ceph_dentry_lru_touch(dentry);
1062+
else
1063+
d_drop(dentry);
1064+
iput(dir);
1065+
return valid;
10351066
}
10361067

10371068
/*
@@ -1228,9 +1259,8 @@ void ceph_dentry_lru_del(struct dentry *dn)
12281259
* Return name hash for a given dentry. This is dependent on
12291260
* the parent directory's hash function.
12301261
*/
1231-
unsigned ceph_dentry_hash(struct dentry *dn)
1262+
unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn)
12321263
{
1233-
struct inode *dir = dn->d_parent->d_inode;
12341264
struct ceph_inode_info *dci = ceph_inode(dir);
12351265

12361266
switch (dci->i_dir_layout.dl_dir_hash) {

‎fs/ceph/export.c‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
4646
int type;
4747
struct ceph_nfs_fh *fh = (void *)rawfh;
4848
struct ceph_nfs_confh *cfh = (void *)rawfh;
49-
struct dentry *parent = dentry->d_parent;
49+
struct dentry *parent;
5050
struct inode *inode = dentry->d_inode;
5151
int connected_handle_length = sizeof(*cfh)/4;
5252
int handle_length = sizeof(*fh)/4;
@@ -55,26 +55,33 @@ static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
5555
if (ceph_snap(inode) != CEPH_NOSNAP)
5656
return -EINVAL;
5757

58+
spin_lock(&dentry->d_lock);
59+
parent = dget(dentry->d_parent);
60+
spin_unlock(&dentry->d_lock);
61+
5862
if (*max_len >= connected_handle_length) {
5963
dout("encode_fh %p connectable\n", dentry);
6064
cfh->ino = ceph_ino(dentry->d_inode);
6165
cfh->parent_ino = ceph_ino(parent->d_inode);
62-
cfh->parent_name_hash = ceph_dentry_hash(parent);
66+
cfh->parent_name_hash = ceph_dentry_hash(parent->d_inode,
67+
dentry);
6368
*max_len = connected_handle_length;
6469
type = 2;
6570
} else if (*max_len >= handle_length) {
6671
if (connectable) {
6772
*max_len = connected_handle_length;
68-
return 255;
73+
type = 255;
74+
} else {
75+
dout("encode_fh %p\n", dentry);
76+
fh->ino = ceph_ino(dentry->d_inode);
77+
*max_len = handle_length;
78+
type = 1;
6979
}
70-
dout("encode_fh %p\n", dentry);
71-
fh->ino = ceph_ino(dentry->d_inode);
72-
*max_len = handle_length;
73-
type = 1;
7480
} else {
7581
*max_len = handle_length;
76-
return 255;
82+
type = 255;
7783
}
84+
dput(parent);
7885
return type;
7986
}
8087

@@ -123,7 +130,6 @@ static struct dentry *__fh_to_dentry(struct super_block *sb,
123130
return dentry;
124131
}
125132
err = ceph_init_dentry(dentry);
126-
127133
if (err < 0) {
128134
iput(inode);
129135
return ERR_PTR(err);

0 commit comments

Comments
 (0)