Skip to content

Commit cddfa11

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge more updates from Andrew Morton: - more ocfs2 work - various leftovers * emailed patches from Andrew Morton <akpm@linux-foundation.org>: memory_hotplug: cond_resched in __remove_pages bfs: add sanity check at bfs_fill_super() kernel/sysctl.c: remove duplicated include kernel/kexec_file.c: remove some duplicated includes mm, thp: consolidate THP gfp handling into alloc_hugepage_direct_gfpmask ocfs2: fix clusters leak in ocfs2_defrag_extent() ocfs2: dlmglue: clean up timestamp handling ocfs2: don't put and assigning null to bh allocated outside ocfs2: fix a misuse a of brelse after failing ocfs2_check_dir_entry ocfs2: don't use iocb when EIOCBQUEUED returns ocfs2: without quota support, avoid calling quota recovery ocfs2: remove ocfs2_is_o2cb_active() mm: thp: relax __GFP_THISNODE for MADV_HUGEPAGE mappings include/linux/notifier.h: SRCU: fix ctags mm: handle no memcg case in memcg_kmem_charge() properly
2 parents 5f21585 + dd33ad7 commit cddfa11

19 files changed

+172
-124
lines changed

fs/bfs/inode.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
350350

351351
s->s_magic = BFS_MAGIC;
352352

353-
if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end)) {
353+
if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end) ||
354+
le32_to_cpu(bfs_sb->s_start) < BFS_BSIZE) {
354355
printf("Superblock is corrupted\n");
355356
goto out1;
356357
}
@@ -359,9 +360,11 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
359360
sizeof(struct bfs_inode)
360361
+ BFS_ROOT_INO - 1;
361362
imap_len = (info->si_lasti / 8) + 1;
362-
info->si_imap = kzalloc(imap_len, GFP_KERNEL);
363-
if (!info->si_imap)
363+
info->si_imap = kzalloc(imap_len, GFP_KERNEL | __GFP_NOWARN);
364+
if (!info->si_imap) {
365+
printf("Cannot allocate %u bytes\n", imap_len);
364366
goto out1;
367+
}
365368
for (i = 0; i < BFS_ROOT_INO; i++)
366369
set_bit(i, info->si_imap);
367370

fs/ocfs2/buffer_head_io.c

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,34 @@ int ocfs2_write_block(struct ocfs2_super *osb, struct buffer_head *bh,
9999
return ret;
100100
}
101101

102+
/* Caller must provide a bhs[] with all NULL or non-NULL entries, so it
103+
* will be easier to handle read failure.
104+
*/
102105
int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
103106
unsigned int nr, struct buffer_head *bhs[])
104107
{
105108
int status = 0;
106109
unsigned int i;
107110
struct buffer_head *bh;
111+
int new_bh = 0;
108112

109113
trace_ocfs2_read_blocks_sync((unsigned long long)block, nr);
110114

111115
if (!nr)
112116
goto bail;
113117

118+
/* Don't put buffer head and re-assign it to NULL if it is allocated
119+
* outside since the caller can't be aware of this alternation!
120+
*/
121+
new_bh = (bhs[0] == NULL);
122+
114123
for (i = 0 ; i < nr ; i++) {
115124
if (bhs[i] == NULL) {
116125
bhs[i] = sb_getblk(osb->sb, block++);
117126
if (bhs[i] == NULL) {
118127
status = -ENOMEM;
119128
mlog_errno(status);
120-
goto bail;
129+
break;
121130
}
122131
}
123132
bh = bhs[i];
@@ -158,9 +167,26 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
158167
submit_bh(REQ_OP_READ, 0, bh);
159168
}
160169

170+
read_failure:
161171
for (i = nr; i > 0; i--) {
162172
bh = bhs[i - 1];
163173

174+
if (unlikely(status)) {
175+
if (new_bh && bh) {
176+
/* If middle bh fails, let previous bh
177+
* finish its read and then put it to
178+
* aovoid bh leak
179+
*/
180+
if (!buffer_jbd(bh))
181+
wait_on_buffer(bh);
182+
put_bh(bh);
183+
bhs[i - 1] = NULL;
184+
} else if (bh && buffer_uptodate(bh)) {
185+
clear_buffer_uptodate(bh);
186+
}
187+
continue;
188+
}
189+
164190
/* No need to wait on the buffer if it's managed by JBD. */
165191
if (!buffer_jbd(bh))
166192
wait_on_buffer(bh);
@@ -170,15 +196,17 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
170196
* so we can safely record this and loop back
171197
* to cleanup the other buffers. */
172198
status = -EIO;
173-
put_bh(bh);
174-
bhs[i - 1] = NULL;
199+
goto read_failure;
175200
}
176201
}
177202

178203
bail:
179204
return status;
180205
}
181206

207+
/* Caller must provide a bhs[] with all NULL or non-NULL entries, so it
208+
* will be easier to handle read failure.
209+
*/
182210
int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
183211
struct buffer_head *bhs[], int flags,
184212
int (*validate)(struct super_block *sb,
@@ -188,6 +216,7 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
188216
int i, ignore_cache = 0;
189217
struct buffer_head *bh;
190218
struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
219+
int new_bh = 0;
191220

192221
trace_ocfs2_read_blocks_begin(ci, (unsigned long long)block, nr, flags);
193222

@@ -213,6 +242,11 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
213242
goto bail;
214243
}
215244

245+
/* Don't put buffer head and re-assign it to NULL if it is allocated
246+
* outside since the caller can't be aware of this alternation!
247+
*/
248+
new_bh = (bhs[0] == NULL);
249+
216250
ocfs2_metadata_cache_io_lock(ci);
217251
for (i = 0 ; i < nr ; i++) {
218252
if (bhs[i] == NULL) {
@@ -221,7 +255,8 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
221255
ocfs2_metadata_cache_io_unlock(ci);
222256
status = -ENOMEM;
223257
mlog_errno(status);
224-
goto bail;
258+
/* Don't forget to put previous bh! */
259+
break;
225260
}
226261
}
227262
bh = bhs[i];
@@ -316,16 +351,27 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
316351
}
317352
}
318353

319-
status = 0;
320-
354+
read_failure:
321355
for (i = (nr - 1); i >= 0; i--) {
322356
bh = bhs[i];
323357

324358
if (!(flags & OCFS2_BH_READAHEAD)) {
325-
if (status) {
326-
/* Clear the rest of the buffers on error */
327-
put_bh(bh);
328-
bhs[i] = NULL;
359+
if (unlikely(status)) {
360+
/* Clear the buffers on error including those
361+
* ever succeeded in reading
362+
*/
363+
if (new_bh && bh) {
364+
/* If middle bh fails, let previous bh
365+
* finish its read and then put it to
366+
* aovoid bh leak
367+
*/
368+
if (!buffer_jbd(bh))
369+
wait_on_buffer(bh);
370+
put_bh(bh);
371+
bhs[i] = NULL;
372+
} else if (bh && buffer_uptodate(bh)) {
373+
clear_buffer_uptodate(bh);
374+
}
329375
continue;
330376
}
331377
/* We know this can't have changed as we hold the
@@ -343,9 +389,7 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
343389
* uptodate. */
344390
status = -EIO;
345391
clear_buffer_needs_validate(bh);
346-
put_bh(bh);
347-
bhs[i] = NULL;
348-
continue;
392+
goto read_failure;
349393
}
350394

351395
if (buffer_needs_validate(bh)) {
@@ -355,11 +399,8 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
355399
BUG_ON(buffer_jbd(bh));
356400
clear_buffer_needs_validate(bh);
357401
status = validate(sb, bh);
358-
if (status) {
359-
put_bh(bh);
360-
bhs[i] = NULL;
361-
continue;
362-
}
402+
if (status)
403+
goto read_failure;
363404
}
364405
}
365406

fs/ocfs2/dir.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,8 +1897,7 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode,
18971897
/* On error, skip the f_pos to the
18981898
next block. */
18991899
ctx->pos = (ctx->pos | (sb->s_blocksize - 1)) + 1;
1900-
brelse(bh);
1901-
continue;
1900+
break;
19021901
}
19031902
if (le64_to_cpu(de->inode)) {
19041903
unsigned char d_type = DT_UNKNOWN;

fs/ocfs2/dlmglue.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,10 +2123,10 @@ static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb,
21232123

21242124
/* LVB only has room for 64 bits of time here so we pack it for
21252125
* now. */
2126-
static u64 ocfs2_pack_timespec(struct timespec *spec)
2126+
static u64 ocfs2_pack_timespec(struct timespec64 *spec)
21272127
{
21282128
u64 res;
2129-
u64 sec = spec->tv_sec;
2129+
u64 sec = clamp_t(time64_t, spec->tv_sec, 0, 0x3ffffffffull);
21302130
u32 nsec = spec->tv_nsec;
21312131

21322132
res = (sec << OCFS2_SEC_SHIFT) | (nsec & OCFS2_NSEC_MASK);
@@ -2142,7 +2142,6 @@ static void __ocfs2_stuff_meta_lvb(struct inode *inode)
21422142
struct ocfs2_inode_info *oi = OCFS2_I(inode);
21432143
struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres;
21442144
struct ocfs2_meta_lvb *lvb;
2145-
struct timespec ts;
21462145

21472146
lvb = ocfs2_dlm_lvb(&lockres->l_lksb);
21482147

@@ -2163,15 +2162,12 @@ static void __ocfs2_stuff_meta_lvb(struct inode *inode)
21632162
lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
21642163
lvb->lvb_imode = cpu_to_be16(inode->i_mode);
21652164
lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
2166-
ts = timespec64_to_timespec(inode->i_atime);
21672165
lvb->lvb_iatime_packed =
2168-
cpu_to_be64(ocfs2_pack_timespec(&ts));
2169-
ts = timespec64_to_timespec(inode->i_ctime);
2166+
cpu_to_be64(ocfs2_pack_timespec(&inode->i_atime));
21702167
lvb->lvb_ictime_packed =
2171-
cpu_to_be64(ocfs2_pack_timespec(&ts));
2172-
ts = timespec64_to_timespec(inode->i_mtime);
2168+
cpu_to_be64(ocfs2_pack_timespec(&inode->i_ctime));
21732169
lvb->lvb_imtime_packed =
2174-
cpu_to_be64(ocfs2_pack_timespec(&ts));
2170+
cpu_to_be64(ocfs2_pack_timespec(&inode->i_mtime));
21752171
lvb->lvb_iattr = cpu_to_be32(oi->ip_attr);
21762172
lvb->lvb_idynfeatures = cpu_to_be16(oi->ip_dyn_features);
21772173
lvb->lvb_igeneration = cpu_to_be32(inode->i_generation);
@@ -2180,7 +2176,7 @@ static void __ocfs2_stuff_meta_lvb(struct inode *inode)
21802176
mlog_meta_lvb(0, lockres);
21812177
}
21822178

2183-
static void ocfs2_unpack_timespec(struct timespec *spec,
2179+
static void ocfs2_unpack_timespec(struct timespec64 *spec,
21842180
u64 packed_time)
21852181
{
21862182
spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT;
@@ -2189,7 +2185,6 @@ static void ocfs2_unpack_timespec(struct timespec *spec,
21892185

21902186
static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
21912187
{
2192-
struct timespec ts;
21932188
struct ocfs2_inode_info *oi = OCFS2_I(inode);
21942189
struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres;
21952190
struct ocfs2_meta_lvb *lvb;
@@ -2217,15 +2212,12 @@ static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
22172212
i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
22182213
inode->i_mode = be16_to_cpu(lvb->lvb_imode);
22192214
set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
2220-
ocfs2_unpack_timespec(&ts,
2215+
ocfs2_unpack_timespec(&inode->i_atime,
22212216
be64_to_cpu(lvb->lvb_iatime_packed));
2222-
inode->i_atime = timespec_to_timespec64(ts);
2223-
ocfs2_unpack_timespec(&ts,
2217+
ocfs2_unpack_timespec(&inode->i_mtime,
22242218
be64_to_cpu(lvb->lvb_imtime_packed));
2225-
inode->i_mtime = timespec_to_timespec64(ts);
2226-
ocfs2_unpack_timespec(&ts,
2219+
ocfs2_unpack_timespec(&inode->i_ctime,
22272220
be64_to_cpu(lvb->lvb_ictime_packed));
2228-
inode->i_ctime = timespec_to_timespec64(ts);
22292221
spin_unlock(&oi->ip_lock);
22302222
}
22312223

@@ -3603,7 +3595,7 @@ static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
36033595
* we can recover correctly from node failure. Otherwise, we may get
36043596
* invalid LVB in LKB, but without DLM_SBF_VALNOTVALID being set.
36053597
*/
3606-
if (!ocfs2_is_o2cb_active() &&
3598+
if (ocfs2_userspace_stack(osb) &&
36073599
lockres->l_ops->flags & LOCK_TYPE_USES_LVB)
36083600
lvb = 1;
36093601

fs/ocfs2/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
23432343

23442344
written = __generic_file_write_iter(iocb, from);
23452345
/* buffered aio wouldn't have proper lock coverage today */
2346-
BUG_ON(written == -EIOCBQUEUED && !(iocb->ki_flags & IOCB_DIRECT));
2346+
BUG_ON(written == -EIOCBQUEUED && !direct_io);
23472347

23482348
/*
23492349
* deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io
@@ -2463,7 +2463,7 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
24632463
trace_generic_file_read_iter_ret(ret);
24642464

24652465
/* buffered aio wouldn't have proper lock coverage today */
2466-
BUG_ON(ret == -EIOCBQUEUED && !(iocb->ki_flags & IOCB_DIRECT));
2466+
BUG_ON(ret == -EIOCBQUEUED && !direct_io);
24672467

24682468
/* see ocfs2_file_write_iter */
24692469
if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) {

fs/ocfs2/journal.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,15 +1378,23 @@ static int __ocfs2_recovery_thread(void *arg)
13781378
int rm_quota_used = 0, i;
13791379
struct ocfs2_quota_recovery *qrec;
13801380

1381+
/* Whether the quota supported. */
1382+
int quota_enabled = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb,
1383+
OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
1384+
|| OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb,
1385+
OCFS2_FEATURE_RO_COMPAT_GRPQUOTA);
1386+
13811387
status = ocfs2_wait_on_mount(osb);
13821388
if (status < 0) {
13831389
goto bail;
13841390
}
13851391

1386-
rm_quota = kcalloc(osb->max_slots, sizeof(int), GFP_NOFS);
1387-
if (!rm_quota) {
1388-
status = -ENOMEM;
1389-
goto bail;
1392+
if (quota_enabled) {
1393+
rm_quota = kcalloc(osb->max_slots, sizeof(int), GFP_NOFS);
1394+
if (!rm_quota) {
1395+
status = -ENOMEM;
1396+
goto bail;
1397+
}
13901398
}
13911399
restart:
13921400
status = ocfs2_super_lock(osb, 1);
@@ -1422,9 +1430,14 @@ static int __ocfs2_recovery_thread(void *arg)
14221430
* then quota usage would be out of sync until some node takes
14231431
* the slot. So we remember which nodes need quota recovery
14241432
* and when everything else is done, we recover quotas. */
1425-
for (i = 0; i < rm_quota_used && rm_quota[i] != slot_num; i++);
1426-
if (i == rm_quota_used)
1427-
rm_quota[rm_quota_used++] = slot_num;
1433+
if (quota_enabled) {
1434+
for (i = 0; i < rm_quota_used
1435+
&& rm_quota[i] != slot_num; i++)
1436+
;
1437+
1438+
if (i == rm_quota_used)
1439+
rm_quota[rm_quota_used++] = slot_num;
1440+
}
14281441

14291442
status = ocfs2_recover_node(osb, node_num, slot_num);
14301443
skip_recovery:
@@ -1452,16 +1465,19 @@ static int __ocfs2_recovery_thread(void *arg)
14521465
/* Now it is right time to recover quotas... We have to do this under
14531466
* superblock lock so that no one can start using the slot (and crash)
14541467
* before we recover it */
1455-
for (i = 0; i < rm_quota_used; i++) {
1456-
qrec = ocfs2_begin_quota_recovery(osb, rm_quota[i]);
1457-
if (IS_ERR(qrec)) {
1458-
status = PTR_ERR(qrec);
1459-
mlog_errno(status);
1460-
continue;
1468+
if (quota_enabled) {
1469+
for (i = 0; i < rm_quota_used; i++) {
1470+
qrec = ocfs2_begin_quota_recovery(osb, rm_quota[i]);
1471+
if (IS_ERR(qrec)) {
1472+
status = PTR_ERR(qrec);
1473+
mlog_errno(status);
1474+
continue;
1475+
}
1476+
ocfs2_queue_recovery_completion(osb->journal,
1477+
rm_quota[i],
1478+
NULL, NULL, qrec,
1479+
ORPHAN_NEED_TRUNCATE);
14611480
}
1462-
ocfs2_queue_recovery_completion(osb->journal, rm_quota[i],
1463-
NULL, NULL, qrec,
1464-
ORPHAN_NEED_TRUNCATE);
14651481
}
14661482

14671483
ocfs2_super_unlock(osb, 1);
@@ -1483,7 +1499,8 @@ static int __ocfs2_recovery_thread(void *arg)
14831499

14841500
mutex_unlock(&osb->recovery_lock);
14851501

1486-
kfree(rm_quota);
1502+
if (quota_enabled)
1503+
kfree(rm_quota);
14871504

14881505
/* no one is callint kthread_stop() for us so the kthread() api
14891506
* requires that we call do_exit(). And it isn't exported, but

0 commit comments

Comments
 (0)