Skip to content

Commit c934a92

Browse files
author
Mark Fasheh
committed
ocfs2: Remove data locks
The meta lock now covers both meta data and data, so this just removes the now-redundant data lock. Combining locks saves us a round of lock mastery per inode and one less lock to ping between nodes during read/write. We don't lose much - since meta locks were always held before a data lock (and at the same level) ordered writeout mode (the default) ensured that flushing for the meta data lock also pushed out data anyways. Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
1 parent f1f5406 commit c934a92

File tree

9 files changed

+22
-214
lines changed

9 files changed

+22
-214
lines changed

fs/ocfs2/aops.c

+2-42
Original file line numberDiff line numberDiff line change
@@ -305,21 +305,12 @@ static int ocfs2_readpage(struct file *file, struct page *page)
305305
goto out_alloc;
306306
}
307307

308-
ret = ocfs2_data_lock_with_page(inode, 0, page);
309-
if (ret != 0) {
310-
if (ret == AOP_TRUNCATED_PAGE)
311-
unlock = 0;
312-
mlog_errno(ret);
313-
goto out_alloc;
314-
}
315-
316308
if (oi->ip_dyn_features & OCFS2_INLINE_DATA_FL)
317309
ret = ocfs2_readpage_inline(inode, page);
318310
else
319311
ret = block_read_full_page(page, ocfs2_get_block);
320312
unlock = 0;
321313

322-
ocfs2_data_unlock(inode, 0);
323314
out_alloc:
324315
up_read(&OCFS2_I(inode)->ip_alloc_sem);
325316
out_meta_unlock:
@@ -638,34 +629,12 @@ static ssize_t ocfs2_direct_IO(int rw,
638629
if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
639630
return 0;
640631

641-
if (!ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb))) {
642-
/*
643-
* We get PR data locks even for O_DIRECT. This
644-
* allows concurrent O_DIRECT I/O but doesn't let
645-
* O_DIRECT with extending and buffered zeroing writes
646-
* race. If they did race then the buffered zeroing
647-
* could be written back after the O_DIRECT I/O. It's
648-
* one thing to tell people not to mix buffered and
649-
* O_DIRECT writes, but expecting them to understand
650-
* that file extension is also an implicit buffered
651-
* write is too much. By getting the PR we force
652-
* writeback of the buffered zeroing before
653-
* proceeding.
654-
*/
655-
ret = ocfs2_data_lock(inode, 0);
656-
if (ret < 0) {
657-
mlog_errno(ret);
658-
goto out;
659-
}
660-
ocfs2_data_unlock(inode, 0);
661-
}
662-
663632
ret = blockdev_direct_IO_no_locking(rw, iocb, inode,
664633
inode->i_sb->s_bdev, iov, offset,
665634
nr_segs,
666635
ocfs2_direct_IO_get_blocks,
667636
ocfs2_dio_end_io);
668-
out:
637+
669638
mlog_exit(ret);
670639
return ret;
671640
}
@@ -1769,25 +1738,17 @@ static int ocfs2_write_begin(struct file *file, struct address_space *mapping,
17691738
*/
17701739
down_write(&OCFS2_I(inode)->ip_alloc_sem);
17711740

1772-
ret = ocfs2_data_lock(inode, 1);
1773-
if (ret) {
1774-
mlog_errno(ret);
1775-
goto out_fail;
1776-
}
1777-
17781741
ret = ocfs2_write_begin_nolock(mapping, pos, len, flags, pagep,
17791742
fsdata, di_bh, NULL);
17801743
if (ret) {
17811744
mlog_errno(ret);
1782-
goto out_fail_data;
1745+
goto out_fail;
17831746
}
17841747

17851748
brelse(di_bh);
17861749

17871750
return 0;
17881751

1789-
out_fail_data:
1790-
ocfs2_data_unlock(inode, 1);
17911752
out_fail:
17921753
up_write(&OCFS2_I(inode)->ip_alloc_sem);
17931754

@@ -1908,7 +1869,6 @@ static int ocfs2_write_end(struct file *file, struct address_space *mapping,
19081869

19091870
ret = ocfs2_write_end_nolock(mapping, pos, len, copied, page, fsdata);
19101871

1911-
ocfs2_data_unlock(inode, 1);
19121872
up_write(&OCFS2_I(inode)->ip_alloc_sem);
19131873
ocfs2_meta_unlock(inode, 1);
19141874

fs/ocfs2/cluster/tcp_internal.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
* locking semantics of the file system using the protocol. It should
3939
* be somewhere else, I'm sure, but right now it isn't.
4040
*
41+
* New in version 10:
42+
* - Meta/data locks combined
43+
*
4144
* New in version 9:
4245
* - All votes removed
4346
*
@@ -63,7 +66,7 @@
6366
* - full 64 bit i_size in the metadata lock lvbs
6467
* - introduction of "rw" lock and pushing meta/data locking down
6568
*/
66-
#define O2NET_PROTOCOL_VERSION 9ULL
69+
#define O2NET_PROTOCOL_VERSION 10ULL
6770
struct o2net_handshake {
6871
__be64 protocol_version;
6972
__be64 connector_id;

fs/ocfs2/dlmglue.c

-104
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,6 @@ static struct ocfs2_lock_res_ops ocfs2_inode_meta_lops = {
232232
.flags = LOCK_TYPE_REQUIRES_REFRESH|LOCK_TYPE_USES_LVB,
233233
};
234234

235-
static struct ocfs2_lock_res_ops ocfs2_inode_data_lops = {
236-
.get_osb = ocfs2_get_inode_osb,
237-
.downconvert_worker = ocfs2_data_convert_worker,
238-
.flags = 0,
239-
};
240-
241235
static struct ocfs2_lock_res_ops ocfs2_super_lops = {
242236
.flags = LOCK_TYPE_REQUIRES_REFRESH,
243237
};
@@ -261,7 +255,6 @@ static struct ocfs2_lock_res_ops ocfs2_inode_open_lops = {
261255
static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres)
262256
{
263257
return lockres->l_type == OCFS2_LOCK_TYPE_META ||
264-
lockres->l_type == OCFS2_LOCK_TYPE_DATA ||
265258
lockres->l_type == OCFS2_LOCK_TYPE_RW ||
266259
lockres->l_type == OCFS2_LOCK_TYPE_OPEN;
267260
}
@@ -405,9 +398,6 @@ void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
405398
case OCFS2_LOCK_TYPE_META:
406399
ops = &ocfs2_inode_meta_lops;
407400
break;
408-
case OCFS2_LOCK_TYPE_DATA:
409-
ops = &ocfs2_inode_data_lops;
410-
break;
411401
case OCFS2_LOCK_TYPE_OPEN:
412402
ops = &ocfs2_inode_open_lops;
413403
break;
@@ -1154,12 +1144,6 @@ int ocfs2_create_new_inode_locks(struct inode *inode)
11541144
goto bail;
11551145
}
11561146

1157-
ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_data_lockres, 1, 1);
1158-
if (ret) {
1159-
mlog_errno(ret);
1160-
goto bail;
1161-
}
1162-
11631147
ret = ocfs2_create_new_lock(osb, &OCFS2_I(inode)->ip_open_lockres, 0, 0);
11641148
if (ret) {
11651149
mlog_errno(ret);
@@ -1312,67 +1296,6 @@ void ocfs2_open_unlock(struct inode *inode)
13121296
mlog_exit_void();
13131297
}
13141298

1315-
int ocfs2_data_lock_full(struct inode *inode,
1316-
int write,
1317-
int arg_flags)
1318-
{
1319-
int status = 0, level;
1320-
struct ocfs2_lock_res *lockres;
1321-
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1322-
1323-
BUG_ON(!inode);
1324-
1325-
mlog_entry_void();
1326-
1327-
mlog(0, "inode %llu take %s DATA lock\n",
1328-
(unsigned long long)OCFS2_I(inode)->ip_blkno,
1329-
write ? "EXMODE" : "PRMODE");
1330-
1331-
/* We'll allow faking a readonly data lock for
1332-
* rodevices. */
1333-
if (ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb))) {
1334-
if (write) {
1335-
status = -EROFS;
1336-
mlog_errno(status);
1337-
}
1338-
goto out;
1339-
}
1340-
1341-
if (ocfs2_mount_local(osb))
1342-
goto out;
1343-
1344-
lockres = &OCFS2_I(inode)->ip_data_lockres;
1345-
1346-
level = write ? LKM_EXMODE : LKM_PRMODE;
1347-
1348-
status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level,
1349-
0, arg_flags);
1350-
if (status < 0 && status != -EAGAIN)
1351-
mlog_errno(status);
1352-
1353-
out:
1354-
mlog_exit(status);
1355-
return status;
1356-
}
1357-
1358-
/* see ocfs2_meta_lock_with_page() */
1359-
int ocfs2_data_lock_with_page(struct inode *inode,
1360-
int write,
1361-
struct page *page)
1362-
{
1363-
int ret;
1364-
1365-
ret = ocfs2_data_lock_full(inode, write, OCFS2_LOCK_NONBLOCK);
1366-
if (ret == -EAGAIN) {
1367-
unlock_page(page);
1368-
if (ocfs2_data_lock(inode, write) == 0)
1369-
ocfs2_data_unlock(inode, write);
1370-
ret = AOP_TRUNCATED_PAGE;
1371-
}
1372-
1373-
return ret;
1374-
}
1375-
13761299
static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb,
13771300
struct ocfs2_lock_res *lockres)
13781301
{
@@ -1404,26 +1327,6 @@ static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb,
14041327
mlog_exit_void();
14051328
}
14061329

1407-
void ocfs2_data_unlock(struct inode *inode,
1408-
int write)
1409-
{
1410-
int level = write ? LKM_EXMODE : LKM_PRMODE;
1411-
struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres;
1412-
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1413-
1414-
mlog_entry_void();
1415-
1416-
mlog(0, "inode %llu drop %s DATA lock\n",
1417-
(unsigned long long)OCFS2_I(inode)->ip_blkno,
1418-
write ? "EXMODE" : "PRMODE");
1419-
1420-
if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) &&
1421-
!ocfs2_mount_local(osb))
1422-
ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1423-
1424-
mlog_exit_void();
1425-
}
1426-
14271330
#define OCFS2_SEC_BITS 34
14281331
#define OCFS2_SEC_SHIFT (64 - 34)
14291332
#define OCFS2_NSEC_MASK ((1ULL << OCFS2_SEC_SHIFT) - 1)
@@ -2591,13 +2494,6 @@ int ocfs2_drop_inode_locks(struct inode *inode)
25912494

25922495
status = err;
25932496

2594-
err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
2595-
&OCFS2_I(inode)->ip_data_lockres);
2596-
if (err < 0)
2597-
mlog_errno(err);
2598-
if (err < 0 && !status)
2599-
status = err;
2600-
26012497
err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
26022498
&OCFS2_I(inode)->ip_meta_lockres);
26032499
if (err < 0)

fs/ocfs2/dlmglue.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct ocfs2_meta_lvb {
4949
__be32 lvb_reserved2;
5050
};
5151

52-
/* ocfs2_meta_lock_full() and ocfs2_data_lock_full() 'arg_flags' flags */
52+
/* ocfs2_meta_lock_full() 'arg_flags' flags */
5353
/* don't wait on recovery. */
5454
#define OCFS2_META_LOCK_RECOVERY (0x01)
5555
/* Instruct the dlm not to queue ourselves on the other node. */
@@ -69,15 +69,6 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
6969
void ocfs2_lock_res_free(struct ocfs2_lock_res *res);
7070
int ocfs2_create_new_inode_locks(struct inode *inode);
7171
int ocfs2_drop_inode_locks(struct inode *inode);
72-
int ocfs2_data_lock_full(struct inode *inode,
73-
int write,
74-
int arg_flags);
75-
#define ocfs2_data_lock(inode, write) ocfs2_data_lock_full(inode, write, 0)
76-
int ocfs2_data_lock_with_page(struct inode *inode,
77-
int write,
78-
struct page *page);
79-
void ocfs2_data_unlock(struct inode *inode,
80-
int write);
8172
int ocfs2_rw_lock(struct inode *inode, int write);
8273
void ocfs2_rw_unlock(struct inode *inode, int write);
8374
int ocfs2_open_lock(struct inode *inode);

0 commit comments

Comments
 (0)