| 0/0 |
2026/05/29 16:18 |
flow |
patching |
1h11m
Results: map[AckedBy:[] Fixes:map[Hash:d647c5b2fbf81560818dacade360abc8c00a9665 Title:ocfs2: split transactions in dio completion to avoid credit exhaustion] KernelBranch:master KernelCommit:e7ae89a0c97ce2b68b0983cd01eda67cf373517d KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git PatchDescription:ocfs2: fix circular locking dependency in ocfs2_dio_end_io_write()
A circular locking dependency can occur involving three OCFS2 system inode
locks: INODE_ALLOC_SYSTEM_INODE, EXTENT_ALLOC_SYSTEM_INODE, and
ORPHAN_DIR_SYSTEM_INODE.
The circular dependency is formed by three separate code paths. First, in
ocfs2_mknod(), the code reserves an inode by acquiring the
INODE_ALLOC_SYSTEM_INODE lock, and then reserves metadata blocks by
acquiring the EXTENT_ALLOC_SYSTEM_INODE lock. Second, in
ocfs2_dio_end_io_write(), the code allocates metadata blocks for unwritten
extents, acquiring the EXTENT_ALLOC_SYSTEM_INODE lock. Later in the same
function, if the inode was orphaned, it calls
ocfs2_del_inode_from_orphan(), which acquires the ORPHAN_DIR_SYSTEM_INODE
lock. The allocation context is only freed at the end of the function,
meaning the EXTENT_ALLOC_SYSTEM_INODE lock is held while
ORPHAN_DIR_SYSTEM_INODE is acquired. Third, in ocfs2_wipe_inode(), the
ORPHAN_DIR_SYSTEM_INODE lock is acquired first to prevent races with
recovery completion, and then it calls ocfs2_remove_inode(), which acquires
the INODE_ALLOC_SYSTEM_INODE lock to free the inode.
This patch breaks the cycle by addressing the dependency in
ocfs2_dio_end_io_write(). The data_ac and meta_ac allocation contexts are
only needed for the transaction that marks the extents as written. Once the
transaction is committed and the allocation semaphore is released, these
contexts are no longer needed. We can safely free them, which releases the
EXTENT_ALLOC_SYSTEM_INODE lock, before calling
ocfs2_del_inode_from_orphan(). This ensures that the
EXTENT_ALLOC_SYSTEM_INODE lock is dropped before we attempt to acquire the
ORPHAN_DIR_SYSTEM_INODE lock, successfully breaking the circular
dependency. PatchDiff:diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 6ec198bda..4acdbb708 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2372,6 +2372,15 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2392,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
Recipients:[map[Email:jlbec@evilplan.org Name:Joel Becker To:true] map[Email:joseph.qi@linux.alibaba.com Name:Joseph Qi To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:mark@fasheh.com Name:Mark Fasheh To:true] map[Email:ocfs2-devel@lists.linux.dev Name: To:true]] ReportedBy:[] ReviewedBy:[] TestedBy:[]]
|
| 1/1 |
2026/05/29 16:18 |
action |
base-commit-picker |
0m
Results: map[KernelBranch:master KernelCommit:e7ae89a0c97ce2b68b0983cd01eda67cf373517d KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git]
|
| 2/1 |
2026/05/29 16:19 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/loop.h>
#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif
static unsigned long long procid;
//% This code is derived from puff.{c,h}, found in the zlib development. The
//% original files come with the following copyright notice:
//% Copyright (C) 2002-2013 Mark Adler, all rights reserved
//% version 2.3, 21 Jan 2013
//% This software is provided 'as-is', without any express or implied
//% warranty. In no event will the author be held liable for any damages
//% arising from the use of this software.
//% Permission is granted to anyone to use this software for any purpose,
//% including commercial applications, and to alter it and redistribute it
//% freely, subject to the following restrictions:
//% 1. The origin of this software must not be misrepresented; you must not
//% claim that you wrote the original software. If you use this software
//% in a product, an acknowledgment in the product documentation would be
//% appreciated but is not required.
//% 2. Altered source versions must be plainly marked as such, and must not be
//% misrepresented as being the original software.
//% 3. This notice may not be removed or altered from any source distribution.
//% Mark Adler madler@alumni.caltech.edu
//% BEGIN CODE DERIVED FROM puff.{c,h}
#define MAXBITS 15
#define MAXLCODES 286
#define MAXDCODES 30
#define MAXCODES (MAXLCODES + MAXDCODES)
#define FIXLCODES 288
struct puff_state {
unsigned char* out;
unsigned long outlen;
unsigned long outcnt;
const unsigned char* in;
unsigned long inlen;
unsigned long incnt;
int bitbuf;
int bitcnt;
jmp_buf env;
};
static int puff_bits(struct puff_state* s, int need)
{
long val = s->bitbuf;
while (s->bitcnt < need) {
if (s->incnt == s->inlen)
longjmp(s->env, 1);
val |= (long)(s->in[s->incnt++]) << s->bitcnt;
s->bitcnt += 8;
}
s->bitbuf = (int)(val >> need);
s->bitcnt -= need;
return (int)(val & ((1L << need) - 1));
}
static int puff_stored(struct puff_state* s)
{
s->bitbuf = 0;
s->bitcnt = 0;
if (s->incnt + 4 > s->inlen)
return 2;
unsigned len = s->in[s->incnt++];
len |= s->in[s->incnt++] << 8;
if (s->in[s->incnt++] != (~len & 0xff) ||
s->in[s->incnt++] != ((~len >> 8) & 0xff))
return -2;
if (s->incnt + len > s->inlen)
return 2;
if (s->outcnt + len > s->outlen)
return 1;
for (; len--; s->outcnt++, s->incnt++) {
if (s->in[s->incnt])
s->out[s->outcnt] = s->in[s->incnt];
}
return 0;
}
struct puff_huffman {
short* count;
short* symbol;
};
static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
{
int first = 0;
int index = 0;
int bitbuf = s->bitbuf;
int left = s->bitcnt;
int code = first = index = 0;
int len = 1;
short* next = h->count + 1;
while (1) {
while (left--) {
code |= bitbuf & 1;
bitbuf >>= 1;
int count = *next++;
if (code - count < first) {
s->bitbuf = bitbuf;
s->bitcnt = (s->bitcnt - len) & 7;
return h->symbol[index + (code - first)];
}
index += count;
first += count;
first <<= 1;
code <<= 1;
len++;
}
left = (MAXBITS + 1) - len;
if (left == 0)
break;
if (s->incnt == s->inlen)
longjmp(s->env, 1);
bitbuf = s->in[s->incnt++];
if (left > 8)
left = 8;
}
return -10;
}
static int puff_construct(struct puff_huffman* h, const short* length, int n)
{
int len;
for (len = 0; len <= MAXBITS; len++)
h->count[len] = 0;
int symbol;
for (symbol = 0; symbol < n; symbol++)
(h->count[length[symbol]])++;
if (h->count[0] == n)
return 0;
int left = 1;
for (len = 1; len <= MAXBITS; len++) {
left <<= 1;
left -= h->count[len];
if (left < 0)
return left;
}
short offs[MAXBITS + 1];
offs[1] = 0;
for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + h->count[len];
for (symbol = 0; symbol < n; symbol++)
if (length[symbol] != 0)
h->symbol[offs[length[symbol]]++] = symbol;
return left;
}
static int puff_codes(struct puff_state* s,
const struct puff_huffman* lencode,
const struct puff_huffman* distcode)
{
static const short lens[29] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
static const short lext[29] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
static const short dists[30] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
static const short dext[30] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
int symbol;
do {
symbol = puff_decode(s, lencode);
if (symbol < 0)
return symbol;
if (symbol < 256) {
if (s->outcnt == s->outlen)
return 1;
if (symbol)
s->out[s->outcnt] = symbol;
s->outcnt++;
} else if (symbol > 256) {
symbol -= 257;
if (symbol >= 29)
return -10;
int len = lens[symbol] + puff_bits(s, lext[symbol]);
symbol = puff_decode(s, distcode);
if (symbol < 0)
return symbol;
unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
if (dist > s->outcnt)
return -11;
if (s->outcnt + len > s->outlen)
return 1;
while (len--) {
if (dist <= s->outcnt && s->out[s->outcnt - dist])
s->out[s->outcnt] = s->out[s->outcnt - dist];
s->outcnt++;
}
}
} while (symbol != 256);
return 0;
}
static int puff_fixed(struct puff_state* s)
{
static int virgin = 1;
static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
static struct puff_huffman lencode, distcode;
if (virgin) {
lencode.count = lencnt;
lencode.symbol = lensym;
distcode.count = distcnt;
distcode.symbol = distsym;
short lengths[FIXLCODES];
int symbol;
for (symbol = 0; symbol < 144; symbol++)
lengths[symbol] = 8;
for (; symbol < 256; symbol++)
lengths[symbol] = 9;
for (; symbol < 280; symbol++)
lengths[symbol] = 7;
for (; symbol < FIXLCODES; symbol++)
lengths[symbol] = 8;
puff_construct(&lencode, lengths, FIXLCODES);
for (symbol = 0; symbol < MAXDCODES; symbol++)
lengths[symbol] = 5;
puff_construct(&distcode, lengths, MAXDCODES);
virgin = 0;
}
return puff_codes(s, &lencode, &distcode);
}
static int puff_dynamic(struct puff_state* s)
{
static const short order[19] =
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
int nlen = puff_bits(s, 5) + 257;
int ndist = puff_bits(s, 5) + 1;
int ncode = puff_bits(s, 4) + 4;
if (nlen > MAXLCODES || ndist > MAXDCODES)
return -3;
short lengths[MAXCODES];
int index;
for (index = 0; index < ncode; index++)
lengths[order[index]] = puff_bits(s, 3);
for (; index < 19; index++)
lengths[order[index]] = 0;
short lencnt[MAXBITS + 1], lensym[MAXLCODES];
struct puff_huffman lencode = {lencnt, lensym};
int err = puff_construct(&lencode, lengths, 19);
if (err != 0)
return -4;
index = 0;
while (index < nlen + ndist) {
int symbol;
int len;
symbol = puff_decode(s, &lencode);
if (symbol < 0)
return symbol;
if (symbol < 16)
lengths[index++] = symbol;
else {
len = 0;
if (symbol == 16) {
if (index == 0)
return -5;
len = lengths[index - 1];
symbol = 3 + puff_bits(s, 2);
} else if (symbol == 17)
symbol = 3 + puff_bits(s, 3);
else
symbol = 11 + puff_bits(s, 7);
if (index + symbol > nlen + ndist)
return -6;
while (symbol--)
lengths[index++] = len;
}
}
if (lengths[256] == 0)
return -9;
err = puff_construct(&lencode, lengths, nlen);
if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
return -7;
short distcnt[MAXBITS + 1], distsym[MAXDCODES];
struct puff_huffman distcode = {distcnt, distsym};
err = puff_construct(&distcode, lengths + nlen, ndist);
if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
return -8;
return puff_codes(s, &lencode, &distcode);
}
static int puff(
unsigned char* dest,
unsigned long* destlen,
const unsigned char* source,
unsigned long sourcelen)
{
struct puff_state s = {
.out = dest,
.outlen = *destlen,
.outcnt = 0,
.in = source,
.inlen = sourcelen,
.incnt = 0,
.bitbuf = 0,
.bitcnt = 0,
};
int err;
if (setjmp(s.env) != 0)
err = 2;
else {
int last;
do {
last = puff_bits(&s, 1);
int type = puff_bits(&s, 2);
err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1));
if (err != 0)
break;
} while (!last);
}
*destlen = s.outcnt;
return err;
}
//% END CODE DERIVED FROM puff.{c,h}
#define ZLIB_HEADER_WIDTH 2
static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd)
{
if (sourcelen < ZLIB_HEADER_WIDTH)
return 0;
source += ZLIB_HEADER_WIDTH;
sourcelen -= ZLIB_HEADER_WIDTH;
const unsigned long max_destlen = 132 << 20;
void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
if (ret == MAP_FAILED)
return -1;
unsigned char* dest = (unsigned char*)ret;
unsigned long destlen = max_destlen;
int err = puff(dest, &destlen, source, sourcelen);
if (err) {
munmap(dest, max_destlen);
errno = -err;
return -1;
}
if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
munmap(dest, max_destlen);
return -1;
}
return munmap(dest, max_destlen);
}
static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p)
{
int err = 0, loopfd = -1;
int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
if (memfd == -1) {
err = errno;
goto error;
}
if (puff_zlib_to_file(data, size, memfd)) {
err = errno;
goto error_close_memfd;
}
loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
err = errno;
goto error_close_memfd;
}
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
if (errno != EBUSY) {
err = errno;
goto error_close_loop;
}
ioctl(loopfd, LOOP_CLR_FD, 0);
usleep(1000);
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
err = errno;
goto error_close_loop;
}
}
close(memfd);
*loopfd_p = loopfd;
return 0;
error_close_loop:
close(loopfd);
error_close_memfd:
close(memfd);
error:
errno = err;
return -1;
}
static void reset_loop_device(const char* loopname)
{
int loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
return;
}
if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
}
close(loopfd);
}
static long syz_mount_image(
volatile long fsarg,
volatile long dir,
volatile long flags,
volatile long optsarg,
volatile long change_dir,
volatile unsigned long size,
volatile long image)
{
unsigned char* data = (unsigned char*)image;
int res = -1, err = 0, need_loop_device = !!size;
char* mount_opts = (char*)optsarg;
char* target = (char*)dir;
char* fs = (char*)fsarg;
char* source = NULL;
char loopname[64];
if (need_loop_device) {
int loopfd;
memset(loopname, 0, sizeof(loopname));
snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
if (setup_loop_device(data, size, loopname, &loopfd) == -1)
return -1;
close(loopfd);
source = loopname;
}
mkdir(target, 0777);
char opts[256];
memset(opts, 0, sizeof(opts));
if (strlen(mount_opts) > (sizeof(opts) - 32)) {
}
strncpy(opts, mount_opts, sizeof(opts) - 32);
if (strcmp(fs, "iso9660") == 0) {
flags |= MS_RDONLY;
} else if (strncmp(fs, "ext", 3) == 0) {
bool has_remount_ro = false;
char* remount_ro_start = strstr(opts, "errors=remount-ro");
if (remount_ro_start != NULL) {
char after = *(remount_ro_start + strlen("errors=remount-ro"));
char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ','));
}
if (strstr(opts, "errors=panic") || !has_remount_ro)
strcat(opts, ",errors=continue");
} else if (strcmp(fs, "xfs") == 0) {
strcat(opts, ",nouuid");
} else if (strncmp(fs, "gfs2", 4) == 0 && (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
strcat(opts, ",errors=withdraw");
}
res = mount(source, target, fs, flags, opts);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
res = open(target, O_RDONLY | O_DIRECTORY);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
if (change_dir) {
res = chdir(target);
if (res == -1) {
err = errno;
}
}
error_clear_loop:
if (need_loop_device)
reset_loop_device(loopname);
errno = err;
return res;
}
#define USLEEP_FORKED_CHILD (3 * 50 *1000)
static long handle_clone_ret(long ret)
{
if (ret != 0) {
return ret;
}
usleep(USLEEP_FORKED_CHILD);
syscall(__NR_exit, 0);
while (1) {
}
}
static long syz_clone(volatile long flags, volatile long stack, volatile long stack_len,
volatile long ptid, volatile long ctid, volatile long tls)
{
long sp = (stack + stack_len) & ~15;
long ret = (long)syscall(__NR_clone, flags & ~CLONE_VM, sp, ptid, ctid, tls);
return handle_clone_ret(ret);
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_mount_image$ocfs2 arguments: [
// fs: ptr[in, buffer] {
// buffer: {6f 63 66 73 32 00} (length 0x6)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: mount_flags = 0x8c0 (8 bytes)
// opts: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {61 63 6c 2c 68 65 61 72 74 62 65 61 74 3d 6e 6f 6e 65 2c 64 69 72 5f 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 2c 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 36 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6c 6f 63 61 6c 66 6c 6f 63 6b 73 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6e 6f 61 63 6c 2c 00 4c 98 06 5b 85 e5 b1 37 d6 3b 22 11 c6 2c 40 20 45 08 3d a9 bd dc 3b 0d 88 d4 4e cd 24 ba 52 88 d4 28 19 72 84 f3 32 85 8b 83 34 9a f2 c7 64 6f 1e 07 e9 11 20 d7 f2 3c e2 03 89 bb c0 31 d8 1d 65 4f 1c a0 8f 61 c9 2d 90 e6 ea 47 88 43 c1 ad 94 2c 7c 25 7f 9f f5 34 8d d0 38 e9 47 77 59 91 ad 90 f8 86 1d ad a2 1d 5f a2 de 70 42 b5 e2 cb bc d1 ad a2 b5 68 e3 75 81 2e b0 bc 44 8e 68 ed a4 c7 0c f1 d5 ad f5 66 14 2e d4 59 24 fe 72 a1 eb 1a 91 4f af 75 4b 9d 94 bf 0f dc 1f 98 c7 08 bd 89 94 0b 5e f9 6e 32 82 40 c3 95 59 b3 5b c8 3c 15 c1 51 04 f3 b3 fe 19 45 f0 27 8c 34 e2 39 9d ad cd 97 76 ac 65 9a fc bb 23 95 69 14 0a b4 08 ad 87 f1 5b 35 39 41} (length 0x160)
// }
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x442a (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x442a)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000004440, "ocfs2\000", 6);
memcpy((void*)0x200000000040, "./file1\000", 8);
memcpy((void*)0x200000000600, "... [truncated large byte array] ...", 352);
memcpy((void*)0x200000004480, "... [truncated large byte array] ...", 17450);
syz_mount_image(/*fs=*/0x200000004440, /*dir=*/0x200000000040, /*flags=MS_NODIRATIME|MS_MANDLOCK|MS_DIRSYNC*/0x8c0, /*opts=*/0x200000000600, /*chdir=*/1, /*size=*/0x442a, /*img=*/0x200000004480);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x4842 (4 bytes)
// mode: open_mode = 0x1cb (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000240, "./file1\000", 8);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000240ul, /*flags=O_NONBLOCK|O_DIRECT|O_CREAT|O_RDWR*/0x4842, /*mode=S_IXOTH|S_IWOTH|S_IXGRP|S_IXUSR|S_IWUSR|S_IRUSR*/0x1cb);
if (res != -1)
r[0] = res;
// writev arguments: [
// fd: fd (resource)
// vec: ptr[in, array[iovec[in, array[int8]]]] {
// array[iovec[in, array[int8]]] {
// iovec[in, array[int8]] {
// addr: ptr[in, buffer] {
// buffer: {10} (length 0x1)
// }
// len: len = 0x64000 (8 bytes)
// }
// }
// }
// vlen: len = 0x1 (8 bytes)
// ]
*(uint64_t*)0x200000000140 = 0x200000001200;
memset((void*)0x200000001200, 16, 1);
*(uint64_t*)0x200000000148 = 0x64000;
syscall(__NR_writev, /*fd=*/r[0], /*vec=*/0x200000000140ul, /*vlen=*/1ul);
// syz_clone arguments: [
// flags: clone_flags = 0x20000 (8 bytes)
// stack: nil
// stack_len: bytesize = 0x0 (8 bytes)
// parentid: nil
// childtid: nil
// tls: nil
// ]
// returns pid
syz_clone(/*flags=CLONE_NEWNS*/0x20000, /*stack=*/0, /*stack_len=*/0, /*parentid=*/0, /*childtid=*/0, /*tls=*/0);
return 0;
}
]
|
| 3/1 |
2026/05/29 16:19 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/9e90653914128b0c0a243c2451f414ecec48632b]
|
| 4/1 |
2026/05/29 16:19 |
action |
kernel-builder |
18m
Results: map[KernelObj:/app/workdir/cache/build/eef59a5c837ce8de757f02acbdd4863423e1edc1]
|
| 5/1 |
2026/05/29 16:37 |
action |
crash-reproducer |
1m
Results: map[OtherCrashReports:<nil> ReproducedBugTitle:possible deadlock in ocfs2_evict_inode ReproducedCrashReport:======================================================
WARNING: possible circular locking dependency detected
syzkaller #1 Not tainted
------------------------------------------------------
syz-executor/6069 is trying to acquire lock:
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
but task is already holding lock:
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_del_inode_from_orphan+0x12e/0x7a0 fs/ocfs2/namei.c:2728
ocfs2_dio_end_io_write fs/ocfs2/aops.c:2379 [inline]
ocfs2_dio_end_io+0xf9c/0x1370 fs/ocfs2/aops.c:2418
dio_complete+0x25b/0x790 fs/direct-io.c:281
__blockdev_direct_IO+0x2e5d/0x34e0 fs/direct-io.c:1303
ocfs2_direct_IO+0x251/0x2c0 fs/ocfs2/aops.c:2455
generic_file_direct_write+0x1db/0x3e0 mm/filemap.c:4259
__generic_file_write_iter+0x11d/0x230 mm/filemap.c:4428
ocfs2_file_write_iter+0x1663/0x1e70 fs/ocfs2/file.c:2476
do_iter_readv_writev+0x619/0x8c0 fs/read_write.c:-1
vfs_writev+0x33c/0x990 fs/read_write.c:1059
do_writev+0x154/0x2e0 fs/read_write.c:1105
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_reserve_suballoc_bits+0x16d/0x4840 fs/ocfs2/suballoc.c:882
ocfs2_reserve_new_metadata_blocks+0x415/0x9a0 fs/ocfs2/suballoc.c:1078
ocfs2_mknod+0x10f3/0x2260 fs/ocfs2/namei.c:351
ocfs2_create+0x195/0x460 fs/ocfs2/namei.c:677
lookup_open fs/namei.c:4511 [inline]
open_last_lookups fs/namei.c:4611 [inline]
path_openat+0x1395/0x3860 fs/namei.c:4855
do_file_open+0x23e/0x4a0 fs/namei.c:4887
do_sys_openat2+0x113/0x200 fs/open.c:1364
do_sys_open fs/open.c:1370 [inline]
__do_sys_openat fs/open.c:1386 [inline]
__se_sys_openat fs/open.c:1381 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
*** DEADLOCK ***
4 locks held by syz-executor/6069:
#0: ffff8881161a4410 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:1074 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: __start_dirop fs/namei.c:2914 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: start_dirop fs/namei.c:2938 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: filename_rmdir+0x1cd/0x520 fs/namei.c:5414
#2: ffff8881166b0bc0 (&osb->nfs_sync_rwlock){.+.+}-{4:4}, at: ocfs2_nfs_sync_lock+0x106/0x270 fs/ocfs2/dlmglue.c:2875
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
stack backtrace:
CPU: 1 UID: 0 PID: 6069 Comm: syz-executor Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e1/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f51b819bf77
Code: 77 01 c3 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 b8 07 01 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd5ea06718 EFLAGS: 00000207 ORIG_RAX: 0000000000000107
RAX: ffffffffffffffda RBX: 0000000000000065 RCX: 00007f51b819bf77
RDX: 0000000000000200 RSI: 00007ffd5ea078c0 RDI: 00000000ffffff9c
RBP: 00007f51b82321ca R08: 0000000000018560 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffd5ea078c0
R13: 00007f51b82321ca R14: 000000000001819f R15: 00007ffd5ea09a80
</TASK>
ReproducedFaultInjection:]
|
| 6/1 |
2026/05/29 16:39 |
action |
codesearch-prepare |
13m
Results: map[Index:codesearch-index]
|
| 7/1 |
2026/05/29 16:52 |
agent |
debugger |
6m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with debugging a kernel crash root cause.
You need to provide a detailed explanation of the root cause for another developer to be
able to write a fix for the bug based on your explanation. Include all relevant details
into the response: function/struct/field/etc names, code snippets, line numbers,
macro/enum values, etc.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #1 Not tainted
------------------------------------------------------
syz-executor/6069 is trying to acquire lock:
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
but task is already holding lock:
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_del_inode_from_orphan+0x12e/0x7a0 fs/ocfs2/namei.c:2728
ocfs2_dio_end_io_write fs/ocfs2/aops.c:2379 [inline]
ocfs2_dio_end_io+0xf9c/0x1370 fs/ocfs2/aops.c:2418
dio_complete+0x25b/0x790 fs/direct-io.c:281
__blockdev_direct_IO+0x2e5d/0x34e0 fs/direct-io.c:1303
ocfs2_direct_IO+0x251/0x2c0 fs/ocfs2/aops.c:2455
generic_file_direct_write+0x1db/0x3e0 mm/filemap.c:4259
__generic_file_write_iter+0x11d/0x230 mm/filemap.c:4428
ocfs2_file_write_iter+0x1663/0x1e70 fs/ocfs2/file.c:2476
do_iter_readv_writev+0x619/0x8c0 fs/read_write.c:-1
vfs_writev+0x33c/0x990 fs/read_write.c:1059
do_writev+0x154/0x2e0 fs/read_write.c:1105
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_reserve_suballoc_bits+0x16d/0x4840 fs/ocfs2/suballoc.c:882
ocfs2_reserve_new_metadata_blocks+0x415/0x9a0 fs/ocfs2/suballoc.c:1078
ocfs2_mknod+0x10f3/0x2260 fs/ocfs2/namei.c:351
ocfs2_create+0x195/0x460 fs/ocfs2/namei.c:677
lookup_open fs/namei.c:4511 [inline]
open_last_lookups fs/namei.c:4611 [inline]
path_openat+0x1395/0x3860 fs/namei.c:4855
do_file_open+0x23e/0x4a0 fs/namei.c:4887
do_sys_openat2+0x113/0x200 fs/open.c:1364
do_sys_open fs/open.c:1370 [inline]
__do_sys_openat fs/open.c:1386 [inline]
__se_sys_openat fs/open.c:1381 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
*** DEADLOCK ***
4 locks held by syz-executor/6069:
#0: ffff8881161a4410 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:1074 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: __start_dirop fs/namei.c:2914 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: start_dirop fs/namei.c:2938 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: filename_rmdir+0x1cd/0x520 fs/namei.c:5414
#2: ffff8881166b0bc0 (&osb->nfs_sync_rwlock){.+.+}-{4:4}, at: ocfs2_nfs_sync_lock+0x106/0x270 fs/ocfs2/dlmglue.c:2875
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
stack backtrace:
CPU: 1 UID: 0 PID: 6069 Comm: syz-executor Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e1/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f51b819bf77
Code: 77 01 c3 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 b8 07 01 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd5ea06718 EFLAGS: 00000207 ORIG_RAX: 0000000000000107
RAX: ffffffffffffffda RBX: 0000000000000065 RCX: 00007f51b819bf77
RDX: 0000000000000200 RSI: 00007ffd5ea078c0 RDI: 00000000ffffff9c
RBP: 00007f51b82321ca R08: 0000000000018560 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffd5ea078c0
R13: 00007f51b82321ca R14: 000000000001819f R15: 00007ffd5ea09a80
</TASK>
The following C code is a draft of the vulnerable syscall sequence. Keep in mind that
it may lack the precise threading, sandboxing, and some arguments of a working reproducer:
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/loop.h>
#ifndef __NR_memfd_create
#define __NR_memfd_create 319
#endif
static unsigned long long procid;
//% This code is derived from puff.{c,h}, found in the zlib development. The
//% original files come with the following copyright notice:
//% Copyright (C) 2002-2013 Mark Adler, all rights reserved
//% version 2.3, 21 Jan 2013
//% This software is provided 'as-is', without any express or implied
//% warranty. In no event will the author be held liable for any damages
//% arising from the use of this software.
//% Permission is granted to anyone to use this software for any purpose,
//% including commercial applications, and to alter it and redistribute it
//% freely, subject to the following restrictions:
//% 1. The origin of this software must not be misrepresented; you must not
//% claim that you wrote the original software. If you use this software
//% in a product, an acknowledgment in the product documentation would be
//% appreciated but is not required.
//% 2. Altered source versions must be plainly marked as such, and must not be
//% misrepresented as being the original software.
//% 3. This notice may not be removed or altered from any source distribution.
//% Mark Adler madler@alumni.caltech.edu
//% BEGIN CODE DERIVED FROM puff.{c,h}
#define MAXBITS 15
#define MAXLCODES 286
#define MAXDCODES 30
#define MAXCODES (MAXLCODES + MAXDCODES)
#define FIXLCODES 288
struct puff_state {
unsigned char* out;
unsigned long outlen;
unsigned long outcnt;
const unsigned char* in;
unsigned long inlen;
unsigned long incnt;
int bitbuf;
int bitcnt;
jmp_buf env;
};
static int puff_bits(struct puff_state* s, int need)
{
long val = s->bitbuf;
while (s->bitcnt < need) {
if (s->incnt == s->inlen)
longjmp(s->env, 1);
val |= (long)(s->in[s->incnt++]) << s->bitcnt;
s->bitcnt += 8;
}
s->bitbuf = (int)(val >> need);
s->bitcnt -= need;
return (int)(val & ((1L << need) - 1));
}
static int puff_stored(struct puff_state* s)
{
s->bitbuf = 0;
s->bitcnt = 0;
if (s->incnt + 4 > s->inlen)
return 2;
unsigned len = s->in[s->incnt++];
len |= s->in[s->incnt++] << 8;
if (s->in[s->incnt++] != (~len & 0xff) ||
s->in[s->incnt++] != ((~len >> 8) & 0xff))
return -2;
if (s->incnt + len > s->inlen)
return 2;
if (s->outcnt + len > s->outlen)
return 1;
for (; len--; s->outcnt++, s->incnt++) {
if (s->in[s->incnt])
s->out[s->outcnt] = s->in[s->incnt];
}
return 0;
}
struct puff_huffman {
short* count;
short* symbol;
};
static int puff_decode(struct puff_state* s, const struct puff_huffman* h)
{
int first = 0;
int index = 0;
int bitbuf = s->bitbuf;
int left = s->bitcnt;
int code = first = index = 0;
int len = 1;
short* next = h->count + 1;
while (1) {
while (left--) {
code |= bitbuf & 1;
bitbuf >>= 1;
int count = *next++;
if (code - count < first) {
s->bitbuf = bitbuf;
s->bitcnt = (s->bitcnt - len) & 7;
return h->symbol[index + (code - first)];
}
index += count;
first += count;
first <<= 1;
code <<= 1;
len++;
}
left = (MAXBITS + 1) - len;
if (left == 0)
break;
if (s->incnt == s->inlen)
longjmp(s->env, 1);
bitbuf = s->in[s->incnt++];
if (left > 8)
left = 8;
}
return -10;
}
static int puff_construct(struct puff_huffman* h, const short* length, int n)
{
int len;
for (len = 0; len <= MAXBITS; len++)
h->count[len] = 0;
int symbol;
for (symbol = 0; symbol < n; symbol++)
(h->count[length[symbol]])++;
if (h->count[0] == n)
return 0;
int left = 1;
for (len = 1; len <= MAXBITS; len++) {
left <<= 1;
left -= h->count[len];
if (left < 0)
return left;
}
short offs[MAXBITS + 1];
offs[1] = 0;
for (len = 1; len < MAXBITS; len++)
offs[len + 1] = offs[len] + h->count[len];
for (symbol = 0; symbol < n; symbol++)
if (length[symbol] != 0)
h->symbol[offs[length[symbol]]++] = symbol;
return left;
}
static int puff_codes(struct puff_state* s,
const struct puff_huffman* lencode,
const struct puff_huffman* distcode)
{
static const short lens[29] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
static const short lext[29] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
static const short dists[30] = {
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
static const short dext[30] = {
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
int symbol;
do {
symbol = puff_decode(s, lencode);
if (symbol < 0)
return symbol;
if (symbol < 256) {
if (s->outcnt == s->outlen)
return 1;
if (symbol)
s->out[s->outcnt] = symbol;
s->outcnt++;
} else if (symbol > 256) {
symbol -= 257;
if (symbol >= 29)
return -10;
int len = lens[symbol] + puff_bits(s, lext[symbol]);
symbol = puff_decode(s, distcode);
if (symbol < 0)
return symbol;
unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]);
if (dist > s->outcnt)
return -11;
if (s->outcnt + len > s->outlen)
return 1;
while (len--) {
if (dist <= s->outcnt && s->out[s->outcnt - dist])
s->out[s->outcnt] = s->out[s->outcnt - dist];
s->outcnt++;
}
}
} while (symbol != 256);
return 0;
}
static int puff_fixed(struct puff_state* s)
{
static int virgin = 1;
static short lencnt[MAXBITS + 1], lensym[FIXLCODES];
static short distcnt[MAXBITS + 1], distsym[MAXDCODES];
static struct puff_huffman lencode, distcode;
if (virgin) {
lencode.count = lencnt;
lencode.symbol = lensym;
distcode.count = distcnt;
distcode.symbol = distsym;
short lengths[FIXLCODES];
int symbol;
for (symbol = 0; symbol < 144; symbol++)
lengths[symbol] = 8;
for (; symbol < 256; symbol++)
lengths[symbol] = 9;
for (; symbol < 280; symbol++)
lengths[symbol] = 7;
for (; symbol < FIXLCODES; symbol++)
lengths[symbol] = 8;
puff_construct(&lencode, lengths, FIXLCODES);
for (symbol = 0; symbol < MAXDCODES; symbol++)
lengths[symbol] = 5;
puff_construct(&distcode, lengths, MAXDCODES);
virgin = 0;
}
return puff_codes(s, &lencode, &distcode);
}
static int puff_dynamic(struct puff_state* s)
{
static const short order[19] =
{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
int nlen = puff_bits(s, 5) + 257;
int ndist = puff_bits(s, 5) + 1;
int ncode = puff_bits(s, 4) + 4;
if (nlen > MAXLCODES || ndist > MAXDCODES)
return -3;
short lengths[MAXCODES];
int index;
for (index = 0; index < ncode; index++)
lengths[order[index]] = puff_bits(s, 3);
for (; index < 19; index++)
lengths[order[index]] = 0;
short lencnt[MAXBITS + 1], lensym[MAXLCODES];
struct puff_huffman lencode = {lencnt, lensym};
int err = puff_construct(&lencode, lengths, 19);
if (err != 0)
return -4;
index = 0;
while (index < nlen + ndist) {
int symbol;
int len;
symbol = puff_decode(s, &lencode);
if (symbol < 0)
return symbol;
if (symbol < 16)
lengths[index++] = symbol;
else {
len = 0;
if (symbol == 16) {
if (index == 0)
return -5;
len = lengths[index - 1];
symbol = 3 + puff_bits(s, 2);
} else if (symbol == 17)
symbol = 3 + puff_bits(s, 3);
else
symbol = 11 + puff_bits(s, 7);
if (index + symbol > nlen + ndist)
return -6;
while (symbol--)
lengths[index++] = len;
}
}
if (lengths[256] == 0)
return -9;
err = puff_construct(&lencode, lengths, nlen);
if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1]))
return -7;
short distcnt[MAXBITS + 1], distsym[MAXDCODES];
struct puff_huffman distcode = {distcnt, distsym};
err = puff_construct(&distcode, lengths + nlen, ndist);
if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1]))
return -8;
return puff_codes(s, &lencode, &distcode);
}
static int puff(
unsigned char* dest,
unsigned long* destlen,
const unsigned char* source,
unsigned long sourcelen)
{
struct puff_state s = {
.out = dest,
.outlen = *destlen,
.outcnt = 0,
.in = source,
.inlen = sourcelen,
.incnt = 0,
.bitbuf = 0,
.bitcnt = 0,
};
int err;
if (setjmp(s.env) != 0)
err = 2;
else {
int last;
do {
last = puff_bits(&s, 1);
int type = puff_bits(&s, 2);
err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1));
if (err != 0)
break;
} while (!last);
}
*destlen = s.outcnt;
return err;
}
//% END CODE DERIVED FROM puff.{c,h}
#define ZLIB_HEADER_WIDTH 2
static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd)
{
if (sourcelen < ZLIB_HEADER_WIDTH)
return 0;
source += ZLIB_HEADER_WIDTH;
sourcelen -= ZLIB_HEADER_WIDTH;
const unsigned long max_destlen = 132 << 20;
void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
if (ret == MAP_FAILED)
return -1;
unsigned char* dest = (unsigned char*)ret;
unsigned long destlen = max_destlen;
int err = puff(dest, &destlen, source, sourcelen);
if (err) {
munmap(dest, max_destlen);
errno = -err;
return -1;
}
if (write(dest_fd, dest, destlen) != (ssize_t)destlen) {
munmap(dest, max_destlen);
return -1;
}
return munmap(dest, max_destlen);
}
static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p)
{
int err = 0, loopfd = -1;
int memfd = syscall(__NR_memfd_create, "syzkaller", 0);
if (memfd == -1) {
err = errno;
goto error;
}
if (puff_zlib_to_file(data, size, memfd)) {
err = errno;
goto error_close_memfd;
}
loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
err = errno;
goto error_close_memfd;
}
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
if (errno != EBUSY) {
err = errno;
goto error_close_loop;
}
ioctl(loopfd, LOOP_CLR_FD, 0);
usleep(1000);
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
err = errno;
goto error_close_loop;
}
}
close(memfd);
*loopfd_p = loopfd;
return 0;
error_close_loop:
close(loopfd);
error_close_memfd:
close(memfd);
error:
errno = err;
return -1;
}
static void reset_loop_device(const char* loopname)
{
int loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
return;
}
if (ioctl(loopfd, LOOP_CLR_FD, 0)) {
}
close(loopfd);
}
static long syz_mount_image(
volatile long fsarg,
volatile long dir,
volatile long flags,
volatile long optsarg,
volatile long change_dir,
volatile unsigned long size,
volatile long image)
{
unsigned char* data = (unsigned char*)image;
int res = -1, err = 0, need_loop_device = !!size;
char* mount_opts = (char*)optsarg;
char* target = (char*)dir;
char* fs = (char*)fsarg;
char* source = NULL;
char loopname[64];
if (need_loop_device) {
int loopfd;
memset(loopname, 0, sizeof(loopname));
snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
if (setup_loop_device(data, size, loopname, &loopfd) == -1)
return -1;
close(loopfd);
source = loopname;
}
mkdir(target, 0777);
char opts[256];
memset(opts, 0, sizeof(opts));
if (strlen(mount_opts) > (sizeof(opts) - 32)) {
}
strncpy(opts, mount_opts, sizeof(opts) - 32);
if (strcmp(fs, "iso9660") == 0) {
flags |= MS_RDONLY;
} else if (strncmp(fs, "ext", 3) == 0) {
bool has_remount_ro = false;
char* remount_ro_start = strstr(opts, "errors=remount-ro");
if (remount_ro_start != NULL) {
char after = *(remount_ro_start + strlen("errors=remount-ro"));
char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1);
has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ','));
}
if (strstr(opts, "errors=panic") || !has_remount_ro)
strcat(opts, ",errors=continue");
} else if (strcmp(fs, "xfs") == 0) {
strcat(opts, ",nouuid");
} else if (strncmp(fs, "gfs2", 4) == 0 && (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
strcat(opts, ",errors=withdraw");
}
res = mount(source, target, fs, flags, opts);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
res = open(target, O_RDONLY | O_DIRECTORY);
if (res == -1) {
err = errno;
goto error_clear_loop;
}
if (change_dir) {
res = chdir(target);
if (res == -1) {
err = errno;
}
}
error_clear_loop:
if (need_loop_device)
reset_loop_device(loopname);
errno = err;
return res;
}
#define USLEEP_FORKED_CHILD (3 * 50 *1000)
static long handle_clone_ret(long ret)
{
if (ret != 0) {
return ret;
}
usleep(USLEEP_FORKED_CHILD);
syscall(__NR_exit, 0);
while (1) {
}
}
static long syz_clone(volatile long flags, volatile long stack, volatile long stack_len,
volatile long ptid, volatile long ctid, volatile long tls)
{
long sp = (stack + stack_len) & ~15;
long ret = (long)syscall(__NR_clone, flags & ~CLONE_VM, sp, ptid, ctid, tls);
return handle_clone_ret(ret);
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_mount_image$ocfs2 arguments: [
// fs: ptr[in, buffer] {
// buffer: {6f 63 66 73 32 00} (length 0x6)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: mount_flags = 0x8c0 (8 bytes)
// opts: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {61 63 6c 2c 68 65 61 72 74 62 65 61 74 3d 6e 6f 6e 65 2c 64 69 72 5f 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 33 2c 72 65 73 76 5f 6c 65 76 65 6c 3d 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 36 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6c 6f 63 61 6c 66 6c 6f 63 6b 73 2c 63 6f 68 65 72 65 6e 63 79 3d 66 75 6c 6c 2c 6e 6f 61 63 6c 2c 00 4c 98 06 5b 85 e5 b1 37 d6 3b 22 11 c6 2c 40 20 45 08 3d a9 bd dc 3b 0d 88 d4 4e cd 24 ba 52 88 d4 28 19 72 84 f3 32 85 8b 83 34 9a f2 c7 64 6f 1e 07 e9 11 20 d7 f2 3c e2 03 89 bb c0 31 d8 1d 65 4f 1c a0 8f 61 c9 2d 90 e6 ea 47 88 43 c1 ad 94 2c 7c 25 7f 9f f5 34 8d d0 38 e9 47 77 59 91 ad 90 f8 86 1d ad a2 1d 5f a2 de 70 42 b5 e2 cb bc d1 ad a2 b5 68 e3 75 81 2e b0 bc 44 8e 68 ed a4 c7 0c f1 d5 ad f5 66 14 2e d4 59 24 fe 72 a1 eb 1a 91 4f af 75 4b 9d 94 bf 0f dc 1f 98 c7 08 bd 89 94 0b 5e f9 6e 32 82 40 c3 95 59 b3 5b c8 3c 15 c1 51 04 f3 b3 fe 19 45 f0 27 8c 34 e2 39 9d ad cd 97 76 ac 65 9a fc bb 23 95 69 14 0a b4 08 ad 87 f1 5b 35 39 41} (length 0x160)
// }
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x442a (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x442a)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000004440, "ocfs2\000", 6);
memcpy((void*)0x200000000040, "./file1\000", 8);
memcpy((void*)0x200000000600, "... [truncated large byte array] ...", 352);
memcpy((void*)0x200000004480, "... [truncated large byte array] ...", 17450);
syz_mount_image(/*fs=*/0x200000004440, /*dir=*/0x200000000040, /*flags=MS_NODIRATIME|MS_MANDLOCK|MS_DIRSYNC*/0x8c0, /*opts=*/0x200000000600, /*chdir=*/1, /*size=*/0x442a, /*img=*/0x200000004480);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8)
// }
// flags: open_flags = 0x4842 (4 bytes)
// mode: open_mode = 0x1cb (2 bytes)
// ]
// returns fd
memcpy((void*)0x200000000240, "./file1\000", 8);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000240ul, /*flags=O_NONBLOCK|O_DIRECT|O_CREAT|O_RDWR*/0x4842, /*mode=S_IXOTH|S_IWOTH|S_IXGRP|S_IXUSR|S_IWUSR|S_IRUSR*/0x1cb);
if (res != -1)
r[0] = res;
// writev arguments: [
// fd: fd (resource)
// vec: ptr[in, array[iovec[in, array[int8]]]] {
// array[iovec[in, array[int8]]] {
// iovec[in, array[int8]] {
// addr: ptr[in, buffer] {
// buffer: {10} (length 0x1)
// }
// len: len = 0x64000 (8 bytes)
// }
// }
// }
// vlen: len = 0x1 (8 bytes)
// ]
*(uint64_t*)0x200000000140 = 0x200000001200;
memset((void*)0x200000001200, 16, 1);
*(uint64_t*)0x200000000148 = 0x64000;
syscall(__NR_writev, /*fd=*/r[0], /*vec=*/0x200000000140ul, /*vlen=*/1ul);
// syz_clone arguments: [
// flags: clone_flags = 0x20000 (8 bytes)
// stack: nil
// stack_len: bytesize = 0x0 (8 bytes)
// parentid: nil
// childtid: nil
// tls: nil
// ]
// returns pid
syz_clone(/*flags=CLONE_NEWNS*/0x20000, /*stack=*/0, /*stack_len=*/0, /*parentid=*/0, /*childtid=*/0, /*tls=*/0);
return 0;
}
Reply: The lockdep warning reports a circular locking dependency involving three OCFS2 system inode locks (which all belong to the `ocfs2_sysfile_lock_key` lock class, but are distinct locks based on their system inode type).
The three locks involved are:
1. `INODE_ALLOC_SYSTEM_INODE`
2. `EXTENT_ALLOC_SYSTEM_INODE`
3. `ORPHAN_DIR_SYSTEM_INODE`
### Root Cause Analysis
The circular dependency is formed by three separate code paths that establish the following lock ordering:
**1. `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE`**
In `ocfs2_mknod()` (`fs/ocfs2/namei.c`), the code first reserves an inode by calling `ocfs2_reserve_new_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock. Shortly after, it reserves metadata blocks by calling `ocfs2_reserve_new_metadata_blocks()`, which acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Both locks are held concurrently until the end of the function (or upon error), establishing this dependency.
**2. `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`**
In `ocfs2_dio_end_io_write()` (`fs/ocfs2/aops.c`), the code allocates metadata blocks for unwritten extents by calling `ocfs2_lock_allocators()`. This allocates `meta_ac` and acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Later in the same function, if the inode was orphaned, it calls `ocfs2_del_inode_from_orphan()`, which acquires the `ORPHAN_DIR_SYSTEM_INODE` lock. The `meta_ac` context (and thus the `EXTENT_ALLOC_SYSTEM_INODE` lock) is only freed at the very end of the function, meaning it is held while `ORPHAN_DIR_SYSTEM_INODE` is acquired.
**3. `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`**
In `ocfs2_wipe_inode()` (`fs/ocfs2/inode.c`), the `ORPHAN_DIR_SYSTEM_INODE` lock is acquired first to prevent races with recovery completion. While holding this lock, it calls `ocfs2_remove_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock to free the inode. (A similar dependency is also established in `ocfs2_prep_new_orphaned_file()`).
Combining these three paths creates the circular dependency:
`INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`.
### How to Fix
We can break the cycle by addressing the second dependency (`EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`) in `ocfs2_dio_end_io_write()`.
The `data_ac` and `meta_ac` allocation contexts are only needed for the transaction that marks the extents as written. Once the transaction is committed via `ocfs2_commit_trans()` and the allocation semaphore is released via `up_write(&oi->ip_alloc_sem)`, these contexts are no longer needed. We can safely free them (which releases the `EXTENT_ALLOC_SYSTEM_INODE` lock) *before* calling `ocfs2_del_inode_from_orphan()`.
Here is the proposed fix for `fs/ocfs2/aops.c`:
```c
@@ -2372,6 +2372,16 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2393,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
```
This ensures that the `EXTENT_ALLOC_SYSTEM_INODE` lock is dropped before we attempt to acquire the `ORPHAN_DIR_SYSTEM_INODE` lock, successfully breaking the circular dependency.
|
| 8/2 |
2026/05/29 16:52 |
llm |
debugger |
0m
Model:
Tokens:
input: 16374
output: 37
thoughts: 1589
Thoughts: **Analyzing a Circular Locking Dependency in OCFS2**
Okay, so I'm looking at this circular locking dependency warning in `ocfs2`. The report points out a potential deadlock scenario involving three locks: `INODE_ALLOC_SYSTEM_INODE`, `ORPHAN_DIR_SYSTEM_INODE`, and `EXTENT_ALLOC_SYSTEM_INODE`. The report suggests a chain of dependencies: `INODE_ALLOC_SYSTEM_INODE` depends on `EXTENT_ALLOC_SYSTEM_INODE`, which depends on `ORPHAN_DIR_SYSTEM_INODE`.
The provided example shows a possible unsafe locking sequence: one CPU holds `ORPHAN_DIR_SYSTEM_INODE` and attempts to acquire `INODE_ALLOC_SYSTEM_INODE`, while another CPU holds `EXTENT_ALLOC_SYSTEM_INODE` and tries to acquire `ORPHAN_DIR_SYSTEM_INODE`. That's a classic deadlock situation, if the locks are acquired in this order and one process can block waiting for the others.
The report highlights that the task that's trying to acquire the `INODE_ALLOC_SYSTEM_INODE` lock is actually already holding the `ORPHAN_DIR_SYSTEM_INODE` lock. Specifically, this happens within the `ocfs2_wipe_inode` function, suggesting that this function is where the potential for a circular dependency lies. It looks like `ocfs2_wipe_inode` acquires `ORPHAN_DIR_SYSTEM_INODE` and *then* tries to get `INODE_ALLOC_SYSTEM_INODE`.
Let's trace back. The given chain indicates `ocfs2_dio_end_io_write` calls `ocfs2_del_inode_from_orphan`, and, ultimately, it's holding the `ORPHAN_DIR_SYSTEM_INODE` lock in this chain.
Now, what lock does `ocfs2_dio_end_io_write` hold before acquiring `ORPHAN_DIR_SYSTEM_INODE`? This is the crucial missing piece. The provided dependency chain shows a crucial lock-holding before `ORPHAN_DIR_SYSTEM_INODE` which is `EXTENT_ALLOC_SYSTEM_INODE`. Specifically, the path is through `ocfs2_reserve_suballoc_bits`, and then through `ocfs2_mknod` which calls it.
So, in the critical path, `ocfs2_mknod` is what's acquiring `EXTENT_ALLOC_SYSTEM_INODE`. We need to verify that `ocfs2_mknod` *does* indeed acquire this lock. This is important: that means `ocfs2_mknod` is the point where the `EXTENT_ALLOC_SYSTEM_INODE` lock gets involved in the dependency. This is where I need to dig deeper and confirm the locking order within `ocfs2_mknod` and the functions it calls, specifically `ocfs2_reserve_new_metadata_blocks` which is from the dependency chain. I need to understand if there is a problem with the lock acquisition order.
|
| 9/2 |
2026/05/29 16:52 |
tool |
grepper |
0m
Args: map[Expression:ocfs2_reserve_new_metadata_blocks PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/alloc.c=5672=static int ocfs2_reserve_blocks_for_rec_trunc(struct inode *inode,
--
fs/ocfs2/alloc.c-5695- if (extra_blocks) {
fs/ocfs2/alloc.c:5696: ret = ocfs2_reserve_new_metadata_blocks(osb, extra_blocks, ac);
fs/ocfs2/alloc.c-5697- if (ret < 0) {
--
fs/ocfs2/dir.c=2824=static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
--
fs/ocfs2/dir.c-2871- /* This gets us the dx_root */
fs/ocfs2/dir.c:2872: ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &meta_ac);
fs/ocfs2/dir.c-2873- if (ret) {
--
fs/ocfs2/move_extents.c=149=static int ocfs2_lock_meta_allocator_move_extents(struct inode *inode,
--
fs/ocfs2/move_extents.c-171-
fs/ocfs2/move_extents.c:172: ret = ocfs2_reserve_new_metadata_blocks(osb, extra_blocks, meta_ac);
fs/ocfs2/move_extents.c-173- if (ret) {
--
fs/ocfs2/namei.c=230=static int ocfs2_mknod(struct mnt_idmap *idmap,
--
fs/ocfs2/namei.c-350-
fs/ocfs2/namei.c:351: status = ocfs2_reserve_new_metadata_blocks(osb, want_meta, &meta_ac);
fs/ocfs2/namei.c-352- if (status < 0) {
--
fs/ocfs2/refcounttree.c=550=static int ocfs2_create_refcount_tree(struct inode *inode,
--
fs/ocfs2/refcounttree.c-570-
fs/ocfs2/refcounttree.c:571: ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &meta_ac);
fs/ocfs2/refcounttree.c-572- if (ret) {
--
fs/ocfs2/refcounttree.c=2830=static int ocfs2_lock_refcount_allocators(struct super_block *sb,
--
fs/ocfs2/refcounttree.c-2862- trace_ocfs2_lock_refcount_allocators(meta_add, *credits);
fs/ocfs2/refcounttree.c:2863: ret = ocfs2_reserve_new_metadata_blocks(OCFS2_SB(sb), meta_add,
fs/ocfs2/refcounttree.c-2864- meta_ac);
--
fs/ocfs2/refcounttree.c=3645=int ocfs2_add_refcount_flag(struct inode *inode,
--
fs/ocfs2/refcounttree.c-3673- if (ref_blocks) {
fs/ocfs2/refcounttree.c:3674: ret = ocfs2_reserve_new_metadata_blocks(osb,
fs/ocfs2/refcounttree.c-3675- ref_blocks, &meta_ac);
--
fs/ocfs2/suballoc.c=1049=static int ocfs2_steal_meta(struct ocfs2_super *osb,
--
fs/ocfs2/suballoc.c-1054-
fs/ocfs2/suballoc.c:1055:int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb,
fs/ocfs2/suballoc.c-1056- int blocks,
--
fs/ocfs2/suballoc.c=1117=int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
--
fs/ocfs2/suballoc.c-1120-{
fs/ocfs2/suballoc.c:1121: return ocfs2_reserve_new_metadata_blocks(osb,
fs/ocfs2/suballoc.c-1122- ocfs2_extend_meta_needed(root_el),
--
fs/ocfs2/suballoc.h=62=int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
--
fs/ocfs2/suballoc.h-64- struct ocfs2_alloc_context **ac);
fs/ocfs2/suballoc.h:65:int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb,
fs/ocfs2/suballoc.h-66- int blocks,
--
fs/ocfs2/xattr.c=576=int ocfs2_calc_security_init(struct inode *dir,
--
fs/ocfs2/xattr.c-593- s_size > OCFS2_XATTR_FREE_IN_IBODY) {
fs/ocfs2/xattr.c:594: ret = ocfs2_reserve_new_metadata_blocks(osb, 1, xattr_ac);
fs/ocfs2/xattr.c-595- if (ret) {
--
fs/ocfs2/xattr.c=2354=static int ocfs2_lock_xattr_remove_allocators(struct inode *inode,
--
fs/ocfs2/xattr.c-2385-
fs/ocfs2/xattr.c:2386: ret = ocfs2_reserve_new_metadata_blocks(OCFS2_SB(inode->i_sb),
fs/ocfs2/xattr.c-2387- meta_add, meta_ac);
--
fs/ocfs2/xattr.c=3280=static int ocfs2_init_xattr_set_ctxt(struct inode *inode,
--
fs/ocfs2/xattr.c-3307- if (meta_add) {
fs/ocfs2/xattr.c:3308: ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add,
fs/ocfs2/xattr.c-3309- &ctxt->meta_ac);
--
fs/ocfs2/xattr.c=6306=static int ocfs2_reflink_lock_xattr_allocators(struct ocfs2_super *osb,
--
fs/ocfs2/xattr.c-6342-
fs/ocfs2/xattr.c:6343: ret = ocfs2_reserve_new_metadata_blocks(osb, meta_add, meta_ac);
fs/ocfs2/xattr.c-6344- if (ret)
--
fs/ocfs2/xattr.c=6565=static int ocfs2_create_empty_xattr_block(struct inode *inode,
--
fs/ocfs2/xattr.c-6574- memset(&ctxt, 0, sizeof(ctxt));
fs/ocfs2/xattr.c:6575: ret = ocfs2_reserve_new_metadata_blocks(osb, 1, &ctxt.meta_ac);
fs/ocfs2/xattr.c-6576- if (ret < 0) {
--
fs/ocfs2/xattr.c=6766=static int ocfs2_lock_reflink_xattr_rec_allocators(
--
fs/ocfs2/xattr.c-6827- if (metas.num_metas) {
fs/ocfs2/xattr.c:6828: ret = ocfs2_reserve_new_metadata_blocks(osb, metas.num_metas,
fs/ocfs2/xattr.c-6829- meta_ac);
]
|
| 10/2 |
2026/05/29 16:52 |
llm |
debugger |
0m
Model:
Tokens:
input: 20784
output: 39
thoughts: 26
Thoughts: Here's my take on the thought process, as if it were my own:
**Diving into the `ocfs2_mknod` Implementation**
Okay, time to get down to brass tacks. I need to understand what's happening with file creation in the OCFS2 filesystem. Let's start with the `ocfs2_mknod` function. That seems like the logical place to start - creating a new node, hence the "mknod". I'll locate it within `fs/ocfs2/namei.c`. Hopefully, the implementation in this file provides the relevant insights for understanding the creation of various node types, covering device nodes, regular files, etc., within the OCFS2 framework. Time to see what's what.
|
| 11/2 |
2026/05/29 16:52 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/namei.c FirstLine:340 LineCount:100]
Results: map[Contents: 340: }
341:
342: /* Reserve a cluster if creating an extent based directory. */
343: if (S_ISDIR(mode) && !ocfs2_supports_inline_data(osb)) {
344: want_clusters += 1;
345:
346: /* Dir indexing requires extra space as well */
347: if (ocfs2_supports_indexed_dirs(osb))
348: want_meta++;
349: }
350:
351: status = ocfs2_reserve_new_metadata_blocks(osb, want_meta, &meta_ac);
352: if (status < 0) {
353: if (status != -ENOSPC)
354: mlog_errno(status);
355: goto leave;
356: }
357:
358: status = ocfs2_reserve_clusters(osb, want_clusters, &data_ac);
359: if (status < 0) {
360: if (status != -ENOSPC)
361: mlog_errno(status);
362: goto leave;
363: }
364:
365: handle = ocfs2_start_trans(osb, ocfs2_mknod_credits(osb->sb,
366: S_ISDIR(mode),
367: xattr_credits));
368: if (IS_ERR(handle)) {
369: status = PTR_ERR(handle);
370: handle = NULL;
371: mlog_errno(status);
372: goto leave;
373: }
374:
375: /* Starting to change things, restart is no longer possible. */
376: ocfs2_block_signals(&oldset);
377: did_block_signals = 1;
378:
379: status = dquot_alloc_inode(inode);
380: if (status)
381: goto leave;
382: did_quota_inode = 1;
383:
384: /* do the real work now. */
385: status = ocfs2_mknod_locked(osb, dir, inode, dev,
386: &new_fe_bh, parent_fe_bh, handle,
387: inode_ac);
388: if (status < 0) {
389: mlog_errno(status);
390: goto leave;
391: }
392:
393: fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
394: if (S_ISDIR(mode)) {
395: status = ocfs2_fill_new_dir(osb, handle, dir, inode,
396: new_fe_bh, data_ac, meta_ac);
397: if (status < 0) {
398: mlog_errno(status);
399: goto leave;
400: }
401:
402: status = ocfs2_journal_access_di(handle, INODE_CACHE(dir),
403: parent_fe_bh,
404: OCFS2_JOURNAL_ACCESS_WRITE);
405: if (status < 0) {
406: mlog_errno(status);
407: goto leave;
408: }
409: ocfs2_add_links_count(dirfe, 1);
410: ocfs2_journal_dirty(handle, parent_fe_bh);
411: inc_nlink(dir);
412: }
413:
414: status = ocfs2_init_acl(handle, inode, dir, new_fe_bh, parent_fe_bh,
415: meta_ac, data_ac);
416:
417: if (status < 0) {
418: mlog_errno(status);
419: goto roll_back;
420: }
421:
422: if (si.enable) {
423: status = ocfs2_init_security_set(handle, inode, new_fe_bh, &si,
424: meta_ac, data_ac);
425: if (status < 0) {
426: mlog_errno(status);
427: goto roll_back;
428: }
429: }
430:
431: /*
432: * Do this before adding the entry to the directory. We add
433: * also set d_op after success so that ->d_iput() will cleanup
434: * the dentry lock even if ocfs2_add_entry() fails below.
435: */
436: status = ocfs2_dentry_attach_lock(dentry, inode,
437: OCFS2_I(dir)->ip_blkno);
438: if (status) {
439: mlog_errno(status);
]
|
| 12/2 |
2026/05/29 16:52 |
llm |
debugger |
0m
Model:
Tokens:
input: 22508
output: 39
thoughts: 53
Thoughts: Here's my take on the thought process, as requested:
**Examining `ocfs2_mknod`'s Allocation Order**
Okay, hold on a second. I'm just reviewing the `ocfs2_mknod` function, and something's pinging my radar. Did I just read that right? It looks like `ocfs2_mknod` acquires the `INODE_ALLOC_SYSTEM_INODE` lock *before* grabbing the `EXTENT_ALLOC_SYSTEM_INODE` lock. That seems a bit...unconventional, doesn't it? Generally, you'd think allocation order would flow from the broader resource (extents) to the more specific (inodes), but perhaps there's a good reason for this. Let's dig into the start of the function and refresh my memory on the control flow. Gotta be sure I'm not missing something in my mental model of OCFS2's locking strategy.
|
| 13/2 |
2026/05/29 16:53 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/namei.c FirstLine:230 LineCount:100]
Results: map[Contents: 230: static int ocfs2_mknod(struct mnt_idmap *idmap,
231: struct inode *dir,
232: struct dentry *dentry,
233: umode_t mode,
234: dev_t dev)
235: {
236: int status = 0;
237: struct buffer_head *parent_fe_bh = NULL;
238: handle_t *handle = NULL;
239: struct ocfs2_super *osb;
240: struct ocfs2_dinode *dirfe;
241: struct ocfs2_dinode *fe = NULL;
242: struct buffer_head *new_fe_bh = NULL;
243: struct inode *inode = NULL;
244: struct ocfs2_alloc_context *inode_ac = NULL;
245: struct ocfs2_alloc_context *data_ac = NULL;
246: struct ocfs2_alloc_context *meta_ac = NULL;
247: int want_clusters = 0;
248: int want_meta = 0;
249: int xattr_credits = 0;
250: struct ocfs2_security_xattr_info si = {
251: .name = NULL,
252: .enable = 1,
253: };
254: int did_quota_inode = 0;
255: struct ocfs2_dir_lookup_result lookup = { NULL, };
256: sigset_t oldset;
257: int did_block_signals = 0;
258: struct ocfs2_dentry_lock *dl = NULL;
259:
260: trace_ocfs2_mknod(dir, dentry, dentry->d_name.len, dentry->d_name.name,
261: (unsigned long long)OCFS2_I(dir)->ip_blkno,
262: (unsigned long)dev, mode);
263:
264: status = dquot_initialize(dir);
265: if (status) {
266: mlog_errno(status);
267: return status;
268: }
269:
270: /* get our super block */
271: osb = OCFS2_SB(dir->i_sb);
272:
273: status = ocfs2_inode_lock(dir, &parent_fe_bh, 1);
274: if (status < 0) {
275: if (status != -ENOENT)
276: mlog_errno(status);
277: return status;
278: }
279:
280: if (S_ISDIR(mode) && (dir->i_nlink >= ocfs2_link_max(osb))) {
281: status = -EMLINK;
282: goto leave;
283: }
284:
285: dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
286: if (!ocfs2_read_links_count(dirfe)) {
287: /* can't make a file in a deleted directory. */
288: status = -ENOENT;
289: goto leave;
290: }
291:
292: status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
293: dentry->d_name.len);
294: if (status)
295: goto leave;
296:
297: /* get a spot inside the dir. */
298: status = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
299: dentry->d_name.name,
300: dentry->d_name.len, &lookup);
301: if (status < 0) {
302: mlog_errno(status);
303: goto leave;
304: }
305:
306: /* reserve an inode spot */
307: status = ocfs2_reserve_new_inode(osb, &inode_ac);
308: if (status < 0) {
309: if (status != -ENOSPC)
310: mlog_errno(status);
311: goto leave;
312: }
313:
314: inode = ocfs2_get_init_inode(dir, mode);
315: if (IS_ERR(inode)) {
316: status = PTR_ERR(inode);
317: inode = NULL;
318: mlog_errno(status);
319: goto leave;
320: }
321:
322: /* get security xattr */
323: status = ocfs2_init_security_get(inode, dir, &dentry->d_name, &si);
324: if (status) {
325: if (status == -EOPNOTSUPP)
326: si.enable = 0;
327: else {
328: mlog_errno(status);
329: goto leave;
]
|
| 14/2 |
2026/05/29 16:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 24348
output: 35
thoughts: 41
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Diving into Inode Allocation**
Right, so `ocfs2_reserve_new_inode` is kicking off the inode allocation process. The first thing that jumps out is that it grabs the `INODE_ALLOC_SYSTEM_INODE` lock. Naturally, my next thought is to go straight to `ocfs2_reserve_new_inode` and see exactly what's going on under the hood, I need to understand the specifics of this reservation. What's the context? What exactly does it entail? Is this the right place? I need more information to know for sure.
|
| 15/2 |
2026/05/29 16:53 |
tool |
grepper |
0m
Args: map[Expression:ocfs2_reserve_new_inode PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/namei.c=230=static int ocfs2_mknod(struct mnt_idmap *idmap,
--
fs/ocfs2/namei.c-306- /* reserve an inode spot */
fs/ocfs2/namei.c:307: status = ocfs2_reserve_new_inode(osb, &inode_ac);
fs/ocfs2/namei.c-308- if (status < 0) {
--
fs/ocfs2/namei.c=1807=static int ocfs2_symlink(struct mnt_idmap *idmap,
--
fs/ocfs2/namei.c-1880-
fs/ocfs2/namei.c:1881: status = ocfs2_reserve_new_inode(osb, &inode_ac);
fs/ocfs2/namei.c-1882- if (status < 0) {
--
fs/ocfs2/namei.c=2445=static int ocfs2_prep_new_orphaned_file(struct inode *dir,
--
fs/ocfs2/namei.c-2466- /* reserve an inode spot */
fs/ocfs2/namei.c:2467: ret = ocfs2_reserve_new_inode(osb, &inode_ac);
fs/ocfs2/namei.c-2468- if (ret < 0) {
--
fs/ocfs2/ocfs2_trace.h=790=DEFINE_OCFS2_UINT_UINT_UINT_EVENT(ocfs2_reserve_suballoc_bits_no_new_group);
fs/ocfs2/ocfs2_trace.h-791-
fs/ocfs2/ocfs2_trace.h:792:DEFINE_OCFS2_ULL_EVENT(ocfs2_reserve_new_inode_new_group);
fs/ocfs2/ocfs2_trace.h-793-
--
fs/ocfs2/suballoc.c=1117=int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
--
fs/ocfs2/suballoc.c-1125-
fs/ocfs2/suballoc.c:1126:int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
fs/ocfs2/suballoc.c-1127- struct ocfs2_alloc_context **ac)
--
fs/ocfs2/suballoc.c-1179- spin_unlock(&osb->osb_lock);
fs/ocfs2/suballoc.c:1180: trace_ocfs2_reserve_new_inode_new_group(
fs/ocfs2/suballoc.c-1181- (unsigned long long)alloc_group);
--
fs/ocfs2/suballoc.h=65=int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb,
--
fs/ocfs2/suballoc.h-67- struct ocfs2_alloc_context **ac);
fs/ocfs2/suballoc.h:68:int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
fs/ocfs2/suballoc.h-69- struct ocfs2_alloc_context **ac);
]
|
| 16/2 |
2026/05/29 16:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 25442
output: 40
thoughts: 28
Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:
**Analyzing the Inode Reservation Process in OCFS2**
Alright, time to get my hands dirty. I'm going to take a look at the `ocfs2_reserve_new_inode` function. Specifically, I'm finding this in the `fs/ocfs2/suballoc.c` file. I need to refresh my memory on how OCFS2 handles inode allocation and this seems like the key function to dissect. I'm expecting this function will be the gatekeeper, managing the reservation of a fresh inode in the OCFS2 filesystem. Let's see what the code has to say about the intricacies of block allocation, bitmap manipulation, and potential contention during the inode creation process. I'll be particularly interested in the strategies employed to avoid fragmentation and ensure efficient use of disk space. This is where the magic (or the bugs!) typically live when it comes to filesystem design, so I'm keen to get a solid grasp of this function's logic.
|
| 17/2 |
2026/05/29 16:53 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/suballoc.c FirstLine:1126 LineCount:100]
Results: map[Contents:1126: int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
1127: struct ocfs2_alloc_context **ac)
1128: {
1129: int status;
1130: int slot = ocfs2_get_inode_steal_slot(osb);
1131: u64 alloc_group;
1132:
1133: *ac = kzalloc_obj(struct ocfs2_alloc_context);
1134: if (!(*ac)) {
1135: status = -ENOMEM;
1136: mlog_errno(status);
1137: goto bail;
1138: }
1139:
1140: (*ac)->ac_bits_wanted = 1;
1141: (*ac)->ac_which = OCFS2_AC_USE_INODE;
1142:
1143: (*ac)->ac_group_search = ocfs2_block_group_search;
1144:
1145: /*
1146: * stat(2) can't handle i_ino > 32bits, so we tell the
1147: * lower levels not to allocate us a block group past that
1148: * limit. The 'inode64' mount option avoids this behavior.
1149: */
1150: if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64))
1151: (*ac)->ac_max_block = (u32)~0U;
1152:
1153: /*
1154: * slot is set when we successfully steal inode from other nodes.
1155: * It is reset in 3 places:
1156: * 1. when we flush the truncate log
1157: * 2. when we complete local alloc recovery.
1158: * 3. when we successfully allocate from our own slot.
1159: * After it is set, we will go on stealing inodes until we find the
1160: * need to check our slots to see whether there is some space for us.
1161: */
1162: if (slot != OCFS2_INVALID_SLOT &&
1163: atomic_read(&osb->s_num_inodes_stolen) < OCFS2_MAX_TO_STEAL)
1164: goto inode_steal;
1165:
1166: atomic_set(&osb->s_num_inodes_stolen, 0);
1167: alloc_group = osb->osb_inode_alloc_group;
1168: status = ocfs2_reserve_suballoc_bits(osb, *ac,
1169: INODE_ALLOC_SYSTEM_INODE,
1170: (u32)osb->slot_num,
1171: &alloc_group,
1172: ALLOC_NEW_GROUP |
1173: ALLOC_GROUPS_FROM_GLOBAL);
1174: if (status >= 0) {
1175: status = 0;
1176:
1177: spin_lock(&osb->osb_lock);
1178: osb->osb_inode_alloc_group = alloc_group;
1179: spin_unlock(&osb->osb_lock);
1180: trace_ocfs2_reserve_new_inode_new_group(
1181: (unsigned long long)alloc_group);
1182:
1183: /*
1184: * Some inodes must be freed by us, so try to allocate
1185: * from our own next time.
1186: */
1187: if (slot != OCFS2_INVALID_SLOT)
1188: ocfs2_init_inode_steal_slot(osb);
1189: goto bail;
1190: } else if (status < 0 && status != -ENOSPC) {
1191: mlog_errno(status);
1192: goto bail;
1193: }
1194:
1195: ocfs2_free_ac_resource(*ac);
1196:
1197: inode_steal:
1198: status = ocfs2_steal_inode(osb, *ac);
1199: atomic_inc(&osb->s_num_inodes_stolen);
1200: if (status < 0) {
1201: if (status != -ENOSPC)
1202: mlog_errno(status);
1203: goto bail;
1204: }
1205:
1206: status = 0;
1207: bail:
1208: if ((status < 0) && *ac) {
1209: ocfs2_free_alloc_context(*ac);
1210: *ac = NULL;
1211: }
1212:
1213: if (status)
1214: mlog_errno(status);
1215: return status;
1216: }
1217:
1218: /* local alloc code has to do the same thing, so rather than do this
1219: * twice.. */
1220: int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb,
1221: struct ocfs2_alloc_context *ac)
1222: {
1223: int status;
1224:
1225: ac->ac_which = OCFS2_AC_USE_MAIN;
]
|
| 18/2 |
2026/05/29 16:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 27308
output: 39
thoughts: 244
Thoughts: **Analyzing OCFS2 Inode and Metadata Allocation**
Okay, so I'm digging into how OCFS2 handles inode and metadata allocation, specifically around `ocfs2_reserve_new_inode` and `ocfs2_reserve_new_metadata_blocks`. It looks like `ocfs2_reserve_new_inode` ultimately calls `ocfs2_reserve_suballoc_bits` with `INODE_ALLOC_SYSTEM_INODE`, and `ocfs2_reserve_new_metadata_blocks` does the same, but with `EXTENT_ALLOC_SYSTEM_INODE`.
The code snippet in `ocfs2_mknod` is interesting. It clearly shows `ocfs2_reserve_new_inode` being called *before* `ocfs2_reserve_new_metadata_blocks`. That's a key sequencing point to consider. Now, my immediate thought is about the locking strategy in `ocfs2_reserve_suballoc_bits`. Does it acquire the lock and then release it, or does it hold onto it? This is crucial for understanding concurrency and potential contention during allocation. I really need to check the source code for `ocfs2_reserve_suballoc_bits` to verify the lock behavior and clarify the interaction between inode and metadata reservation. Let's see how that works.
|
| 19/2 |
2026/05/29 16:53 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/suballoc.c FirstLine:880 LineCount:100]
Results: map[Contents: 880: }
881:
882: inode_lock(alloc_inode);
883:
884: status = ocfs2_inode_lock(alloc_inode, &bh, 1);
885: if (status < 0) {
886: inode_unlock(alloc_inode);
887: iput(alloc_inode);
888:
889: mlog_errno(status);
890: return status;
891: }
892:
893: ac->ac_inode = alloc_inode;
894: ac->ac_alloc_slot = slot;
895:
896: fe = (struct ocfs2_dinode *) bh->b_data;
897:
898: /* The bh was validated by the inode read inside
899: * ocfs2_inode_lock(). Any corruption is a code bug. */
900: BUG_ON(!OCFS2_IS_VALID_DINODE(fe));
901:
902: if (!(fe->i_flags & cpu_to_le32(OCFS2_CHAIN_FL))) {
903: status = ocfs2_error(alloc_inode->i_sb,
904: "Invalid chain allocator %llu\n",
905: (unsigned long long)le64_to_cpu(fe->i_blkno));
906: goto bail;
907: }
908:
909: free_bits = le32_to_cpu(fe->id1.bitmap1.i_total) -
910: le32_to_cpu(fe->id1.bitmap1.i_used);
911:
912: if (bits_wanted > free_bits) {
913: /* cluster bitmap never grows */
914: if (ocfs2_is_cluster_bitmap(alloc_inode)) {
915: trace_ocfs2_reserve_suballoc_bits_nospc(bits_wanted,
916: free_bits);
917: status = -ENOSPC;
918: goto bail;
919: }
920:
921: if (!(flags & ALLOC_NEW_GROUP)) {
922: trace_ocfs2_reserve_suballoc_bits_no_new_group(
923: slot, bits_wanted, free_bits);
924: status = -ENOSPC;
925: goto bail;
926: }
927:
928: status = ocfs2_block_group_alloc(osb, alloc_inode, bh,
929: ac->ac_max_block,
930: last_alloc_group, flags);
931: if (status < 0) {
932: if (status != -ENOSPC)
933: mlog_errno(status);
934: goto bail;
935: }
936: atomic_inc(&osb->alloc_stats.bg_extends);
937:
938: /* You should never ask for this much metadata */
939: BUG_ON(bits_wanted >
940: (le32_to_cpu(fe->id1.bitmap1.i_total)
941: - le32_to_cpu(fe->id1.bitmap1.i_used)));
942: }
943:
944: get_bh(bh);
945: ac->ac_bh = bh;
946: bail:
947: brelse(bh);
948:
949: if (status)
950: mlog_errno(status);
951: return status;
952: }
953:
954: static void ocfs2_init_inode_steal_slot(struct ocfs2_super *osb)
955: {
956: spin_lock(&osb->osb_lock);
957: osb->s_inode_steal_slot = OCFS2_INVALID_SLOT;
958: spin_unlock(&osb->osb_lock);
959: atomic_set(&osb->s_num_inodes_stolen, 0);
960: }
961:
962: static void ocfs2_init_meta_steal_slot(struct ocfs2_super *osb)
963: {
964: spin_lock(&osb->osb_lock);
965: osb->s_meta_steal_slot = OCFS2_INVALID_SLOT;
966: spin_unlock(&osb->osb_lock);
967: atomic_set(&osb->s_num_meta_stolen, 0);
968: }
969:
970: void ocfs2_init_steal_slots(struct ocfs2_super *osb)
971: {
972: ocfs2_init_inode_steal_slot(osb);
973: ocfs2_init_meta_steal_slot(osb);
974: }
975:
976: static void __ocfs2_set_steal_slot(struct ocfs2_super *osb, int slot, int type)
977: {
978: spin_lock(&osb->osb_lock);
979: if (type == INODE_ALLOC_SYSTEM_INODE)
]
|
| 20/2 |
2026/05/29 16:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 29447
output: 39
thoughts: 681
Thoughts: **Analyzing OCFS2 Lock Dependencies in File Write Iterations**
Okay, let's break this down. My initial thought is that `ocfs2_reserve_suballoc_bits` is holding onto locks acquired by calling `inode_lock(alloc_inode)` and `ocfs2_inode_lock(alloc_inode, &bh, 1)`. I see that the context stores `ac->ac_inode = alloc_inode;` and `ac->ac_bh = bh;`, which strongly suggests the locks are held until `ocfs2_free_alloc_context` is invoked. That's good to know for context.
Now, focusing on `ocfs2_mknod`, I see that `ocfs2_reserve_new_inode` acquires the `INODE_ALLOC_SYSTEM_INODE` lock, and `ocfs2_reserve_new_metadata_blocks` subsequently acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. This directly establishes a dependency: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE`. Makes sense.
But the lockdep report⦠it throws a wrench into the works. It says there's a dependency of `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`. I have to track down where `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` is being established.
The report points to `ocfs2_del_inode_from_orphan`, called from `ocfs2_dio_end_io_write`, then `ocfs2_dio_end_io` which itself is called from `ocfs2_file_write_iter`. I need to figure out which lock is being held before `ORPHAN_DIR_SYSTEM_INODE` in `ocfs2_file_write_iter`. I'll have to investigate the code path starting from `ocfs2_file_write_iter` and work backwards to trace the lock acquisition sequence. Time to dig into the source!
|
| 21/2 |
2026/05/29 16:53 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/file.c FirstLine:2450 LineCount:100]
Results: map[Contents:2450: ret = generic_write_checks(iocb, from);
2451: if (ret <= 0) {
2452: if (ret)
2453: mlog_errno(ret);
2454: goto out;
2455: }
2456: count = ret;
2457:
2458: ret = ocfs2_prepare_inode_for_write(file, iocb->ki_pos, count, !nowait);
2459: if (ret < 0) {
2460: if (ret != -EAGAIN)
2461: mlog_errno(ret);
2462: goto out;
2463: }
2464:
2465: if (direct_io && !is_sync_kiocb(iocb) &&
2466: ocfs2_is_io_unaligned(inode, count, iocb->ki_pos)) {
2467: /*
2468: * Make it a sync io if it's an unaligned aio.
2469: */
2470: saved_ki_complete = xchg(&iocb->ki_complete, NULL);
2471: }
2472:
2473: /* communicate with ocfs2_dio_end_io */
2474: ocfs2_iocb_set_rw_locked(iocb, rw_level);
2475:
2476: written = __generic_file_write_iter(iocb, from);
2477: /* buffered aio wouldn't have proper lock coverage today */
2478: BUG_ON(written == -EIOCBQUEUED && !direct_io);
2479:
2480: /*
2481: * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io
2482: * function pointer which is called when o_direct io completes so that
2483: * it can unlock our rw lock.
2484: * Unfortunately there are error cases which call end_io and others
2485: * that don't. so we don't have to unlock the rw_lock if either an
2486: * async dio is going to do it in the future or an end_io after an
2487: * error has already done it.
2488: */
2489: if ((written == -EIOCBQUEUED) || (!ocfs2_iocb_is_rw_locked(iocb))) {
2490: rw_level = -1;
2491: }
2492:
2493: if (unlikely(written <= 0))
2494: goto out;
2495:
2496: if (((file->f_flags & O_DSYNC) && !direct_io) ||
2497: IS_SYNC(inode)) {
2498: ret = filemap_fdatawrite_range(file->f_mapping,
2499: iocb->ki_pos - written,
2500: iocb->ki_pos - 1);
2501: if (ret < 0)
2502: written = ret;
2503:
2504: if (!ret) {
2505: ret = jbd2_journal_force_commit(osb->journal->j_journal);
2506: if (ret < 0)
2507: written = ret;
2508: }
2509:
2510: if (!ret)
2511: ret = filemap_fdatawait_range(file->f_mapping,
2512: iocb->ki_pos - written,
2513: iocb->ki_pos - 1);
2514: }
2515:
2516: out:
2517: if (saved_ki_complete)
2518: xchg(&iocb->ki_complete, saved_ki_complete);
2519:
2520: if (rw_level != -1)
2521: ocfs2_rw_unlock(inode, rw_level);
2522:
2523: out_mutex:
2524: inode_unlock(inode);
2525:
2526: if (written)
2527: ret = written;
2528: return ret;
2529: }
2530:
2531: static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
2532: struct iov_iter *to)
2533: {
2534: int ret = 0, rw_level = -1, lock_level = 0;
2535: struct file *filp = iocb->ki_filp;
2536: struct inode *inode = file_inode(filp);
2537: int direct_io = iocb->ki_flags & IOCB_DIRECT ? 1 : 0;
2538: int nowait = iocb->ki_flags & IOCB_NOWAIT ? 1 : 0;
2539:
2540: trace_ocfs2_file_read_iter(inode, filp, filp->f_path.dentry,
2541: (unsigned long long)OCFS2_I(inode)->ip_blkno,
2542: filp->f_path.dentry->d_name.len,
2543: filp->f_path.dentry->d_name.name,
2544: to->nr_segs); /* GRRRRR */
2545:
2546:
2547: if (!inode) {
2548: ret = -EINVAL;
2549: mlog_errno(ret);
]
|
| 22/2 |
2026/05/29 16:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 32245
output: 39
thoughts: 51
Thoughts: Here's my thought process, as if I were analyzing this code:
**Diving into the Write Iteration**
Okay, so I'm looking at `ocfs2_file_write_iter`, which is the core of how OCFS2 handles file writes. I need to understand this better. Now, a key step in a write operation is often pre-processing, and I suspect `ocfs2_prepare_inode_for_write` is doing some of that heavy lifting. Hmm, that name rings a bell, I wonder if this function is actually acquiring locks before the write happens? If it does, there could be interesting implications for concurrency and potential deadlocks, or just performance generally.
Let me take a look at the code for `ocfs2_prepare_inode_for_write` immediately and see what's going on under the hood. I need to verify that it does, or doesn't, take any locks, and if so, understand which ones and in what order. This is a critical point to ensure the correctness and scalability of the write path. Time to jump into the function definition.
|
| 23/2 |
2026/05/29 16:53 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/file.c FirstLine:2290 LineCount:100]
Results: map[Contents:2290:
2291: ret = ocfs2_overwrite_io(inode, di_bh, pos, count);
2292: if (ret < 0) {
2293: if (ret != -EAGAIN)
2294: mlog_errno(ret);
2295: goto out_unlock;
2296: }
2297: }
2298:
2299: /* Clear suid / sgid if necessary. We do this here
2300: * instead of later in the write path because
2301: * remove_suid() calls ->setattr without any hint that
2302: * we may have already done our cluster locking. Since
2303: * ocfs2_setattr() *must* take cluster locks to
2304: * proceed, this will lead us to recursively lock the
2305: * inode. There's also the dinode i_size state which
2306: * can be lost via setattr during extending writes (we
2307: * set inode->i_size at the end of a write. */
2308: if (setattr_should_drop_suidgid(&nop_mnt_idmap, inode)) {
2309: if (meta_level == 0) {
2310: ocfs2_inode_unlock_for_extent_tree(inode,
2311: &di_bh,
2312: meta_level,
2313: write_sem);
2314: meta_level = 1;
2315: continue;
2316: }
2317:
2318: ret = ocfs2_write_remove_suid(inode);
2319: if (ret < 0) {
2320: mlog_errno(ret);
2321: goto out_unlock;
2322: }
2323: }
2324:
2325: ret = ocfs2_check_range_for_refcount(inode, pos, count);
2326: if (ret == 1) {
2327: ocfs2_inode_unlock_for_extent_tree(inode,
2328: &di_bh,
2329: meta_level,
2330: write_sem);
2331: meta_level = 1;
2332: write_sem = 1;
2333: ret = ocfs2_inode_lock_for_extent_tree(inode,
2334: &di_bh,
2335: meta_level,
2336: write_sem,
2337: wait);
2338: if (ret < 0) {
2339: if (ret != -EAGAIN)
2340: mlog_errno(ret);
2341: goto out;
2342: }
2343:
2344: cpos = pos >> OCFS2_SB(inode->i_sb)->s_clustersize_bits;
2345: clusters =
2346: ocfs2_clusters_for_bytes(inode->i_sb, pos + count) - cpos;
2347: ret = ocfs2_refcount_cow(inode, di_bh, cpos, clusters, UINT_MAX);
2348: }
2349:
2350: if (ret < 0) {
2351: if (ret != -EAGAIN)
2352: mlog_errno(ret);
2353: goto out_unlock;
2354: }
2355:
2356: break;
2357: }
2358:
2359: out_unlock:
2360: trace_ocfs2_prepare_inode_for_write(OCFS2_I(inode)->ip_blkno,
2361: pos, count, wait);
2362:
2363: ocfs2_inode_unlock_for_extent_tree(inode,
2364: &di_bh,
2365: meta_level,
2366: write_sem);
2367:
2368: out:
2369: return ret;
2370: }
2371:
2372: static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
2373: struct iov_iter *from)
2374: {
2375: int rw_level;
2376: ssize_t written = 0;
2377: ssize_t ret;
2378: size_t count = iov_iter_count(from);
2379: struct file *file = iocb->ki_filp;
2380: struct inode *inode = file_inode(file);
2381: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2382: int full_coherency = !(osb->s_mount_opt &
2383: OCFS2_MOUNT_COHERENCY_BUFFERED);
2384: void *saved_ki_complete = NULL;
2385: int append_write = ((iocb->ki_pos + count) >=
2386: i_size_read(inode) ? 1 : 0);
2387: int direct_io = iocb->ki_flags & IOCB_DIRECT ? 1 : 0;
2388: int nowait = iocb->ki_flags & IOCB_NOWAIT ? 1 : 0;
2389:
]
|
| 24/2 |
2026/05/29 16:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 34126
output: 39
thoughts: 48
Thoughts: Okay, let me think this through.
**Analyzing the `ocfs2_file_write_iter` and its Locking Behavior**
Right, so `ocfs2_file_write_iter` is the critical function here for writes, and it calls `ocfs2_rw_lock` β that's the key. Now, where else does `ocfs2_rw_lock` get invoked? I need to understand the full context of how this read-write lock is used within the OCFS2 file system. What are the calling patterns around it, what `rw_level` values are passed and how that impacts concurrency and data integrity? Understanding where else it is used will help me evaluate any possible contention points and ensure that this write path is interacting correctly. I need to trace those calls and build a clear mental model of the locking strategy at play.
|
| 25/2 |
2026/05/29 16:53 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/file.c FirstLine:2390 LineCount:100]
Results: map[Contents:2390: trace_ocfs2_file_write_iter(inode, file, file->f_path.dentry,
2391: (unsigned long long)OCFS2_I(inode)->ip_blkno,
2392: file->f_path.dentry->d_name.len,
2393: file->f_path.dentry->d_name.name,
2394: (unsigned int)from->nr_segs); /* GRRRRR */
2395:
2396: if (!direct_io && nowait)
2397: return -EOPNOTSUPP;
2398:
2399: if (count == 0)
2400: return 0;
2401:
2402: if (nowait) {
2403: if (!inode_trylock(inode))
2404: return -EAGAIN;
2405: } else
2406: inode_lock(inode);
2407:
2408: ocfs2_iocb_init_rw_locked(iocb);
2409:
2410: /*
2411: * Concurrent O_DIRECT writes are allowed with
2412: * mount_option "coherency=buffered".
2413: * For append write, we must take rw EX.
2414: */
2415: rw_level = (!direct_io || full_coherency || append_write);
2416:
2417: if (nowait)
2418: ret = ocfs2_try_rw_lock(inode, rw_level);
2419: else
2420: ret = ocfs2_rw_lock(inode, rw_level);
2421: if (ret < 0) {
2422: if (ret != -EAGAIN)
2423: mlog_errno(ret);
2424: goto out_mutex;
2425: }
2426:
2427: /*
2428: * O_DIRECT writes with "coherency=full" need to take EX cluster
2429: * inode_lock to guarantee coherency.
2430: */
2431: if (direct_io && full_coherency) {
2432: /*
2433: * We need to take and drop the inode lock to force
2434: * other nodes to drop their caches. Buffered I/O
2435: * already does this in write_begin().
2436: */
2437: if (nowait)
2438: ret = ocfs2_try_inode_lock(inode, NULL, 1);
2439: else
2440: ret = ocfs2_inode_lock(inode, NULL, 1);
2441: if (ret < 0) {
2442: if (ret != -EAGAIN)
2443: mlog_errno(ret);
2444: goto out;
2445: }
2446:
2447: ocfs2_inode_unlock(inode, 1);
2448: }
2449:
2450: ret = generic_write_checks(iocb, from);
2451: if (ret <= 0) {
2452: if (ret)
2453: mlog_errno(ret);
2454: goto out;
2455: }
2456: count = ret;
2457:
2458: ret = ocfs2_prepare_inode_for_write(file, iocb->ki_pos, count, !nowait);
2459: if (ret < 0) {
2460: if (ret != -EAGAIN)
2461: mlog_errno(ret);
2462: goto out;
2463: }
2464:
2465: if (direct_io && !is_sync_kiocb(iocb) &&
2466: ocfs2_is_io_unaligned(inode, count, iocb->ki_pos)) {
2467: /*
2468: * Make it a sync io if it's an unaligned aio.
2469: */
2470: saved_ki_complete = xchg(&iocb->ki_complete, NULL);
2471: }
2472:
2473: /* communicate with ocfs2_dio_end_io */
2474: ocfs2_iocb_set_rw_locked(iocb, rw_level);
2475:
2476: written = __generic_file_write_iter(iocb, from);
2477: /* buffered aio wouldn't have proper lock coverage today */
2478: BUG_ON(written == -EIOCBQUEUED && !direct_io);
2479:
2480: /*
2481: * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io
2482: * function pointer which is called when o_direct io completes so that
2483: * it can unlock our rw lock.
2484: * Unfortunately there are error cases which call end_io and others
2485: * that don't. so we don't have to unlock the rw_lock if either an
2486: * async dio is going to do it in the future or an end_io after an
2487: * error has already done it.
2488: */
2489: if ((written == -EIOCBQUEUED) || (!ocfs2_iocb_is_rw_locked(iocb))) {
]
|
| 26/2 |
2026/05/29 16:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 35962
output: 40
thoughts: 252
Thoughts: **My Convoluted Walk Through the OCFS2 Write Path**
Okay, so I'm tracing this write path in OCFS2, starting with `ocfs2_file_write_iter`. First off, I see it takes `inode_lock(inode)` which is using the `i_rwsem`. Then, it immediately calls `ocfs2_rw_lock(inode, rw_level)`. This feels a bit redundant, doesn't it? Let's keep going.
Now it dives into `ocfs2_prepare_inode_for_write`. This looks interesting, because it calls `ocfs2_inode_lock_for_extent_tree`, and this is where it *could* allocate extents. That triggers some alarms. If it *is* allocating extents in this context, shouldn't we be looking for contention around `EXTENT_ALLOC_SYSTEM_INODE`? This is something I'll need to keep an eye on.
So this prepare function then calls either `ocfs2_overwrite_io` or `ocfs2_check_range_for_refcount`. Hmmm... that's where the actual I/O or refcount check takes place. Now, I have another trigger. I'm seeing that `ocfs2_dio_end_io_write` is called from `ocfs2_dio_end_io`, which comes from `dio_complete`. That's the asynchronous completion path for direct I/O.
And here's where it gets really interesting: `ocfs2_dio_end_io_write` calls `ocfs2_del_inode_from_orphan`. Why is orphan cleanup happening in the DIO completion path for *writes*? I need to understand this better. I think I'll dive into `ocfs2_dio_end_io_write` to see exactly what's going on there. I'm expecting something to be amiss, so I want to be certain about the connection.
|
| 27/2 |
2026/05/29 16:54 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/aops.c FirstLine:2360 LineCount:100]
Results: map[Contents:2360: mlog_errno(ret);
2361: goto unlock;
2362: }
2363: }
2364: ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
2365: if (ret < 0)
2366: mlog_errno(ret);
2367: }
2368:
2369: commit:
2370: if (handle)
2371: ocfs2_commit_trans(osb, handle);
2372: unlock:
2373: up_write(&oi->ip_alloc_sem);
2374:
2375: /* everything looks good, let's start the cleanup */
2376: if (!ret && dwc->dw_orphaned) {
2377: BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
2378:
2379: ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2380: if (ret < 0)
2381: mlog_errno(ret);
2382: }
2383: ocfs2_inode_unlock(inode, 1);
2384: brelse(di_bh);
2385: out:
2386: if (data_ac)
2387: ocfs2_free_alloc_context(data_ac);
2388: if (meta_ac)
2389: ocfs2_free_alloc_context(meta_ac);
2390: ocfs2_run_deallocs(osb, &dealloc);
2391: ocfs2_dio_free_write_ctx(inode, dwc);
2392:
2393: return ret;
2394: }
2395:
2396: /*
2397: * ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
2398: * particularly interested in the aio/dio case. We use the rw_lock DLM lock
2399: * to protect io on one node from truncation on another.
2400: */
2401: static int ocfs2_dio_end_io(struct kiocb *iocb,
2402: loff_t offset,
2403: ssize_t bytes,
2404: void *private)
2405: {
2406: struct inode *inode = file_inode(iocb->ki_filp);
2407: int level;
2408: int ret = 0;
2409:
2410: /* this io's submitter should not have unlocked this before we could */
2411: BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
2412:
2413: if (bytes <= 0)
2414: mlog_ratelimited(ML_ERROR, "Direct IO failed, bytes = %lld",
2415: (long long)bytes);
2416: if (private) {
2417: if (bytes > 0)
2418: ret = ocfs2_dio_end_io_write(inode, private, offset,
2419: bytes);
2420: else
2421: ocfs2_dio_free_write_ctx(inode, private);
2422: }
2423:
2424: ocfs2_iocb_clear_rw_locked(iocb);
2425:
2426: level = ocfs2_iocb_rw_locked_level(iocb);
2427: ocfs2_rw_unlock(inode, level);
2428: return ret;
2429: }
2430:
2431: static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
2432: {
2433: struct file *file = iocb->ki_filp;
2434: struct inode *inode = file->f_mapping->host;
2435: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2436: get_block_t *get_block;
2437:
2438: /*
2439: * Fallback to buffered I/O if we see an inode without
2440: * extents.
2441: */
2442: if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
2443: return 0;
2444:
2445: /* Fallback to buffered I/O if we do not support append dio. */
2446: if (iocb->ki_pos + iter->count > i_size_read(inode) &&
2447: !ocfs2_supports_append_dio(osb))
2448: return 0;
2449:
2450: if (iov_iter_rw(iter) == READ)
2451: get_block = ocfs2_lock_get_block;
2452: else
2453: get_block = ocfs2_dio_wr_get_block;
2454:
2455: return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
2456: iter, get_block,
2457: ocfs2_dio_end_io, 0);
2458: }
2459:
]
|
| 28/2 |
2026/05/29 16:54 |
llm |
debugger |
0m
Model:
Tokens:
input: 38260
output: 40
thoughts: 62
Thoughts: Okay, here's my interpretation of this code flow, from a perspective of analyzing its behavior:
**Diving into the `ocfs2_dio_end_io_write` Function**
Alright, so I'm tracing this `ocfs2_dio_end_io_write` function. The call stack just indicated that it's calling `ocfs2_del_inode_from_orphan` directly. I need to understand what that function does in this specific context. I immediately recognize that `osb`, `inode`, and `di_bh` are passed to the function, along with `0, 0` for some flags, which are probably related to the deletion or processing of the inode. Let me dig into the details of the `ocfs2_del_inode_from_orphan` function now; I need to figure out what it's contributing at this point of the write cycle. That's the key to understanding this particular step.
|
| 29/2 |
2026/05/29 16:54 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/namei.c FirstLine:2720 LineCount:100]
Results: map[Contents:2720: ORPHAN_DIR_SYSTEM_INODE,
2721: le16_to_cpu(di->i_dio_orphaned_slot));
2722: if (!orphan_dir_inode) {
2723: status = -ENOENT;
2724: mlog_errno(status);
2725: goto bail;
2726: }
2727:
2728: inode_lock(orphan_dir_inode);
2729: status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
2730: if (status < 0) {
2731: inode_unlock(orphan_dir_inode);
2732: iput(orphan_dir_inode);
2733: mlog_errno(status);
2734: goto bail;
2735: }
2736:
2737: handle = ocfs2_start_trans(osb,
2738: OCFS2_INODE_DEL_FROM_ORPHAN_CREDITS);
2739: if (IS_ERR(handle)) {
2740: status = PTR_ERR(handle);
2741: goto bail_unlock_orphan;
2742: }
2743:
2744: BUG_ON(!(di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL)));
2745:
2746: status = ocfs2_orphan_del(osb, handle, orphan_dir_inode,
2747: inode, orphan_dir_bh, true);
2748: if (status < 0) {
2749: mlog_errno(status);
2750: goto bail_commit;
2751: }
2752:
2753: status = ocfs2_journal_access_di(handle,
2754: INODE_CACHE(inode),
2755: di_bh,
2756: OCFS2_JOURNAL_ACCESS_WRITE);
2757: if (status < 0) {
2758: mlog_errno(status);
2759: goto bail_commit;
2760: }
2761:
2762: di->i_flags &= ~cpu_to_le32(OCFS2_DIO_ORPHANED_FL);
2763: di->i_dio_orphaned_slot = 0;
2764:
2765: if (update_isize) {
2766: status = ocfs2_set_inode_size(handle, inode, di_bh, end);
2767: if (status)
2768: mlog_errno(status);
2769: } else
2770: ocfs2_journal_dirty(handle, di_bh);
2771:
2772: bail_commit:
2773: ocfs2_commit_trans(osb, handle);
2774:
2775: bail_unlock_orphan:
2776: ocfs2_inode_unlock(orphan_dir_inode, 1);
2777: inode_unlock(orphan_dir_inode);
2778: brelse(orphan_dir_bh);
2779: iput(orphan_dir_inode);
2780:
2781: bail:
2782: return status;
2783: }
2784:
2785: int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
2786: struct inode *inode,
2787: struct dentry *dentry)
2788: {
2789: int status = 0;
2790: struct buffer_head *parent_di_bh = NULL;
2791: handle_t *handle = NULL;
2792: struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
2793: struct ocfs2_dinode *dir_di, *di;
2794: struct inode *orphan_dir_inode = NULL;
2795: struct buffer_head *orphan_dir_bh = NULL;
2796: struct buffer_head *di_bh = NULL;
2797: struct ocfs2_dir_lookup_result lookup = { NULL, };
2798:
2799: trace_ocfs2_mv_orphaned_inode_to_new(dir, dentry,
2800: dentry->d_name.len, dentry->d_name.name,
2801: (unsigned long long)OCFS2_I(dir)->ip_blkno,
2802: (unsigned long long)OCFS2_I(inode)->ip_blkno);
2803:
2804: status = ocfs2_inode_lock(dir, &parent_di_bh, 1);
2805: if (status < 0) {
2806: if (status != -ENOENT)
2807: mlog_errno(status);
2808: return status;
2809: }
2810:
2811: dir_di = (struct ocfs2_dinode *) parent_di_bh->b_data;
2812: if (!dir_di->i_links_count) {
2813: /* can't make a file in a deleted directory. */
2814: status = -ENOENT;
2815: goto leave;
2816: }
2817:
2818: status = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
2819: dentry->d_name.len);
]
|
| 30/2 |
2026/05/29 16:54 |
llm |
debugger |
0m
Model:
Tokens:
input: 40152
output: 40
thoughts: 2789
Thoughts: **Locking Hierarchy in OCFS2: A Deep Dive into System Inode Dependencies**
Okay, so I'm digging into this lock dependency issue within the OCFS2 code. It looks like we've got a potential lock order reversal or, at the very least, a complex locking pattern emerging. Specifically, I'm focusing on how `EXTENT_ALLOC_SYSTEM_INODE` and `ORPHAN_DIR_SYSTEM_INODE` interact, and how this relates to a write operation, in conjunction with `INODE_ALLOC_SYSTEM_INODE`.
Initially, I see `ocfs2_del_inode_from_orphan` grabbing `ORPHAN_DIR_SYSTEM_INODE`, and I'm trying to figure out how `EXTENT_ALLOC_SYSTEM_INODE` comes into play at this stage, particularly since it seems to be involved with the DIO path somehow. I started tracing the call stack from `ocfs2_dio_end_io_write` backward, eventually hitting `ocfs2_file_write_iter`. Within that, I see `ocfs2_prepare_inode_for_write` which actually *releases* `EXTENT_ALLOC_SYSTEM_INODE`, which initially made things confusing. The lockdep report shows `EXTENT_ALLOC_SYSTEM_INODE` is acquired inside `ocfs2_mknod`.
Then I see these lockdep reports, specifically this chain: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`. Where is this chain established?
It *seems* like the lockdep report is showing the dependencies in reverse order, which is a key realization here. I confirmed that the chain is: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`. So, `ORPHAN_DIR_SYSTEM_INODE` appears to be the last lock acquired in this chain.
Looking at the report again, and I confirm `ORPHAN_DIR_SYSTEM_INODE` is acquired in `ocfs2_del_inode_from_orphan`. This function is being called from the DIO path.
I also observe `inode_lock` being called within `ocfs2_file_write_iter`, but that's a *regular* inode, not a system inode. Then, the realization hits: the key here is not the *files* themselves, but the *system inodes* associated with various operations. It looks like `ocfs2_del_inode_from_orphan` acquires `ORPHAN_DIR_SYSTEM_INODE` after a previous lock.
Now, I was initially worried that `EXTENT_ALLOC_SYSTEM_INODE` and `ORPHAN_DIR_SYSTEM_INODE` might be treated as the same lock class. But no, the array index in `ocfs2_sysfile_lock_key` tells us they are distinct.
So, let's break down the lock dependencies. Dependency 1, `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` is clearly established inside `ocfs2_mknod`: `INODE_ALLOC_SYSTEM_INODE` is reserved *before* `EXTENT_ALLOC_SYSTEM_INODE`. I confirm this in `ocfs2_mknod` where the code first acquires `INODE_ALLOC_SYSTEM_INODE` and subsequently acquires `EXTENT_ALLOC_SYSTEM_INODE`.
The next dependency, `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`, remains the central question. Since the lockdep shows `#1` and `#2` show these 2 locks, then there *must* be a point where `ORPHAN_DIR_SYSTEM_INODE` is acquired while `EXTENT_ALLOC_SYSTEM_INODE` is held. I suspect that this *might* be in `ocfs2_del_inode_from_orphan`, however, now the DIO write path comes into focus as a possible candidate. That's the part that is still unclear. The analysis continues.
|
| 31/2 |
2026/05/29 16:54 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/aops.c FirstLine:2340 LineCount:100]
Results: map[Contents:2340: ue->ue_cpos, 1,
2341: ue->ue_phys,
2342: meta_ac, &dealloc);
2343: if (ret < 0) {
2344: mlog_errno(ret);
2345: goto commit;
2346: }
2347:
2348: if (++batch == OCFS2_DIO_MARK_EXTENT_BATCH) {
2349: ocfs2_commit_trans(osb, handle);
2350: handle = NULL;
2351: batch = 0;
2352: }
2353: }
2354:
2355: if (end > i_size_read(inode)) {
2356: if (!handle) {
2357: handle = ocfs2_start_trans(osb, credits);
2358: if (IS_ERR(handle)) {
2359: ret = PTR_ERR(handle);
2360: mlog_errno(ret);
2361: goto unlock;
2362: }
2363: }
2364: ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
2365: if (ret < 0)
2366: mlog_errno(ret);
2367: }
2368:
2369: commit:
2370: if (handle)
2371: ocfs2_commit_trans(osb, handle);
2372: unlock:
2373: up_write(&oi->ip_alloc_sem);
2374:
2375: /* everything looks good, let's start the cleanup */
2376: if (!ret && dwc->dw_orphaned) {
2377: BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
2378:
2379: ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2380: if (ret < 0)
2381: mlog_errno(ret);
2382: }
2383: ocfs2_inode_unlock(inode, 1);
2384: brelse(di_bh);
2385: out:
2386: if (data_ac)
2387: ocfs2_free_alloc_context(data_ac);
2388: if (meta_ac)
2389: ocfs2_free_alloc_context(meta_ac);
2390: ocfs2_run_deallocs(osb, &dealloc);
2391: ocfs2_dio_free_write_ctx(inode, dwc);
2392:
2393: return ret;
2394: }
2395:
2396: /*
2397: * ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
2398: * particularly interested in the aio/dio case. We use the rw_lock DLM lock
2399: * to protect io on one node from truncation on another.
2400: */
2401: static int ocfs2_dio_end_io(struct kiocb *iocb,
2402: loff_t offset,
2403: ssize_t bytes,
2404: void *private)
2405: {
2406: struct inode *inode = file_inode(iocb->ki_filp);
2407: int level;
2408: int ret = 0;
2409:
2410: /* this io's submitter should not have unlocked this before we could */
2411: BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
2412:
2413: if (bytes <= 0)
2414: mlog_ratelimited(ML_ERROR, "Direct IO failed, bytes = %lld",
2415: (long long)bytes);
2416: if (private) {
2417: if (bytes > 0)
2418: ret = ocfs2_dio_end_io_write(inode, private, offset,
2419: bytes);
2420: else
2421: ocfs2_dio_free_write_ctx(inode, private);
2422: }
2423:
2424: ocfs2_iocb_clear_rw_locked(iocb);
2425:
2426: level = ocfs2_iocb_rw_locked_level(iocb);
2427: ocfs2_rw_unlock(inode, level);
2428: return ret;
2429: }
2430:
2431: static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
2432: {
2433: struct file *file = iocb->ki_filp;
2434: struct inode *inode = file->f_mapping->host;
2435: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2436: get_block_t *get_block;
2437:
2438: /*
2439: * Fallback to buffered I/O if we see an inode without
]
|
| 32/2 |
2026/05/29 16:54 |
llm |
debugger |
0m
Model:
Tokens:
input: 45428
output: 40
thoughts: 125
Thoughts: **Analyzing a Potential Race Condition in OCFS2**
Okay, hold on a second. I'm looking at `ocfs2_dio_end_io_write` and I see a potential problem. Line 2379 shows `ocfs2_del_inode_from_orphan` being called. My immediate concern is that `meta_ac` is freed *right after* that, at line 2388! This is screaming race condition to me.
If `meta_ac` is getting freed *after* the call to `ocfs2_del_inode_from_orphan`, then that means `ocfs2_del_inode_from_orphan` must be *holding* `meta_ac` during its execution. Now, the next question is where is `meta_ac` acquired to understand if this behaviour can be problematic? I need to trace this back and pinpoint the exact locking scheme in `ocfs2_dio_end_io_write` to see if there's a window of vulnerability here. I need to know how it's acquired and how that relates to the orphan clean-up process. Let's dig in and figure out where that acquisition is happening.
|
| 33/2 |
2026/05/29 16:54 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/aops.c FirstLine:2250 LineCount:100]
Results: map[Contents:2250:
2251: list_splice_tail_init(&wc->w_unwritten_list, &dwc->dw_zero_list);
2252: dwc->dw_zero_count += wc->w_unwritten_count;
2253: }
2254:
2255: ret = ocfs2_write_end_nolock(inode->i_mapping, pos, len, len, wc);
2256: BUG_ON(ret != len);
2257: ret = 0;
2258: unlock:
2259: up_write(&oi->ip_alloc_sem);
2260: ocfs2_inode_unlock(inode, 1);
2261: brelse(di_bh);
2262: out:
2263: return ret;
2264: }
2265:
2266: static int ocfs2_dio_end_io_write(struct inode *inode,
2267: struct ocfs2_dio_write_ctxt *dwc,
2268: loff_t offset,
2269: ssize_t bytes)
2270: {
2271: struct ocfs2_cached_dealloc_ctxt dealloc;
2272: struct ocfs2_extent_tree et;
2273: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2274: struct ocfs2_inode_info *oi = OCFS2_I(inode);
2275: struct ocfs2_unwritten_extent *ue = NULL;
2276: struct buffer_head *di_bh = NULL;
2277: struct ocfs2_dinode *di;
2278: struct ocfs2_alloc_context *data_ac = NULL;
2279: struct ocfs2_alloc_context *meta_ac = NULL;
2280: handle_t *handle = NULL;
2281: loff_t end = offset + bytes;
2282: int ret = 0, credits = 0, batch = 0;
2283:
2284: ocfs2_init_dealloc_ctxt(&dealloc);
2285:
2286: /* We do clear unwritten, delete orphan, change i_size here. If neither
2287: * of these happen, we can skip all this. */
2288: if (list_empty(&dwc->dw_zero_list) &&
2289: end <= i_size_read(inode) &&
2290: !dwc->dw_orphaned)
2291: goto out;
2292:
2293: ret = ocfs2_inode_lock(inode, &di_bh, 1);
2294: if (ret < 0) {
2295: mlog_errno(ret);
2296: goto out;
2297: }
2298:
2299: down_write(&oi->ip_alloc_sem);
2300: di = (struct ocfs2_dinode *)di_bh->b_data;
2301:
2302: ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh);
2303:
2304: /* Attach dealloc with extent tree in case that we may reuse extents
2305: * which are already unlinked from current extent tree due to extent
2306: * rotation and merging.
2307: */
2308: et.et_dealloc = &dealloc;
2309:
2310: ret = ocfs2_lock_allocators(inode, &et, 0, dwc->dw_zero_count*2,
2311: &data_ac, &meta_ac);
2312: if (ret) {
2313: mlog_errno(ret);
2314: goto unlock;
2315: }
2316:
2317: credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
2318:
2319: list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) {
2320: if (!handle) {
2321: handle = ocfs2_start_trans(osb, credits);
2322: if (IS_ERR(handle)) {
2323: ret = PTR_ERR(handle);
2324: mlog_errno(ret);
2325: goto unlock;
2326: }
2327: ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
2328: OCFS2_JOURNAL_ACCESS_WRITE);
2329: if (ret) {
2330: mlog_errno(ret);
2331: goto commit;
2332: }
2333: }
2334: ret = ocfs2_assure_trans_credits(handle, credits);
2335: if (ret < 0) {
2336: mlog_errno(ret);
2337: goto commit;
2338: }
2339: ret = ocfs2_mark_extent_written(inode, &et, handle,
2340: ue->ue_cpos, 1,
2341: ue->ue_phys,
2342: meta_ac, &dealloc);
2343: if (ret < 0) {
2344: mlog_errno(ret);
2345: goto commit;
2346: }
2347:
2348: if (++batch == OCFS2_DIO_MARK_EXTENT_BATCH) {
2349: ocfs2_commit_trans(osb, handle);
]
|
| 34/2 |
2026/05/29 16:54 |
llm |
debugger |
0m
Model:
Tokens:
input: 47471
output: 40
thoughts: 186
Thoughts: **Lock Ordering Insight**
Okay, let me break this down. Line 2310, `ocfs2_lock_allocators` is called. Interesting. This function's allocating `meta_ac`, which is locking `EXTENT_ALLOC_SYSTEM_INODE`. Right. So we're establishing an ordering relationship with that lock. Now, at line 2379, it calls `ocfs2_del_inode_from_orphan`, and that function *acquires* `ORPHAN_DIR_SYSTEM_INODE`. Aha! And `meta_ac` gets freed, thankfully, at line 2388.
So, *effectively*, this sequence ensures that `EXTENT_ALLOC_SYSTEM_INODE` is held while `ORPHAN_DIR_SYSTEM_INODE` is acquired. That's a lock ordering; we've got `EXTENT_ALLOC_SYSTEM_INODE` before `ORPHAN_DIR_SYSTEM_INODE`. It's `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`. Need to verify my theory though. Let's trace it through. Time to check how `ocfs2_lock_allocators` is actually acquiring `EXTENT_ALLOC_SYSTEM_INODE`.
|
| 35/2 |
2026/05/29 16:54 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/aops.c FirstLine:1730 LineCount:100]
Results: map[Contents:1730:
1731: credits = ocfs2_calc_extend_credits(inode->i_sb,
1732: &di->id2.i_list);
1733: } else if (type == OCFS2_WRITE_DIRECT)
1734: /* direct write needs not to start trans if no extents alloc. */
1735: goto success;
1736:
1737: /*
1738: * We have to zero sparse allocated clusters, unwritten extent clusters,
1739: * and non-sparse clusters we just extended. For non-sparse writes,
1740: * we know zeros will only be needed in the first and/or last cluster.
1741: */
1742: if (wc->w_clen && (wc->w_desc[0].c_needs_zero ||
1743: wc->w_desc[wc->w_clen - 1].c_needs_zero))
1744: cluster_of_pages = 1;
1745: else
1746: cluster_of_pages = 0;
1747:
1748: ocfs2_set_target_boundaries(osb, wc, pos, len, cluster_of_pages);
1749:
1750: handle = ocfs2_start_trans(osb, credits);
1751: if (IS_ERR(handle)) {
1752: ret = PTR_ERR(handle);
1753: mlog_errno(ret);
1754: goto out;
1755: }
1756:
1757: wc->w_handle = handle;
1758:
1759: if (clusters_to_alloc) {
1760: ret = dquot_alloc_space_nodirty(inode,
1761: ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc));
1762: if (ret)
1763: goto out_commit;
1764: }
1765:
1766: ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), wc->w_di_bh,
1767: OCFS2_JOURNAL_ACCESS_WRITE);
1768: if (ret) {
1769: mlog_errno(ret);
1770: goto out_quota;
1771: }
1772:
1773: /*
1774: * Fill our folio array first. That way we've grabbed enough so
1775: * that we can zero and flush if we error after adding the
1776: * extent.
1777: */
1778: ret = ocfs2_grab_folios_for_write(mapping, wc, wc->w_cpos, pos, len,
1779: cluster_of_pages, mmap_folio);
1780: if (ret) {
1781: /*
1782: * ocfs2_grab_folios_for_write() returns -EAGAIN if it
1783: * could not lock the target folio. In this case, we exit
1784: * with no error and no target folio. This will trigger
1785: * the caller, page_mkwrite(), to re-try the operation.
1786: */
1787: if (type == OCFS2_WRITE_MMAP && ret == -EAGAIN) {
1788: BUG_ON(wc->w_target_folio);
1789: ret = 0;
1790: goto out_quota;
1791: }
1792:
1793: mlog_errno(ret);
1794: goto out_quota;
1795: }
1796:
1797: ret = ocfs2_write_cluster_by_desc(mapping, data_ac, meta_ac, wc, pos,
1798: len);
1799: if (ret) {
1800: mlog_errno(ret);
1801: goto out_quota;
1802: }
1803:
1804: if (data_ac)
1805: ocfs2_free_alloc_context(data_ac);
1806: if (meta_ac)
1807: ocfs2_free_alloc_context(meta_ac);
1808:
1809: success:
1810: if (foliop)
1811: *foliop = wc->w_target_folio;
1812: *fsdata = wc;
1813: return 0;
1814: out_quota:
1815: if (clusters_to_alloc)
1816: dquot_free_space(inode,
1817: ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc));
1818: out_commit:
1819: ocfs2_commit_trans(osb, handle);
1820:
1821: out:
1822: /*
1823: * The mmapped page won't be unlocked in ocfs2_free_write_ctxt(),
1824: * even in case of error here like ENOSPC and ENOMEM. So, we need
1825: * to unlock the target page manually to prevent deadlocks when
1826: * retrying again on ENOSPC, or when returning non-VM_FAULT_LOCKED
1827: * to VM code.
1828: */
1829: if (wc->w_target_locked)
]
|
| 36/2 |
2026/05/29 16:54 |
llm |
debugger |
0m
Model:
Tokens:
input: 49528
output: 34
thoughts: 16
Thoughts: Here's my thought process, summarized as you requested:
**Navigating the OCFS2 Lock Allocator Landscape**
Okay, hold on a second. Before I proceed any further with this line of investigation, I need to make absolutely sure I'm fully up-to-speed on the foundational elements. Specifically, I need to zoom in on the `ocfs2_lock_allocators`. This isn't just a casual glance; I need to mentally review the architecture, the key data structures involved, and, of course, the implications of various allocator strategies on the system's overall performance. I know I have a strong foundation in locking principles, but a quick refresh on the nuances of this specific implementation within OCFS2 is absolutely critical to avoid making a costly mistake later on. It's time to solidify my understanding of the allocator's role in the bigger picture.
|
| 37/2 |
2026/05/29 16:55 |
tool |
grepper |
0m
Args: map[Expression:ocfs2_lock_allocators PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/aops.c=1625=int ocfs2_write_begin_nolock(struct address_space *mapping,
--
fs/ocfs2/aops.c-1714- * XXX: We are stretching the limits of
fs/ocfs2/aops.c:1715: * ocfs2_lock_allocators(). It greatly over-estimates
fs/ocfs2/aops.c-1716- * the work to be done.
--
fs/ocfs2/aops.c-1719- wc->w_di_bh);
fs/ocfs2/aops.c:1720: ret = ocfs2_lock_allocators(inode, &et,
fs/ocfs2/aops.c-1721- clusters_to_alloc, extents_to_split,
--
fs/ocfs2/aops.c=2266=static int ocfs2_dio_end_io_write(struct inode *inode,
--
fs/ocfs2/aops.c-2309-
fs/ocfs2/aops.c:2310: ret = ocfs2_lock_allocators(inode, &et, 0, dwc->dw_zero_count*2,
fs/ocfs2/aops.c-2311- &data_ac, &meta_ac);
--
fs/ocfs2/dir.c=3745=static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir,
--
fs/ocfs2/dir.c-3800-
fs/ocfs2/dir.c:3801: ret = ocfs2_lock_allocators(dir, &et, 1, 0, &data_ac, &meta_ac);
fs/ocfs2/dir.c-3802- if (ret) {
--
fs/ocfs2/file.c=556=static int ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
--
fs/ocfs2/file.c-589- ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), bh);
fs/ocfs2/file.c:590: status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
fs/ocfs2/file.c-591- &data_ac, &meta_ac);
--
fs/ocfs2/suballoc.c=3028=int ocfs2_release_clusters(handle_t *handle,
--
fs/ocfs2/suballoc.c-3048- */
fs/ocfs2/suballoc.c:3049:int ocfs2_lock_allocators(struct inode *inode,
fs/ocfs2/suballoc.c-3050- struct ocfs2_extent_tree *et,
--
fs/ocfs2/suballoc.h=199=int ocfs2_read_group_descriptor(struct inode *inode, struct ocfs2_dinode *di,
--
fs/ocfs2/suballoc.h-201-
fs/ocfs2/suballoc.h:202:int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et,
fs/ocfs2/suballoc.h-203- u32 clusters_to_add, u32 extents_to_split,
--
fs/ocfs2/xattr.c=5441=static int ocfs2_rm_xattr_cluster(struct inode *inode,
--
fs/ocfs2/xattr.c-5475-
fs/ocfs2/xattr.c:5476: ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
fs/ocfs2/xattr.c-5477- if (ret) {
]
|
| 38/2 |
2026/05/29 16:55 |
llm |
debugger |
0m
Model:
Tokens:
input: 50794
output: 40
thoughts: 27
Thoughts: Here's my take on the thought process, as if it were my own:
**Diving into the OCFS2 Suballocator**
Alright, time to dig into the `ocfs2_lock_allocators` component, specifically within the `fs/ocfs2/suballoc.c` file. I need to refresh my memory on how this locking mechanism interacts with the suballocation process within the OCFS2 filesystem. My experience tells me there will be intricacies around concurrency and ensuring data consistency during allocation and deallocation of metadata blocks. I'm going to want to understand how contention is handled here. Let's see how they've structured and implemented the allocator data structures. Time to get my hands dirty.
|
| 39/2 |
2026/05/29 16:55 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/suballoc.c FirstLine:3049 LineCount:100]
Results: map[Contents:3049: int ocfs2_lock_allocators(struct inode *inode,
3050: struct ocfs2_extent_tree *et,
3051: u32 clusters_to_add, u32 extents_to_split,
3052: struct ocfs2_alloc_context **data_ac,
3053: struct ocfs2_alloc_context **meta_ac)
3054: {
3055: int ret = 0, num_free_extents;
3056: unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split;
3057: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
3058:
3059: *meta_ac = NULL;
3060: if (data_ac)
3061: *data_ac = NULL;
3062:
3063: BUG_ON(clusters_to_add != 0 && data_ac == NULL);
3064:
3065: num_free_extents = ocfs2_num_free_extents(et);
3066: if (num_free_extents < 0) {
3067: ret = num_free_extents;
3068: mlog_errno(ret);
3069: goto out;
3070: }
3071:
3072: /*
3073: * Sparse allocation file systems need to be more conservative
3074: * with reserving room for expansion - the actual allocation
3075: * happens while we've got a journal handle open so re-taking
3076: * a cluster lock (because we ran out of room for another
3077: * extent) will violate ordering rules.
3078: *
3079: * Most of the time we'll only be seeing this 1 cluster at a time
3080: * anyway.
3081: *
3082: * Always lock for any unwritten extents - we might want to
3083: * add blocks during a split.
3084: */
3085: if (!num_free_extents ||
3086: (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) {
3087: ret = ocfs2_reserve_new_metadata(osb, et->et_root_el, meta_ac);
3088: if (ret < 0) {
3089: if (ret != -ENOSPC)
3090: mlog_errno(ret);
3091: goto out;
3092: }
3093: }
3094:
3095: if (clusters_to_add == 0)
3096: goto out;
3097:
3098: ret = ocfs2_reserve_clusters(osb, clusters_to_add, data_ac);
3099: if (ret < 0) {
3100: if (ret != -ENOSPC)
3101: mlog_errno(ret);
3102: goto out;
3103: }
3104:
3105: out:
3106: if (ret) {
3107: if (*meta_ac) {
3108: ocfs2_free_alloc_context(*meta_ac);
3109: *meta_ac = NULL;
3110: }
3111:
3112: /*
3113: * We cannot have an error and a non null *data_ac.
3114: */
3115: }
3116:
3117: return ret;
3118: }
3119:
3120: /*
3121: * Read the inode specified by blkno to get suballoc_slot and
3122: * suballoc_bit.
3123: */
3124: static int ocfs2_get_suballoc_slot_bit(struct ocfs2_super *osb, u64 blkno,
3125: u16 *suballoc_slot, u64 *group_blkno,
3126: u16 *suballoc_bit)
3127: {
3128: int status;
3129: struct buffer_head *inode_bh = NULL;
3130: struct ocfs2_dinode *inode_fe;
3131:
3132: trace_ocfs2_get_suballoc_slot_bit((unsigned long long)blkno);
3133:
3134: /* dirty read disk */
3135: status = ocfs2_read_blocks_sync(osb, blkno, 1, &inode_bh);
3136: if (status < 0) {
3137: mlog(ML_ERROR, "read block %llu failed %d\n",
3138: (unsigned long long)blkno, status);
3139: goto bail;
3140: }
3141:
3142: inode_fe = (struct ocfs2_dinode *) inode_bh->b_data;
3143: if (!OCFS2_IS_VALID_DINODE(inode_fe)) {
3144: mlog(ML_ERROR, "invalid inode %llu requested\n",
3145: (unsigned long long)blkno);
3146: status = -EINVAL;
3147: goto bail;
3148: }
]
|
| 40/2 |
2026/05/29 16:55 |
llm |
debugger |
0m
Model:
Tokens:
input: 52559
output: 38
thoughts: 885
Thoughts: **Analyzing the Lock Dependency Cycle**
Okay, let's break this down. From what I'm seeing, `ocfs2_lock_allocators` in `ocfs2_dio_end_io_write` calls `ocfs2_reserve_new_metadata`, which then calls `ocfs2_reserve_new_metadata_blocks`. This sequence ends up acquiring `EXTENT_ALLOC_SYSTEM_INODE` through `meta_ac`. So, step one in `ocfs2_dio_end_io_write` is acquiring `EXTENT_ALLOC_SYSTEM_INODE`. Step two involves `ocfs2_del_inode_from_orphan`, which grabs `ORPHAN_DIR_SYSTEM_INODE`. After this, `meta_ac` is freed, releasing `EXTENT_ALLOC_SYSTEM_INODE`.
This immediately highlights a dependency: `EXTENT_ALLOC_SYSTEM_INODE` *must* come before `ORPHAN_DIR_SYSTEM_INODE`. Now, the crucial question is: what is the third piece of this lock dependency puzzle, the final piece in this circular dependency?
The lockdep report is very insightful here. It shows that `ocfs2_wipe_inode` is trying to acquire `ORPHAN_DIR_SYSTEM_INODE` *before* `INODE_ALLOC_SYSTEM_INODE`. The relevant snippets are in `fs/ocfs2/inode.c`, specifically `ocfs2_wipe_inode` and within the `ocfs2_evict_inode` function. The key is in those calls to `inode_lock` within those functions.
This means that `ocfs2_wipe_inode` acquires `ORPHAN_DIR_SYSTEM_INODE` and then tries to get `INODE_ALLOC_SYSTEM_INODE`. That looks to be our third dependency. It's time to check what's happening within `ocfs2_wipe_inode`. I'll want to review the code to confirm this dependency and see how the functions interact to solidify this understanding.
|
| 41/2 |
2026/05/29 16:55 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/inode.c FirstLine:840 LineCount:100]
Results: map[Contents: 840: return status;
841:
842: orphan_dir_inode = ocfs2_get_system_file_inode(osb,
843: ORPHAN_DIR_SYSTEM_INODE,
844: orphaned_slot);
845: if (!orphan_dir_inode) {
846: status = -ENOENT;
847: mlog_errno(status);
848: goto bail;
849: }
850:
851: /* Lock the orphan dir. The lock will be held for the entire
852: * delete_inode operation. We do this now to avoid races with
853: * recovery completion on other nodes. */
854: inode_lock(orphan_dir_inode);
855: status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
856: if (status < 0) {
857: inode_unlock(orphan_dir_inode);
858:
859: mlog_errno(status);
860: goto bail;
861: }
862: }
863:
864: /* we do this while holding the orphan dir lock because we
865: * don't want recovery being run from another node to try an
866: * inode delete underneath us -- this will result in two nodes
867: * truncating the same file! */
868: status = ocfs2_truncate_for_delete(osb, inode, di_bh);
869: if (status < 0) {
870: mlog_errno(status);
871: goto bail_unlock_dir;
872: }
873:
874: /* Remove any dir index tree */
875: if (S_ISDIR(inode->i_mode)) {
876: status = ocfs2_dx_dir_truncate(inode, di_bh);
877: if (status) {
878: mlog_errno(status);
879: goto bail_unlock_dir;
880: }
881: }
882:
883: /*Free extended attribute resources associated with this inode.*/
884: status = ocfs2_xattr_remove(inode, di_bh);
885: if (status < 0) {
886: mlog_errno(status);
887: goto bail_unlock_dir;
888: }
889:
890: status = ocfs2_remove_refcount_tree(inode, di_bh);
891: if (status < 0) {
892: mlog_errno(status);
893: goto bail_unlock_dir;
894: }
895:
896: status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode,
897: orphan_dir_bh);
898: if (status < 0)
899: mlog_errno(status);
900:
901: bail_unlock_dir:
902: if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)
903: return status;
904:
905: ocfs2_inode_unlock(orphan_dir_inode, 1);
906: inode_unlock(orphan_dir_inode);
907: brelse(orphan_dir_bh);
908: bail:
909: iput(orphan_dir_inode);
910: ocfs2_signal_wipe_completion(osb, orphaned_slot);
911:
912: return status;
913: }
914:
915: /* There is a series of simple checks that should be done before a
916: * trylock is even considered. Encapsulate those in this function. */
917: static int ocfs2_inode_is_valid_to_delete(struct inode *inode)
918: {
919: int ret = 0;
920: struct ocfs2_inode_info *oi = OCFS2_I(inode);
921: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
922:
923: trace_ocfs2_inode_is_valid_to_delete(current, osb->dc_task,
924: (unsigned long long)oi->ip_blkno,
925: oi->ip_flags);
926:
927: /* We shouldn't be getting here for the root directory
928: * inode.. */
929: if (inode == osb->root_inode) {
930: mlog(ML_ERROR, "Skipping delete of root inode.\n");
931: goto bail;
932: }
933:
934: /*
935: * If we're coming from downconvert_thread we can't go into our own
936: * voting [hello, deadlock city!] so we cannot delete the inode. But
937: * since we dropped last inode ref when downconverting dentry lock,
938: * we cannot have the file open and thus the node doing unlink will
939: * take care of deleting the inode.
]
|
| 42/2 |
2026/05/29 16:55 |
llm |
debugger |
0m
Model:
Tokens:
input: 55472
output: 38
thoughts: 65
Thoughts: **Analyzing the Inode Wiping Process**
Okay, so I'm looking at `ocfs2_wipe_inode` and it looks like, as expected, it grabs that `ORPHAN_DIR_SYSTEM_INODE` lock around line 854. That's the critical point for ensuring data consistency when dealing with orphaned inodes, so that makes perfect sense. Now, it appears to call `ocfs2_remove_inode` at line 896. Right. We need to dissect what happens inside that function to truly understand the overall process. Time to dig into `ocfs2_remove_inode` and see how it interacts with the lock and what other operations it performs.
|
| 43/2 |
2026/05/29 16:55 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/inode.c FirstLine:710 LineCount:100]
Results: map[Contents: 710: }
711:
712: static int ocfs2_remove_inode(struct inode *inode,
713: struct buffer_head *di_bh,
714: struct inode *orphan_dir_inode,
715: struct buffer_head *orphan_dir_bh)
716: {
717: int status;
718: struct inode *inode_alloc_inode = NULL;
719: struct buffer_head *inode_alloc_bh = NULL;
720: handle_t *handle;
721: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
722: struct ocfs2_dinode *di = (struct ocfs2_dinode *) di_bh->b_data;
723:
724: inode_alloc_inode =
725: ocfs2_get_system_file_inode(osb, INODE_ALLOC_SYSTEM_INODE,
726: le16_to_cpu(di->i_suballoc_slot));
727: if (!inode_alloc_inode) {
728: status = -ENOENT;
729: mlog_errno(status);
730: goto bail;
731: }
732:
733: inode_lock(inode_alloc_inode);
734: status = ocfs2_inode_lock(inode_alloc_inode, &inode_alloc_bh, 1);
735: if (status < 0) {
736: inode_unlock(inode_alloc_inode);
737:
738: mlog_errno(status);
739: goto bail;
740: }
741:
742: handle = ocfs2_start_trans(osb, OCFS2_DELETE_INODE_CREDITS +
743: ocfs2_quota_trans_credits(inode->i_sb));
744: if (IS_ERR(handle)) {
745: status = PTR_ERR(handle);
746: mlog_errno(status);
747: goto bail_unlock;
748: }
749:
750: if (!(OCFS2_I(inode)->ip_flags & OCFS2_INODE_SKIP_ORPHAN_DIR)) {
751: status = ocfs2_orphan_del(osb, handle, orphan_dir_inode, inode,
752: orphan_dir_bh, false);
753: if (status < 0) {
754: mlog_errno(status);
755: goto bail_commit;
756: }
757: }
758:
759: /* set the inodes dtime */
760: status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
761: OCFS2_JOURNAL_ACCESS_WRITE);
762: if (status < 0) {
763: mlog_errno(status);
764: goto bail_commit;
765: }
766:
767: di->i_dtime = cpu_to_le64(ktime_get_real_seconds());
768: di->i_flags &= cpu_to_le32(~(OCFS2_VALID_FL | OCFS2_ORPHANED_FL));
769: ocfs2_journal_dirty(handle, di_bh);
770:
771: ocfs2_remove_from_cache(INODE_CACHE(inode), di_bh);
772: dquot_free_inode(inode);
773:
774: status = ocfs2_free_dinode(handle, inode_alloc_inode,
775: inode_alloc_bh, di);
776: if (status < 0)
777: mlog_errno(status);
778:
779: bail_commit:
780: ocfs2_commit_trans(osb, handle);
781: bail_unlock:
782: ocfs2_inode_unlock(inode_alloc_inode, 1);
783: inode_unlock(inode_alloc_inode);
784: brelse(inode_alloc_bh);
785: bail:
786: iput(inode_alloc_inode);
787:
788: return status;
789: }
790:
791: /*
792: * Serialize with orphan dir recovery. If the process doing
793: * recovery on this orphan dir does an iget() with the dir
794: * i_rwsem held, we'll deadlock here. Instead we detect this
795: * and exit early - recovery will wipe this inode for us.
796: */
797: static int ocfs2_check_orphan_recovery_state(struct ocfs2_super *osb,
798: int slot)
799: {
800: int ret = 0;
801:
802: spin_lock(&osb->osb_lock);
803: if (ocfs2_node_map_test_bit(osb, &osb->osb_recovering_orphan_dirs, slot)) {
804: ret = -EDEADLK;
805: goto out;
806: }
807: /* This signals to the orphan recovery process that it should
808: * wait for us to handle the wipe. */
809: osb->osb_orphan_wipes[slot]++;
]
|
| 44/2 |
2026/05/29 16:55 |
llm |
debugger |
0m
Model:
Tokens:
input: 57333
output: 40
thoughts: 905
Thoughts: **Analyzing a Lock Dependency Cycle in OCFS2**
Okay, so I'm looking at this lockdep report, and it's pointing out a nasty cycle: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`. I can see how this happens. Let's break it down:
First, in `ocfs2_mknod`, we have the `INODE_ALLOC_SYSTEM_INODE` lock acquired before `EXTENT_ALLOC_SYSTEM_INODE`. Specifically, `ocfs2_reserve_new_inode` gets `INODE_ALLOC_SYSTEM_INODE` and then `ocfs2_reserve_new_metadata_blocks` grabs `EXTENT_ALLOC_SYSTEM_INODE`. I need to remember that `INODE_ALLOC_SYSTEM_INODE` is held throughout `ocfs2_mknod` until the end, or on error.
Next, in `ocfs2_dio_end_io_write`, we see the flip side. `ocfs2_lock_allocators` acquires `EXTENT_ALLOC_SYSTEM_INODE` *then* `ocfs2_del_inode_from_orphan` gets `ORPHAN_DIR_SYSTEM_INODE`. The critical point here is that `EXTENT_ALLOC_SYSTEM_INODE` is held *throughout* the call to `ocfs2_del_inode_from_orphan`, until the alloc context is freed after.
Finally, in `ocfs2_wipe_inode`, we have `inode_lock(orphan_dir_inode)` acquiring `ORPHAN_DIR_SYSTEM_INODE`, and then `ocfs2_remove_inode` takes `INODE_ALLOC_SYSTEM_INODE`. And again, `ORPHAN_DIR_SYSTEM_INODE` is held while `INODE_ALLOC_SYSTEM_INODE` is acquired.
So, yeah, that's a classic deadlock cycle right there: `INODE` -> `EXTENT` -> `ORPHAN` -> `INODE`.
The question is, how do we break it? It seems the crucial dependency to break is in `ocfs2_dio_end_io_write`. If we release `EXTENT_ALLOC_SYSTEM_INODE` (held by `meta_ac`) *before* calling `ocfs2_del_inode_from_orphan`, we'd eliminate the `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` dependency. Looking at the code for that function, it seems like we *could* free `meta_ac` (and `data_ac`) earlier. That's the key.
|
| 45/2 |
2026/05/29 16:55 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/aops.c FirstLine:2360 LineCount:100]
Results: map[Contents:2360: mlog_errno(ret);
2361: goto unlock;
2362: }
2363: }
2364: ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
2365: if (ret < 0)
2366: mlog_errno(ret);
2367: }
2368:
2369: commit:
2370: if (handle)
2371: ocfs2_commit_trans(osb, handle);
2372: unlock:
2373: up_write(&oi->ip_alloc_sem);
2374:
2375: /* everything looks good, let's start the cleanup */
2376: if (!ret && dwc->dw_orphaned) {
2377: BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
2378:
2379: ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2380: if (ret < 0)
2381: mlog_errno(ret);
2382: }
2383: ocfs2_inode_unlock(inode, 1);
2384: brelse(di_bh);
2385: out:
2386: if (data_ac)
2387: ocfs2_free_alloc_context(data_ac);
2388: if (meta_ac)
2389: ocfs2_free_alloc_context(meta_ac);
2390: ocfs2_run_deallocs(osb, &dealloc);
2391: ocfs2_dio_free_write_ctx(inode, dwc);
2392:
2393: return ret;
2394: }
2395:
2396: /*
2397: * ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
2398: * particularly interested in the aio/dio case. We use the rw_lock DLM lock
2399: * to protect io on one node from truncation on another.
2400: */
2401: static int ocfs2_dio_end_io(struct kiocb *iocb,
2402: loff_t offset,
2403: ssize_t bytes,
2404: void *private)
2405: {
2406: struct inode *inode = file_inode(iocb->ki_filp);
2407: int level;
2408: int ret = 0;
2409:
2410: /* this io's submitter should not have unlocked this before we could */
2411: BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
2412:
2413: if (bytes <= 0)
2414: mlog_ratelimited(ML_ERROR, "Direct IO failed, bytes = %lld",
2415: (long long)bytes);
2416: if (private) {
2417: if (bytes > 0)
2418: ret = ocfs2_dio_end_io_write(inode, private, offset,
2419: bytes);
2420: else
2421: ocfs2_dio_free_write_ctx(inode, private);
2422: }
2423:
2424: ocfs2_iocb_clear_rw_locked(iocb);
2425:
2426: level = ocfs2_iocb_rw_locked_level(iocb);
2427: ocfs2_rw_unlock(inode, level);
2428: return ret;
2429: }
2430:
2431: static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
2432: {
2433: struct file *file = iocb->ki_filp;
2434: struct inode *inode = file->f_mapping->host;
2435: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2436: get_block_t *get_block;
2437:
2438: /*
2439: * Fallback to buffered I/O if we see an inode without
2440: * extents.
2441: */
2442: if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
2443: return 0;
2444:
2445: /* Fallback to buffered I/O if we do not support append dio. */
2446: if (iocb->ki_pos + iter->count > i_size_read(inode) &&
2447: !ocfs2_supports_append_dio(osb))
2448: return 0;
2449:
2450: if (iov_iter_rw(iter) == READ)
2451: get_block = ocfs2_lock_get_block;
2452: else
2453: get_block = ocfs2_dio_wr_get_block;
2454:
2455: return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
2456: iter, get_block,
2457: ocfs2_dio_end_io, 0);
2458: }
2459:
]
|
| 46/2 |
2026/05/29 16:55 |
llm |
debugger |
0m
Model:
Tokens:
input: 60470
output: 40
thoughts: 343
Thoughts: **My Optimization Plan**
Okay, so I'm focusing on these `data_ac` and `meta_ac` variables. I see they're only used within that loop that calls `ocfs2_mark_extent_written`. After the `commit:` point, they're definitely not needed anymore. My immediate thought is, can I free them then?
Wait, hold on. I see `ocfs2_run_deallocs` called later, at line 2390. Does *it* need either `data_ac` or `meta_ac`? Nope, it takes `&dealloc`, so that's good! So, yes, I can free `data_ac` and `meta_ac` before calling `ocfs2_del_inode_from_orphan`.
Wait a minute, `ocfs2_del_inode_from_orphan` is *actually* called at line 2379. We need to free it before 2375 to keep everything in sync!
Alright, let's step back and see if there are other points where this `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` is established. Let's make sure we're not missing anything.
Hold on, I see `ocfs2_free_alloc_context`, and that releases the lock... Wait, no, that is incorrect. Let me re-read this code:
```c
void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
{
if (ac->ac_inode)
iput(ac->ac_inode);
if (ac->ac_bh)
brelse(ac->ac_bh);
kfree(ac);
}
```
Okay, `ocfs2_free_alloc_context` does *NOT* unlock the inode. Got it. So I need to keep that in mind.
|
| 47/2 |
2026/05/29 16:55 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/suballoc.c FirstLine:1020 LineCount:100]
Results: map[Contents:1020:
1021: for (i = 0; i < osb->max_slots; i++, slot++) {
1022: if (slot == osb->max_slots)
1023: slot = 0;
1024:
1025: if (slot == osb->slot_num)
1026: continue;
1027:
1028: status = ocfs2_reserve_suballoc_bits(osb, ac,
1029: type,
1030: (u32)slot, NULL,
1031: NOT_ALLOC_NEW_GROUP);
1032: if (status >= 0) {
1033: __ocfs2_set_steal_slot(osb, slot, type);
1034: break;
1035: }
1036:
1037: ocfs2_free_ac_resource(ac);
1038: }
1039:
1040: return status;
1041: }
1042:
1043: static int ocfs2_steal_inode(struct ocfs2_super *osb,
1044: struct ocfs2_alloc_context *ac)
1045: {
1046: return ocfs2_steal_resource(osb, ac, INODE_ALLOC_SYSTEM_INODE);
1047: }
1048:
1049: static int ocfs2_steal_meta(struct ocfs2_super *osb,
1050: struct ocfs2_alloc_context *ac)
1051: {
1052: return ocfs2_steal_resource(osb, ac, EXTENT_ALLOC_SYSTEM_INODE);
1053: }
1054:
1055: int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb,
1056: int blocks,
1057: struct ocfs2_alloc_context **ac)
1058: {
1059: int status;
1060: int slot = ocfs2_get_meta_steal_slot(osb);
1061:
1062: *ac = kzalloc_obj(struct ocfs2_alloc_context);
1063: if (!(*ac)) {
1064: status = -ENOMEM;
1065: mlog_errno(status);
1066: goto bail;
1067: }
1068:
1069: (*ac)->ac_bits_wanted = blocks;
1070: (*ac)->ac_which = OCFS2_AC_USE_META;
1071: (*ac)->ac_group_search = ocfs2_block_group_search;
1072:
1073: if (slot != OCFS2_INVALID_SLOT &&
1074: atomic_read(&osb->s_num_meta_stolen) < OCFS2_MAX_TO_STEAL)
1075: goto extent_steal;
1076:
1077: atomic_set(&osb->s_num_meta_stolen, 0);
1078: status = ocfs2_reserve_suballoc_bits(osb, (*ac),
1079: EXTENT_ALLOC_SYSTEM_INODE,
1080: (u32)osb->slot_num, NULL,
1081: ALLOC_GROUPS_FROM_GLOBAL|ALLOC_NEW_GROUP);
1082:
1083:
1084: if (status >= 0) {
1085: status = 0;
1086: if (slot != OCFS2_INVALID_SLOT)
1087: ocfs2_init_meta_steal_slot(osb);
1088: goto bail;
1089: } else if (status < 0 && status != -ENOSPC) {
1090: mlog_errno(status);
1091: goto bail;
1092: }
1093:
1094: ocfs2_free_ac_resource(*ac);
1095:
1096: extent_steal:
1097: status = ocfs2_steal_meta(osb, *ac);
1098: atomic_inc(&osb->s_num_meta_stolen);
1099: if (status < 0) {
1100: if (status != -ENOSPC)
1101: mlog_errno(status);
1102: goto bail;
1103: }
1104:
1105: status = 0;
1106: bail:
1107: if ((status < 0) && *ac) {
1108: ocfs2_free_alloc_context(*ac);
1109: *ac = NULL;
1110: }
1111:
1112: if (status)
1113: mlog_errno(status);
1114: return status;
1115: }
1116:
1117: int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
1118: struct ocfs2_extent_list *root_el,
1119: struct ocfs2_alloc_context **ac)
]
|
| 48/2 |
2026/05/29 16:55 |
llm |
debugger |
0m
Model:
Tokens:
input: 62777
output: 36
thoughts: 60
Thoughts: **Digging into Allocation Contexts**
Okay, so I'm tracing through this allocation code and something just jumped out at me. I see that `ocfs2_free_ac_resource` is called within `ocfs2_reserve_new_metadata_blocks` when an error occurs. That's a good place to start, it gives a clear indication of how these resources are supposed to be cleaned up when a block reservation fails.
Now I need to understand what's actually happening in that `ocfs2_free_ac_resource` function, and how it relates to the broader allocation process. I'll need to locate and check both `ocfs2_free_alloc_context` and that `ocfs2_free_ac_resource` function to completely understand this. I'm hoping this will provide insight into how the allocation contexts are managed, how the resources associated with them are allocated and deallocated, and what the error paths look like. Understanding this interaction between resource freeing and context freeing is critical to determining the true nature of what's happening.
|
| 49/2 |
2026/05/29 16:55 |
tool |
grepper |
0m
Args: map[Expression:void ocfs2_free_alloc_context PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/suballoc.c=123=void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac)
--
fs/ocfs2/suballoc.c-142-
fs/ocfs2/suballoc.c:143:void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
fs/ocfs2/suballoc.c-144-{
--
fs/ocfs2/suballoc.h=50=void ocfs2_init_steal_slots(struct ocfs2_super *osb);
fs/ocfs2/suballoc.h:51:void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac);
fs/ocfs2/suballoc.h-52-static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac)
]
|
| 50/2 |
2026/05/29 16:55 |
llm |
debugger |
0m
Model:
Tokens:
input: 63338
output: 38
thoughts: 27
Thoughts: Okay, here's my interpretation of what's going through my mind as I analyze those functions, presented as a first-person summary geared towards an expert:
**Diving into Allocation Context Management**
Alright, time to dig into `ocfs2_free_alloc_context` and `ocfs2_free_ac_resource`. From the names alone, I'm expecting to see the core logic for releasing allocation contexts and associated resources within OCFS2. We're talking about managing the structures that track free space and how it's allocated in the filesystem, so correctness here is *absolutely* critical to overall system stability. I'm hoping to see clean resource deallocation and avoidance of any potential double frees or memory leaks.
I want to see how these functions handle the interplay between different allocation pools, perhaps block allocation groups (BAGs) or inode allocation pools. My immediate thoughts go to the locking involved. Is this a simple per-context lock, or something more sophisticated to handle concurrent access across different threads or processes? I need to analyze those locks very carefully to ensure the allocation structures aren't getting corrupted. Iβm particularly curious about the specific data structures being released, and whether there are any potential race conditions during the release process. I will be looking closely at any potential locking issues and how they handle errors.
My mental checklist includes looking for:
* **Proper synchronization:** Are there adequate mutexes/spinlocks around the critical sections? What is the granularity of the locking? Is it efficient, or overly coarse-grained?
* **Error handling:** What happens if a resource release fails, or if a context is already freed? Are there appropriate checks and logging to help debug issues?
* **Resource deallocation:** Are we freeing all the relevant memory? No dangling pointers? Any potential memory leaks?
* **Consistency:** Does the freed context or resource update global metadata correctly, reflecting the release of resources back to the pool?
Let's get into the details and start pulling this apart. Time to find the key pieces of the puzzle and see how these two pieces of code function, and more importantly, how well. Let's make sure it's all rock solid.
|
| 51/2 |
2026/05/29 16:56 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/suballoc.c FirstLine:120 LineCount:50]
Results: map[Contents: 120: int flags,
121: struct ocfs2_alloc_context **ac);
122:
123: void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac)
124: {
125: struct inode *inode = ac->ac_inode;
126:
127: if (inode) {
128: if (ac->ac_which != OCFS2_AC_USE_LOCAL)
129: ocfs2_inode_unlock(inode, 1);
130:
131: inode_unlock(inode);
132:
133: iput(inode);
134: ac->ac_inode = NULL;
135: }
136: brelse(ac->ac_bh);
137: ac->ac_bh = NULL;
138: ac->ac_resv = NULL;
139: kfree(ac->ac_find_loc_priv);
140: ac->ac_find_loc_priv = NULL;
141: }
142:
143: void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
144: {
145: ocfs2_free_ac_resource(ac);
146: kfree(ac);
147: }
148:
149: static u32 ocfs2_bits_per_group(struct ocfs2_chain_list *cl)
150: {
151: return (u32)le16_to_cpu(cl->cl_cpg) * (u32)le16_to_cpu(cl->cl_bpc);
152: }
153:
154: #define do_error(fmt, ...) \
155: do { \
156: if (resize) \
157: mlog(ML_ERROR, fmt, ##__VA_ARGS__); \
158: else \
159: return ocfs2_error(sb, fmt, ##__VA_ARGS__); \
160: } while (0)
161:
162: static int ocfs2_validate_gd_self(struct super_block *sb,
163: struct buffer_head *bh,
164: int resize)
165: {
166: struct ocfs2_group_desc *gd = (struct ocfs2_group_desc *)bh->b_data;
167:
168: if (!OCFS2_IS_VALID_GROUP_DESC(gd)) {
169: do_error("Group descriptor #%llu has bad signature %.*s\n",
]
|
| 52/2 |
2026/05/29 16:56 |
llm |
debugger |
0m
Model:
Tokens:
input: 64660
output: 37
thoughts: 1241
Thoughts: **Analyzing Allocation Context Release in OCFS2's Direct I/O Write Path**
Okay, so I'm looking at `ocfs2_dio_end_io_write` and trying to optimize the release of allocation contexts. I see that `ocfs2_free_ac_resource` calls `ocfs2_inode_unlock` and `inode_unlock`, so the allocation contexts *do* release locks. Good.
In this function, the plan is to see if I can move the freeing of `data_ac` and `meta_ac` *before* the call to `ocfs2_del_inode_from_orphan`. This should avoid any unnecessary lock contention. The initial hunch is that it might be safe, but I need to confirm. Let's see...
`ocfs2_del_inode_from_orphan` takes `osb`, `inode`, and `di_bh`, but no allocation contexts. So, on the face of it, it doesn't *directly* need them. I need to make sure this is safe.
I'm now thinking about the call stack, since this needs to be air tight. `ocfs2_run_deallocs` happens after `ocfs2_free_alloc_context` and it doesn't use `data_ac` or `meta_ac`, as far as I can see. Same with `ocfs2_inode_unlock` and `brelse(di_bh)`. But wait, `ocfs2_del_inode_from_orphan` *modifies* `di_bh`! It calls `ocfs2_journal_access_di`. So that buffer *must* be held and locked.
Right, `data_ac` and `meta_ac` are used for allocating clusters and metadata blocks; they're used in `ocfs2_mark_extent_written`. And once `ocfs2_mark_extent_written` is done and the transaction is committed, those allocation contexts should no longer be needed, right?
Thinking further, `ocfs2_mark_extent_written` is called inside a loop, and then *after* that loop, we have a transaction commit (`ocfs2_commit_trans`) and an unlock of `ip_alloc_sem`. That's where it happens. Right now it appears `data_ac` and `meta_ac` are held *across* the commit and the `up_write` on `ip_alloc_sem`.
Hmm. Is it safe to release them *immediately* after `commit:`? So, right after `ocfs2_commit_trans` but before `ocfs2_del_inode_from_orphan`? It *looks* like it would be safe, but let's be absolutely certain here. Releasing them there would free `EXTENT_ALLOC_SYSTEM_INODE` before `ORPHAN_DIR_SYSTEM_INODE` gets acquired.
The problem here is that there is a critical dependency: `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`. If this is broken, then things will go very wrong. So, I need to make sure this is not broken.
Finally, I need to check for other calls to `ocfs2_del_inode_from_orphan` that might hold those contexts. I need to see if there is another place in the code path.
|
| 53/2 |
2026/05/29 16:56 |
tool |
grepper |
0m
Args: map[Expression:ocfs2_del_inode_from_orphan PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/aops.c=2266=static int ocfs2_dio_end_io_write(struct inode *inode,
--
fs/ocfs2/aops.c-2378-
fs/ocfs2/aops.c:2379: ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
fs/ocfs2/aops.c-2380- if (ret < 0)
--
fs/ocfs2/journal.c=2287=static int ocfs2_recover_orphans(struct ocfs2_super *osb,
--
fs/ocfs2/journal.c-2344-
fs/ocfs2/journal.c:2345: ret = ocfs2_del_inode_from_orphan(osb, inode,
fs/ocfs2/journal.c-2346- di_bh, 0, 0);
--
fs/ocfs2/namei.c=2633=int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
--
fs/ocfs2/namei.c-2662-
fs/ocfs2/namei.c:2663: status = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
fs/ocfs2/namei.c-2664- if (status < 0) {
--
fs/ocfs2/namei.c-2708-
fs/ocfs2/namei.c:2709:int ocfs2_del_inode_from_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.c-2710- struct inode *inode, struct buffer_head *di_bh,
--
fs/ocfs2/namei.h=29=int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.h-30- struct inode *inode);
fs/ocfs2/namei.h:31:int ocfs2_del_inode_from_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.h-32- struct inode *inode, struct buffer_head *di_bh,
]
|
| 54/2 |
2026/05/29 16:56 |
llm |
debugger |
0m
Model:
Tokens:
input: 67291
output: 39
thoughts: 30
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating `ocfs2_add_inode_to_orphan`**
Alright, I'm thinking I need to delve into `ocfs2_add_inode_to_orphan` within `fs/ocfs2/namei.c`. Seems like something related to orphan inodes and namei operations is where I should be focusing my attention. I need to understand how this function handles adding inodes to the orphan list. What are the specific conditions that trigger this? What locks are involved? Are there any potential race conditions I should be considering related to concurrent access? I'll start by checking the function definition and look for any clues in its surrounding code about how the system handles orphan inodes and its integration with other parts of the OCFS2 namespace layer. I need to quickly grasp the implications of this function for overall filesystem consistency and recovery. Let's see what we can find.
|
| 55/2 |
2026/05/29 16:56 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/namei.c FirstLine:2633 LineCount:50]
Results: map[Contents:2633: int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
2634: struct inode *inode)
2635: {
2636: char orphan_name[OCFS2_DIO_ORPHAN_PREFIX_LEN + OCFS2_ORPHAN_NAMELEN + 1];
2637: struct inode *orphan_dir_inode = NULL;
2638: struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
2639: struct buffer_head *di_bh = NULL;
2640: int status = 0;
2641: handle_t *handle = NULL;
2642: struct ocfs2_dinode *di = NULL;
2643:
2644: status = ocfs2_inode_lock(inode, &di_bh, 1);
2645: if (status < 0) {
2646: mlog_errno(status);
2647: goto bail;
2648: }
2649:
2650: di = (struct ocfs2_dinode *) di_bh->b_data;
2651: /*
2652: * Another append dio crashed?
2653: * If so, manually recover it first.
2654: */
2655: if (unlikely(di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL))) {
2656: status = ocfs2_truncate_file(inode, di_bh, i_size_read(inode));
2657: if (status < 0) {
2658: if (status != -ENOSPC)
2659: mlog_errno(status);
2660: goto bail_unlock_inode;
2661: }
2662:
2663: status = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2664: if (status < 0) {
2665: mlog_errno(status);
2666: goto bail_unlock_inode;
2667: }
2668: }
2669:
2670: status = ocfs2_prepare_orphan_dir(osb, &orphan_dir_inode,
2671: OCFS2_I(inode)->ip_blkno,
2672: orphan_name,
2673: &orphan_insert,
2674: true);
2675: if (status < 0) {
2676: mlog_errno(status);
2677: goto bail_unlock_inode;
2678: }
2679:
2680: handle = ocfs2_start_trans(osb,
2681: OCFS2_INODE_ADD_TO_ORPHAN_CREDITS);
2682: if (IS_ERR(handle)) {
]
|
| 56/2 |
2026/05/29 16:56 |
llm |
debugger |
0m
Model:
Tokens:
input: 68388
output: 38
thoughts: 65
Thoughts: Okay, let me think this through.
**Analyzing the OCFS2 Truncation and Orphan Inode Removal Sequence**
Hmm, so I'm focusing on the interaction between `ocfs2_truncate_file` and `ocfs2_del_inode_from_orphan`. The crucial point here is the order of operations: `ocfs2_truncate_file` is called *before* the orphan inode removal. That immediately triggers a question: does the `ocfs2_truncate_file` function potentially hold the `EXTENT_ALLOC_SYSTEM_INODE` lock? That's the critical piece of information. If it does, and if we're dealing with a system inode, a tricky race could be going on. It is important to know which locks this code takes, and if there is a risk of a deadlock with the orphan cleanup logic.
Alright, time to get into the code. I need to dive into `ocfs2_truncate_file` and precisely verify its locking behavior. Only by understanding its locking strategy can I confirm if that lock is held at a time that's critical to the removal of orphan inodes. I'll need to pay close attention to the extent allocation system and ensure there's no potential conflict. This is definitely worth a thorough investigation.
|
| 57/2 |
2026/05/29 16:56 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/file.c FirstLine:440 LineCount:100]
Results: map[Contents: 440: struct buffer_head *di_bh,
441: u64 new_i_size)
442: {
443: int status = 0;
444: struct ocfs2_dinode *fe = NULL;
445: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
446:
447: /* We trust di_bh because it comes from ocfs2_inode_lock(), which
448: * already validated it */
449: fe = (struct ocfs2_dinode *) di_bh->b_data;
450:
451: trace_ocfs2_truncate_file((unsigned long long)OCFS2_I(inode)->ip_blkno,
452: (unsigned long long)le64_to_cpu(fe->i_size),
453: (unsigned long long)new_i_size);
454:
455: mlog_bug_on_msg(le64_to_cpu(fe->i_size) != i_size_read(inode),
456: "Inode %llu, inode i_size = %lld != di "
457: "i_size = %llu, i_flags = 0x%x\n",
458: (unsigned long long)OCFS2_I(inode)->ip_blkno,
459: i_size_read(inode),
460: (unsigned long long)le64_to_cpu(fe->i_size),
461: le32_to_cpu(fe->i_flags));
462:
463: if (new_i_size > le64_to_cpu(fe->i_size)) {
464: trace_ocfs2_truncate_file_error(
465: (unsigned long long)le64_to_cpu(fe->i_size),
466: (unsigned long long)new_i_size);
467: status = -EINVAL;
468: mlog_errno(status);
469: goto bail;
470: }
471:
472: down_write(&OCFS2_I(inode)->ip_alloc_sem);
473:
474: ocfs2_resv_discard(&osb->osb_la_resmap,
475: &OCFS2_I(inode)->ip_la_data_resv);
476:
477: /*
478: * The inode lock forced other nodes to sync and drop their
479: * pages, which (correctly) happens even if we have a truncate
480: * without allocation change - ocfs2 cluster sizes can be much
481: * greater than page size, so we have to truncate them
482: * anyway.
483: */
484:
485: if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
486: unmap_mapping_range(inode->i_mapping,
487: new_i_size + PAGE_SIZE - 1, 0, 1);
488: truncate_inode_pages(inode->i_mapping, new_i_size);
489: status = ocfs2_truncate_inline(inode, di_bh, new_i_size,
490: i_size_read(inode), 1);
491: if (status)
492: mlog_errno(status);
493:
494: goto bail_unlock_sem;
495: }
496:
497: /* alright, we're going to need to do a full blown alloc size
498: * change. Orphan the inode so that recovery can complete the
499: * truncate if necessary. This does the task of marking
500: * i_size. */
501: status = ocfs2_orphan_for_truncate(osb, inode, di_bh, new_i_size);
502: if (status < 0) {
503: mlog_errno(status);
504: goto bail_unlock_sem;
505: }
506:
507: unmap_mapping_range(inode->i_mapping, new_i_size + PAGE_SIZE - 1, 0, 1);
508: truncate_inode_pages(inode->i_mapping, new_i_size);
509:
510: status = ocfs2_commit_truncate(osb, inode, di_bh);
511: if (status < 0) {
512: mlog_errno(status);
513: goto bail_unlock_sem;
514: }
515:
516: /* TODO: orphan dir cleanup here. */
517: bail_unlock_sem:
518: up_write(&OCFS2_I(inode)->ip_alloc_sem);
519:
520: bail:
521: if (!status && OCFS2_I(inode)->ip_clusters == 0)
522: status = ocfs2_try_remove_refcount_tree(inode, di_bh);
523:
524: return status;
525: }
526:
527: /*
528: * extend file allocation only here.
529: * we'll update all the disk stuff, and oip->alloc_size
530: *
531: * expect stuff to be locked, a transaction started and enough data /
532: * metadata reservations in the contexts.
533: *
534: * Will return -EAGAIN, and a reason if a restart is needed.
535: * If passed in, *reason will always be set, even in error.
536: */
537: int ocfs2_add_inode_data(struct ocfs2_super *osb,
538: struct inode *inode,
539: u32 *logical_offset,
]
|
| 58/2 |
2026/05/29 16:56 |
llm |
debugger |
0m
Model:
Tokens:
input: 70480
output: 35
thoughts: 1177
Thoughts: **Analyzing OCFS2 Orphan and Allocation Context Dependencies**
Okay, let's break this down. My initial thought process is centered around understanding the locking order, specifically around orphan inodes and the allocation context within the OCFS2 file system. I'm starting by tracing how `ocfs2_truncate_file` and `ocfs2_dio_end_io_write` interact with these systems.
First, I realize that `ocfs2_truncate_file` acquires `ORPHAN_DIR_SYSTEM_INODE` through its call to `ocfs2_orphan_for_truncate`. Crucially, it *doesn't* hold `EXTENT_ALLOC_SYSTEM_INODE`. This means `ocfs2_add_inode_to_orphan` doesn't either. Good.
Now, let's move to `ocfs2_dio_end_io_write`. Here, `meta_ac` (and `data_ac`) are allocated and `EXTENT_ALLOC_SYSTEM_INODE` is acquired within the `ocfs2_lock_allocators` function. Subsequently, the extent is marked as written, the transaction is committed, and then the allocation semaphore (`oi->ip_alloc_sem`) is released. Crucially, *then* `ocfs2_del_inode_from_orphan` is called, and *then* the allocation contexts are freed.
My immediate question is: can we safely reorder the freeing of `meta_ac` and `data_ac` to occur *before* the call to `ocfs2_del_inode_from_orphan`? This is the core of the optimization. This is where I start thinking about the implications. By moving the `ocfs2_free_alloc_context` calls earlier, we could break the dependency, that `EXTENT_ALLOC_SYSTEM_INODE` must be held *before* `ORPHAN_DIR_SYSTEM_INODE` is acquired.
I re-examine the code in `ocfs2_dio_end_io_write`. It's clear that the existing order is: commit transaction, unlock the allocation semaphore, *then* free the allocation contexts. The suggested change is to move the context freeing *before* the call to `ocfs2_del_inode_from_orphan`.
My immediate concern is dependency and if the deallocation information stored in `meta_ac` or `data_ac` are used by the orphan deletion routine.
I see that `ocfs2_run_deallocs` is called *after* `ocfs2_free_alloc_context`, which implies it should not be using any resources from those contexts. I re-check the function.
Alright, what if the orphan deletion fails? I realize that freeing `meta_ac` before the orphan deletion is called won't matter, as there's not a strong dependency. An error is returned, but the allocation context will already have been freed.
The key question is, are there *any* other places in the code where the allocation context locks are held when interacting with orphan inodes? This calls for a check of `ocfs2_orphan_for_truncate`. I need to ensure that the code doesn't create some other unexpected locking dependency.
|
| 59/2 |
2026/05/29 16:56 |
tool |
grepper |
0m
Args: map[Expression:ocfs2_orphan_for_truncate PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/file.c=340=static int ocfs2_cow_file_pos(struct inode *inode,
--
fs/ocfs2/file.c-372-
fs/ocfs2/file.c:373:static int ocfs2_orphan_for_truncate(struct ocfs2_super *osb,
fs/ocfs2/file.c-374- struct inode *inode,
--
fs/ocfs2/file.c=439=int ocfs2_truncate_file(struct inode *inode,
--
fs/ocfs2/file.c-500- * i_size. */
fs/ocfs2/file.c:501: status = ocfs2_orphan_for_truncate(osb, inode, di_bh, new_i_size);
fs/ocfs2/file.c-502- if (status < 0) {
]
|
| 60/2 |
2026/05/29 16:57 |
llm |
debugger |
0m
Model:
Tokens:
input: 72636
output: 37
thoughts: 15
Thoughts: Okay, here's my attempt at summarizing the thought process, as though I were an expert:
**Diving into `ocfs2_orphan_for_truncate`**
Alright, let's get down to brass tacks and dissect this function: `ocfs2_orphan_for_truncate`. From the name alone, I can infer we're dealing with orphan handling, and specifically, the consequences of a truncation operation within the OCFS2 filesystem. My initial assumption is that this function will be crucial for maintaining data consistency and preventing orphaned inodes or blocks after a file's size is reduced. It's likely involved in updating the orphan list, which keeps track of inodes that need special attention after a truncation, perhaps because they're no longer directly reachable through the filesystem's directory structure. We'll be looking to see how it manages metadata updates, block allocation/deallocation (if necessary), and synchronization mechanisms to ensure atomicity. Depending on where this function sits, it likely ties into the bigger picture of crash recovery, too. My experience tells me that correctly handling orphan inodes is critical to the robustness of a distributed filesystem like OCFS2; it's a potential Achilles' heel if not implemented properly. So, I expect to see careful attention paid to locking and error handling.
|
| 61/2 |
2026/05/29 16:57 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/file.c FirstLine:373 LineCount:50]
Results: map[Contents: 373: static int ocfs2_orphan_for_truncate(struct ocfs2_super *osb,
374: struct inode *inode,
375: struct buffer_head *fe_bh,
376: u64 new_i_size)
377: {
378: int status;
379: handle_t *handle;
380: struct ocfs2_dinode *di;
381: u64 cluster_bytes;
382:
383: /*
384: * We need to CoW the cluster contains the offset if it is reflinked
385: * since we will call ocfs2_zero_range_for_truncate later which will
386: * write "0" from offset to the end of the cluster.
387: */
388: status = ocfs2_cow_file_pos(inode, fe_bh, new_i_size);
389: if (status) {
390: mlog_errno(status);
391: return status;
392: }
393:
394: /* TODO: This needs to actually orphan the inode in this
395: * transaction. */
396:
397: handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
398: if (IS_ERR(handle)) {
399: status = PTR_ERR(handle);
400: mlog_errno(status);
401: goto out;
402: }
403:
404: status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), fe_bh,
405: OCFS2_JOURNAL_ACCESS_WRITE);
406: if (status < 0) {
407: mlog_errno(status);
408: goto out_commit;
409: }
410:
411: /*
412: * Do this before setting i_size.
413: */
414: cluster_bytes = ocfs2_align_bytes_to_clusters(inode->i_sb, new_i_size);
415: status = ocfs2_zero_range_for_truncate(inode, handle, new_i_size,
416: cluster_bytes);
417: if (status) {
418: mlog_errno(status);
419: goto out_commit;
420: }
421:
422: i_size_write(inode, new_i_size);
]
|
| 62/2 |
2026/05/29 16:57 |
llm |
debugger |
0m
Model:
Tokens:
input: 73717
output: 37
thoughts: 112
Thoughts: **Analyzing Orphaned Inode Handling in OCFS2**
Okay, hold on a second. This is important. I'm looking at the `ocfs2_orphan_for_truncate` function, and something isn't right. It explicitly *doesn't* acquire `ORPHAN_DIR_SYSTEM_INODE`, which is a key lock in this whole process. The code even has a comment that says, "/* TODO: This needs to actually orphan the inode in this transaction. */". So, essentially, it's not even doing the actual orphan operation within that function, which is⦠concerning, to say the least. This seems like a potential race condition or oversight that could lead to data integrity issues during truncate operations.
But then, what *is* responsible for adding the inode to the orphan list? I recall `ocfs2_add_inode_to_orphan` and yes, that *does* correctly acquire the `ORPHAN_DIR_SYSTEM_INODE` lock. This is the critical piece! However, now I need to backtrack and see precisely *where* `ocfs2_add_inode_to_orphan` is called from. I have to understand the flow, the conditions, and the critical sequence of operations that lead to an inode being declared orphaned, especially regarding truncate operations. The call path is the key to understanding this. I have to trace back now.
|
| 63/2 |
2026/05/29 16:57 |
tool |
grepper |
0m
Args: map[Expression:ocfs2_add_inode_to_orphan PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/aops.c=2117=static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
--
fs/ocfs2/aops.c-2186- */
fs/ocfs2/aops.c:2187: ret = ocfs2_add_inode_to_orphan(osb, inode);
fs/ocfs2/aops.c-2188- if (ret < 0) {
--
fs/ocfs2/namei.c=2514=int ocfs2_create_inode_in_orphan(struct inode *dir,
--
fs/ocfs2/namei.c-2632-
fs/ocfs2/namei.c:2633:int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.c-2634- struct inode *inode)
--
fs/ocfs2/namei.h=26=int ocfs2_create_inode_in_orphan(struct inode *dir,
--
fs/ocfs2/namei.h-28- struct inode **new_inode);
fs/ocfs2/namei.h:29:int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.h-30- struct inode *inode);
]
|
| 64/2 |
2026/05/29 16:57 |
llm |
debugger |
0m
Model:
Tokens:
input: 74538
output: 40
thoughts: 17
Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, in the first person and targeted towards an expert:
**Diving into `ocfs2_dio_wr_get_block`**
Alright, time to dig into `ocfs2_dio_wr_get_block`. I need to refresh my memory on exactly how the OCFS2 direct I/O write block mapping process is handled. Let me see... I want to understand the specifics of how it interacts with the underlying block device, especially in the context of concurrent access and potential data coherency issues. I know it's crucial for performance, but I need to make sure I'm solid on the intricacies. The core of this probably involves looking at how the function calculates the physical block addresses, manages the extent mapping, and handles any potential allocation and deallocation within the OCFS2 file system. What are the key data structures and locking primitives used here? And how does it interact with the journaling layer, if at all, for atomicity? I need to remember the implications of different I/O sizes and how they impact the block mapping logic. Let me see where I left off last time... This is where the rubber meets the road in terms of high-performance OCFS2 operation. I have to think about this from a practical standpoint: what are the implications on error handling, and what edge cases exist that I need to keep in mind? I need to get a really good handle on it.
|
| 65/2 |
2026/05/29 16:57 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/aops.c FirstLine:2117 LineCount:100]
Results: map[Contents:2117: static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
2118: struct buffer_head *bh_result, int create)
2119: {
2120: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2121: struct ocfs2_inode_info *oi = OCFS2_I(inode);
2122: struct ocfs2_write_ctxt *wc;
2123: struct ocfs2_write_cluster_desc *desc = NULL;
2124: struct ocfs2_dio_write_ctxt *dwc = NULL;
2125: struct buffer_head *di_bh = NULL;
2126: u64 p_blkno;
2127: unsigned int i_blkbits = inode->i_sb->s_blocksize_bits;
2128: loff_t pos = iblock << i_blkbits;
2129: sector_t endblk = (i_size_read(inode) - 1) >> i_blkbits;
2130: unsigned len, total_len = bh_result->b_size;
2131: int ret = 0, first_get_block = 0;
2132:
2133: len = osb->s_clustersize - (pos & (osb->s_clustersize - 1));
2134: len = min(total_len, len);
2135:
2136: /*
2137: * bh_result->b_size is count in get_more_blocks according to write
2138: * "pos" and "end", we need map twice to return different buffer state:
2139: * 1. area in file size, not set NEW;
2140: * 2. area out file size, set NEW.
2141: *
2142: * iblock endblk
2143: * |--------|---------|---------|---------
2144: * |<-------area in file------->|
2145: */
2146:
2147: if ((iblock <= endblk) &&
2148: ((iblock + ((len - 1) >> i_blkbits)) > endblk))
2149: len = (endblk - iblock + 1) << i_blkbits;
2150:
2151: mlog(0, "get block of %llu at %llu:%u req %u\n",
2152: inode->i_ino, pos, len, total_len);
2153:
2154: /*
2155: * Because we need to change file size in ocfs2_dio_end_io_write(), or
2156: * we may need to add it to orphan dir. So can not fall to fast path
2157: * while file size will be changed.
2158: */
2159: if (pos + total_len <= i_size_read(inode)) {
2160:
2161: /* This is the fast path for re-write. */
2162: ret = ocfs2_lock_get_block(inode, iblock, bh_result, create);
2163: if (buffer_mapped(bh_result) &&
2164: !buffer_new(bh_result) &&
2165: ret == 0)
2166: goto out;
2167:
2168: /* Clear state set by ocfs2_get_block. */
2169: bh_result->b_state = 0;
2170: }
2171:
2172: dwc = ocfs2_dio_alloc_write_ctx(bh_result, &first_get_block);
2173: if (unlikely(dwc == NULL)) {
2174: ret = -ENOMEM;
2175: mlog_errno(ret);
2176: goto out;
2177: }
2178:
2179: if (ocfs2_clusters_for_bytes(inode->i_sb, pos + total_len) >
2180: ocfs2_clusters_for_bytes(inode->i_sb, i_size_read(inode)) &&
2181: !dwc->dw_orphaned) {
2182: /*
2183: * when we are going to alloc extents beyond file size, add the
2184: * inode to orphan dir, so we can recall those spaces when
2185: * system crashed during write.
2186: */
2187: ret = ocfs2_add_inode_to_orphan(osb, inode);
2188: if (ret < 0) {
2189: mlog_errno(ret);
2190: goto out;
2191: }
2192: dwc->dw_orphaned = 1;
2193: }
2194:
2195: ret = ocfs2_inode_lock(inode, &di_bh, 1);
2196: if (ret) {
2197: mlog_errno(ret);
2198: goto out;
2199: }
2200:
2201: down_write(&oi->ip_alloc_sem);
2202:
2203: if (first_get_block) {
2204: if (ocfs2_sparse_alloc(osb))
2205: ret = ocfs2_zero_tail(inode, di_bh, pos);
2206: else
2207: ret = ocfs2_expand_nonsparse_inode(inode, di_bh, pos,
2208: total_len, NULL);
2209: if (ret < 0) {
2210: mlog_errno(ret);
2211: goto unlock;
2212: }
2213: }
2214:
2215: ret = ocfs2_write_begin_nolock(inode->i_mapping, pos, len,
2216: OCFS2_WRITE_DIRECT, NULL,
]
|
| 66/2 |
2026/05/29 16:57 |
llm |
debugger |
0m
Model:
Tokens:
input: 76594
output: 39
thoughts: 2403
Thoughts: **Circular Dependency Identified in OCFS2 Direct I/O Write Path**
Okay, let me walk through this. I started by noticing that `ocfs2_dio_wr_get_block` calls `ocfs2_add_inode_to_orphan`, which *does* acquire `ORPHAN_DIR_SYSTEM_INODE`. I then, more importantly, checked to see if `ocfs2_dio_wr_get_block` held `EXTENT_ALLOC_SYSTEM_INODE`, and found that it did not. I tracked down the relevant code paths and, more importantly, confirmed with the lockdep report that the dependency arose when `ocfs2_del_inode_from_orphan`, called within `ocfs2_dio_end_io_write`, acquired `ORPHAN_DIR_SYSTEM_INODE` while `EXTENT_ALLOC_SYSTEM_INODE` was held, acquired via `ocfs2_lock_allocators`.
Specifically, `ocfs2_dio_end_io_write` calls `ocfs2_lock_allocators`, which *does* hold `EXTENT_ALLOC_SYSTEM_INODE` and then calls `ocfs2_del_inode_from_orphan`. I know that `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` is established in `ocfs2_mknod`, and `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE` in `ocfs2_wipe_inode`. *This* is the circular dependency. We have a deadlock waiting to happen: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`.
To fix this, I think we can break the dependency by freeing `data_ac` and `meta_ac` (which hold `EXTENT_ALLOC_SYSTEM_INODE`) before calling `ocfs2_del_inode_from_orphan` in `ocfs2_dio_end_io_write`. I need to double-check that it is safe to do. I need to make sure that even if `ocfs2_lock_allocators` fails, `data_ac` and `meta_ac` are properly handled. The proposed change addresses this, as it checks if `data_ac` and `meta_ac` are valid before calling the free function.
I also checked other call sites for this. `ocfs2_add_inode_to_orphan` does *not* hold `EXTENT_ALLOC_SYSTEM_INODE` while acquiring `ORPHAN_DIR_SYSTEM_INODE`, so no problem there. `ocfs2_truncate_file` doesn't seem to be a problem either because it goes through a different path. Finally, `ocfs2_remove_inode` relies on `ocfs2_wipe_inode` to hold `ORPHAN_DIR_SYSTEM_INODE` before calling `ocfs2_remove_inode`, so that also is not a problem.
Therefore, the fix is straightforward. I'm confident that the proposed change in `ocfs2_dio_end_io_write` will break the dependency and prevent the deadlock.
|
| 67/2 |
2026/05/29 16:58 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/namei.c FirstLine:2480 LineCount:50]
Results: map[Contents:2480:
2481: ret = __ocfs2_prepare_orphan_dir(orphan_dir, orphan_dir_bh,
2482: di_blkno, orphan_name, orphan_insert,
2483: false);
2484: if (ret < 0) {
2485: mlog_errno(ret);
2486: goto out;
2487: }
2488:
2489: out:
2490: if (ret == 0) {
2491: *ret_orphan_dir = orphan_dir;
2492: *ret_di_blkno = di_blkno;
2493: *ret_inode_ac = inode_ac;
2494: /*
2495: * orphan_name and orphan_insert are already up to
2496: * date via prepare_orphan_dir
2497: */
2498: } else {
2499: /* Unroll reserve_new_inode* */
2500: if (inode_ac)
2501: ocfs2_free_alloc_context(inode_ac);
2502:
2503: /* Unroll orphan dir locking */
2504: inode_unlock(orphan_dir);
2505: ocfs2_inode_unlock(orphan_dir, 1);
2506: iput(orphan_dir);
2507: }
2508:
2509: brelse(orphan_dir_bh);
2510:
2511: return ret;
2512: }
2513:
2514: int ocfs2_create_inode_in_orphan(struct inode *dir,
2515: int mode,
2516: struct inode **new_inode)
2517: {
2518: int status, did_quota_inode = 0;
2519: struct inode *inode = NULL;
2520: struct inode *orphan_dir = NULL;
2521: struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
2522: handle_t *handle = NULL;
2523: char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
2524: struct buffer_head *parent_di_bh = NULL;
2525: struct buffer_head *new_di_bh = NULL;
2526: struct ocfs2_alloc_context *inode_ac = NULL;
2527: struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
2528: u64 di_blkno, suballoc_loc;
2529: u16 suballoc_bit;
]
|
| 68/2 |
2026/05/29 16:58 |
llm |
debugger |
0m
Model:
Tokens:
input: 80525
output: 34
thoughts: 13
Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:
**OCFS2 Orphan Deletion: Time to Investigate**
Right, let's take a look at `ocfs2_orphan_del`. I need to refresh my memory on the orphan deletion process within OCFS2. It's probably been a while since I last looked closely at the details of how it handles file system inconsistencies and recovers from them. I'm especially interested in understanding the current implementation β any recent changes or performance considerations that might be relevant. This function is critical for maintaining data integrity, so a deep understanding is always paramount. Time to dig in and re-evaluate its inner workings.
|
| 69/2 |
2026/05/29 16:58 |
tool |
grepper |
0m
Args: map[Expression:int ocfs2_orphan_del PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/namei.c=2245=static int ocfs2_orphan_add(struct ocfs2_super *osb,
--
fs/ocfs2/namei.c-2346-/* unlike orphan_add, we expect the orphan dir to already be locked here. */
fs/ocfs2/namei.c:2347:int ocfs2_orphan_del(struct ocfs2_super *osb,
fs/ocfs2/namei.c-2348- handle_t *handle,
--
fs/ocfs2/namei.h=18=struct dentry *ocfs2_get_parent(struct dentry *child);
fs/ocfs2/namei.h-19-
fs/ocfs2/namei.h:20:int ocfs2_orphan_del(struct ocfs2_super *osb,
fs/ocfs2/namei.h-21- handle_t *handle,
]
|
| 70/2 |
2026/05/29 16:58 |
llm |
debugger |
0m
Model:
Tokens:
input: 80981
output: 40
thoughts: 39
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Checking Orphan Handling Consistency**
Right, `ocfs2_orphan_del` *definitely* anticipates that the orphan directory is already under lock. That's standard practice, part of the overall locking strategy for managing orphan inodes. Iβd expect nothing less, given the delicate dance of metadata changes and the potential for concurrent operations. The locking is crucial for ensuring data integrity during the deletion process.
Hold on... Now that I think about it... What about `ocfs2_create_inode_in_orphan`? Does *that* function also ensure the orphan directory is locked before attempting to do its work? If so, this is handled well. If not, then we have a potential race condition which needs to be carefully addressed. I better check the locking semantics there immediately, because that could be a significant vulnerability if not correctly implemented.
|
| 71/2 |
2026/05/29 16:58 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/namei.c FirstLine:2514 LineCount:100]
Results: map[Contents:2514: int ocfs2_create_inode_in_orphan(struct inode *dir,
2515: int mode,
2516: struct inode **new_inode)
2517: {
2518: int status, did_quota_inode = 0;
2519: struct inode *inode = NULL;
2520: struct inode *orphan_dir = NULL;
2521: struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
2522: handle_t *handle = NULL;
2523: char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
2524: struct buffer_head *parent_di_bh = NULL;
2525: struct buffer_head *new_di_bh = NULL;
2526: struct ocfs2_alloc_context *inode_ac = NULL;
2527: struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
2528: u64 di_blkno, suballoc_loc;
2529: u16 suballoc_bit;
2530:
2531: status = ocfs2_inode_lock(dir, &parent_di_bh, 1);
2532: if (status < 0) {
2533: if (status != -ENOENT)
2534: mlog_errno(status);
2535: return status;
2536: }
2537:
2538: status = ocfs2_prep_new_orphaned_file(dir, parent_di_bh,
2539: orphan_name, &orphan_dir,
2540: &di_blkno, &orphan_insert, &inode_ac);
2541: if (status < 0) {
2542: if (status != -ENOSPC)
2543: mlog_errno(status);
2544: goto leave;
2545: }
2546:
2547: inode = ocfs2_get_init_inode(dir, mode);
2548: if (IS_ERR(inode)) {
2549: status = PTR_ERR(inode);
2550: inode = NULL;
2551: mlog_errno(status);
2552: goto leave;
2553: }
2554:
2555: handle = ocfs2_start_trans(osb, ocfs2_mknod_credits(osb->sb, 0, 0));
2556: if (IS_ERR(handle)) {
2557: status = PTR_ERR(handle);
2558: handle = NULL;
2559: mlog_errno(status);
2560: goto leave;
2561: }
2562:
2563: status = dquot_alloc_inode(inode);
2564: if (status)
2565: goto leave;
2566: did_quota_inode = 1;
2567:
2568: status = ocfs2_claim_new_inode_at_loc(handle, dir, inode_ac,
2569: &suballoc_loc,
2570: &suballoc_bit, di_blkno);
2571: if (status < 0) {
2572: mlog_errno(status);
2573: goto leave;
2574: }
2575:
2576: clear_nlink(inode);
2577: /* do the real work now. */
2578: status = __ocfs2_mknod_locked(dir, inode,
2579: 0, &new_di_bh, handle,
2580: inode_ac, di_blkno, suballoc_loc,
2581: suballoc_bit);
2582: if (status < 0) {
2583: mlog_errno(status);
2584: goto leave;
2585: }
2586:
2587: status = ocfs2_orphan_add(osb, handle, inode, new_di_bh, orphan_name,
2588: &orphan_insert, orphan_dir, false);
2589: if (status < 0) {
2590: mlog_errno(status);
2591: goto leave;
2592: }
2593:
2594: /* get open lock so that only nodes can't remove it from orphan dir. */
2595: status = ocfs2_open_lock(inode);
2596: if (status < 0)
2597: mlog_errno(status);
2598:
2599: insert_inode_hash(inode);
2600: leave:
2601: if (status < 0 && did_quota_inode)
2602: dquot_free_inode(inode);
2603: if (handle)
2604: ocfs2_commit_trans(osb, handle);
2605:
2606: if (orphan_dir) {
2607: /* This was locked for us in ocfs2_prepare_orphan_dir() */
2608: ocfs2_inode_unlock(orphan_dir, 1);
2609: inode_unlock(orphan_dir);
2610: iput(orphan_dir);
2611: }
2612:
2613: if ((status < 0) && inode) {
]
|
| 72/2 |
2026/05/29 16:58 |
llm |
debugger |
0m
Model:
Tokens:
input: 82790
output: 39
thoughts: 49
Thoughts: Here's my thought process, as if I were analyzing this code:
**Diving into the Orphaned File Creation**
Okay, so I'm tracking the inode creation process within OCFS2, specifically for orphaned files. I see `ocfs2_create_inode_in_orphan` in the call stack. Interesting... it's the gateway for orphaned file creation. That means I need to understand what happens inside that function.
Aha! `ocfs2_create_inode_in_orphan` calls `ocfs2_prep_new_orphaned_file`. This is key. The `prep` function is likely where the *actual* setup work for the new orphaned inode is done. I'm going to shift my focus there. `ocfs2_prep_new_orphaned_file` holds the next crucial piece of this puzzle. I need to examine its implementation to truly understand the mechanics of orphaned file creation within the filesystem. Let's see what that function is doing.
|
| 73/2 |
2026/05/29 16:58 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/namei.c FirstLine:2445 LineCount:50]
Results: map[Contents:2445: static int ocfs2_prep_new_orphaned_file(struct inode *dir,
2446: struct buffer_head *dir_bh,
2447: char *orphan_name,
2448: struct inode **ret_orphan_dir,
2449: u64 *ret_di_blkno,
2450: struct ocfs2_dir_lookup_result *orphan_insert,
2451: struct ocfs2_alloc_context **ret_inode_ac)
2452: {
2453: int ret;
2454: u64 di_blkno;
2455: struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
2456: struct inode *orphan_dir = NULL;
2457: struct buffer_head *orphan_dir_bh = NULL;
2458: struct ocfs2_alloc_context *inode_ac = NULL;
2459:
2460: ret = ocfs2_lookup_lock_orphan_dir(osb, &orphan_dir, &orphan_dir_bh);
2461: if (ret < 0) {
2462: mlog_errno(ret);
2463: return ret;
2464: }
2465:
2466: /* reserve an inode spot */
2467: ret = ocfs2_reserve_new_inode(osb, &inode_ac);
2468: if (ret < 0) {
2469: if (ret != -ENOSPC)
2470: mlog_errno(ret);
2471: goto out;
2472: }
2473:
2474: ret = ocfs2_find_new_inode_loc(dir, dir_bh, inode_ac,
2475: &di_blkno);
2476: if (ret) {
2477: mlog_errno(ret);
2478: goto out;
2479: }
2480:
2481: ret = __ocfs2_prepare_orphan_dir(orphan_dir, orphan_dir_bh,
2482: di_blkno, orphan_name, orphan_insert,
2483: false);
2484: if (ret < 0) {
2485: mlog_errno(ret);
2486: goto out;
2487: }
2488:
2489: out:
2490: if (ret == 0) {
2491: *ret_orphan_dir = orphan_dir;
2492: *ret_di_blkno = di_blkno;
2493: *ret_inode_ac = inode_ac;
2494: /*
]
|
| 74/2 |
2026/05/29 16:58 |
llm |
debugger |
0m
Model:
Tokens:
input: 83864
output: 36
thoughts: 1280
Thoughts: **Analyzing and Fixing a Circular Locking Dependency in OCFS2**
Okay, let's break this down. I see that `ocfs2_prep_new_orphaned_file` calls `ocfs2_lookup_lock_orphan_dir`, which grabs the `ORPHAN_DIR_SYSTEM_INODE` lock. Then, it calls `ocfs2_reserve_new_inode`, and that acquires the `INODE_ALLOC_SYSTEM_INODE`. So, we've got `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE` here as well, similar to what happens in `ocfs2_wipe_inode`.
Aha, that outlines the circular dependency: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` (in `ocfs2_mknod`), then `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` (in `ocfs2_dio_end_io_write`), and finally `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE` (in both `ocfs2_wipe_inode` and now, `ocfs2_prep_new_orphaned_file`).
To break this, the obvious place to look is `ocfs2_dio_end_io_write`. If we release `EXTENT_ALLOC_SYSTEM_INODE` *before* acquiring `ORPHAN_DIR_SYSTEM_INODE`, we should be good.
Let's verify that `ocfs2_dio_end_io_write` is the *only* place establishing this `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` dependency. I'll need to check where `ocfs2_lock_allocators` is called, and *then* `ORPHAN_DIR_SYSTEM_INODE` is acquired.
`ocfs2_lock_allocators` gets called in `ocfs2_write_begin_nolock`, `ocfs2_dio_end_io_write` (the suspect), `ocfs2_dx_dir_rebalance`, `ocfs2_extend_allocation`, and `ocfs2_rm_xattr_cluster`. Let's run through these:
* `ocfs2_write_begin_nolock`: Calls `ocfs2_lock_allocators`, then `ocfs2_start_trans`, `ocfs2_write_cluster_by_desc`, and frees `data_ac` and `meta_ac`. No `ORPHAN_DIR_SYSTEM_INODE`. Good.
* `ocfs2_dx_dir_rebalance`: Calls `ocfs2_lock_allocators`, then `ocfs2_start_trans`, `ocfs2_claim_metadata`, frees `data_ac` and `meta_ac`. Still no `ORPHAN_DIR_SYSTEM_INODE`.
* `ocfs2_extend_allocation`: Calls `ocfs2_lock_allocators`, then `ocfs2_start_trans`, `ocfs2_claim_metadata`, frees `data_ac` and `meta_ac`. No `ORPHAN_DIR_SYSTEM_INODE`.
* `ocfs2_rm_xattr_cluster`: Calls `ocfs2_lock_allocators`, then `ocfs2_start_trans`, `ocfs2_claim_metadata`, frees `meta_ac`. No `ORPHAN_DIR_SYSTEM_INODE`.
Alright, it looks like `ocfs2_dio_end_io_write` is indeed the *only* place. That's excellent news. The plan is sound. Freeing `data_ac` and `meta_ac` before `ocfs2_del_inode_from_orphan` should resolve the dependency.
Here's the fix: I need to move the freeing of the allocation contexts *before* calling `ocfs2_del_inode_from_orphan`. Specifically, in `fs/ocfs2/aops.c`, the `ocfs2_dio_end_io_write` function, I have to ensure that `ocfs2_free_alloc_context` of `data_ac` and `meta_ac` are done *before* `ocfs2_del_inode_from_orphan` is called.
Wait, looking at the code, `ocfs2_run_deallocs` uses `&dealloc`. The `dealloc` structure is populated during `
|
| 75/2 |
2026/05/29 16:58 |
tool |
grepper |
0m
Args: map[Expression:int ocfs2_run_deallocs PathPrefix:fs/ocfs2/]
Results: map[Output:fs/ocfs2/alloc.c=6521=static int ocfs2_free_cached_clusters(struct ocfs2_super *osb,
--
fs/ocfs2/alloc.c-6572-
fs/ocfs2/alloc.c:6573:int ocfs2_run_deallocs(struct ocfs2_super *osb,
fs/ocfs2/alloc.c-6574- struct ocfs2_cached_dealloc_ctxt *ctxt)
--
fs/ocfs2/alloc.h=201=static inline int ocfs2_dealloc_has_cluster(struct ocfs2_cached_dealloc_ctxt *c)
--
fs/ocfs2/alloc.h-204-}
fs/ocfs2/alloc.h:205:int ocfs2_run_deallocs(struct ocfs2_super *osb,
fs/ocfs2/alloc.h-206- struct ocfs2_cached_dealloc_ctxt *ctxt);
]
|
| 76/2 |
2026/05/29 16:58 |
llm |
debugger |
0m
Model:
Tokens:
input: 86471
output: 38
thoughts: 15
Thoughts: Okay, here's my attempt at summarizing the thought process, as if I were considering the `ocfs2_run_deallocs` function, keeping in mind I'm an expert in the field:
**Diving into `ocfs2_run_deallocs`**
Alright, let's get into this. I'm taking a look at `ocfs2_run_deallocs`, so that means I'm probably dealing with either inode deallocation or potentially block deallocation in OCFS2. Immediately, I'm thinking about the context β what's triggering this? Is it a forced unmount, a regular file deletion, a metadata operation, or something else entirely? I need to understand the call path. Where is this function being called from, and under what lock contexts? That's going to be crucial for understanding potential race conditions and the overall performance implications.
My mind immediately jumps to the data structures involved: What queues or lists are likely being processed within this function? I'm expecting to see references to inode lists or block lists, the structures that hold the information of what needs to be freed. I need to understand how these lists are being managed and if there are any critical sections being used to synchronize access to these lists.
I'm thinking about the potential for blocking. Is this function going to be synchronous or asynchronous? Are there any I/O operations involved that could stall things, or is this all in-memory metadata manipulation? If it *is* synchronous, what locks need to be held, and what is the potential impact on other operations that might be waiting? If it's asynchronous, how is this handled, and what are the implications for crash recovery and consistency?
I'm also looking for any opportunities for optimization. Are there any batching strategies used? Can we consolidate multiple deallocation requests into a single I/O operation to reduce overhead? Any potential for parallelization? I'm always thinking about performance, and deallocation is a critical path for responsiveness. I'll need to look at any logging and debugging statements, what information is being logged and if the log level is appropriate. I'll be keeping an eye out for any specific error paths and how they're handled to get a better feel of the robustness of the function.
And finally, I'll be searching for any potential gotchas. Are there any corner cases that might be missed? What about the handling of orphaned inodes or blocks? Is there any special logic for handling extent metadata that might need to be freed? Are there any potential memory leaks or corruption issues that I should be on the lookout for? I'm going to look for any comments that might give some insight.
Time to dive in. Let's see what's actually going on.
|
| 77/2 |
2026/05/29 16:58 |
tool |
read-file |
0m
Args: map[File:fs/ocfs2/alloc.c FirstLine:6573 LineCount:50]
Results: map[Contents:6573: int ocfs2_run_deallocs(struct ocfs2_super *osb,
6574: struct ocfs2_cached_dealloc_ctxt *ctxt)
6575: {
6576: int ret = 0, ret2;
6577: struct ocfs2_per_slot_free_list *fl;
6578:
6579: if (!ctxt)
6580: return 0;
6581:
6582: while (ctxt->c_first_suballocator) {
6583: fl = ctxt->c_first_suballocator;
6584:
6585: if (fl->f_first) {
6586: trace_ocfs2_run_deallocs(fl->f_inode_type,
6587: fl->f_slot);
6588: ret2 = ocfs2_free_cached_blocks(osb,
6589: fl->f_inode_type,
6590: fl->f_slot,
6591: fl->f_first);
6592: if (ret2)
6593: mlog_errno(ret2);
6594: if (!ret)
6595: ret = ret2;
6596: }
6597:
6598: ctxt->c_first_suballocator = fl->f_next_suballocator;
6599: kfree(fl);
6600: }
6601:
6602: if (ctxt->c_global_allocator) {
6603: ret2 = ocfs2_free_cached_clusters(osb,
6604: ctxt->c_global_allocator);
6605: if (ret2)
6606: mlog_errno(ret2);
6607: if (!ret)
6608: ret = ret2;
6609:
6610: ctxt->c_global_allocator = NULL;
6611: }
6612:
6613: return ret;
6614: }
6615:
6616: static struct ocfs2_per_slot_free_list *
6617: ocfs2_find_per_slot_free_list(int type,
6618: int slot,
6619: struct ocfs2_cached_dealloc_ctxt *ctxt)
6620: {
6621: struct ocfs2_per_slot_free_list *fl = ctxt->c_first_suballocator;
6622:
]
|
| 78/2 |
2026/05/29 16:58 |
llm |
debugger |
0m
Model:
Tokens:
input: 87836
output: 1257
thoughts: 4695
Thoughts: **Summary of the Lockdep Issue and Fix**
Okay, so here's the deal, as I understand it. We've got a lockdep issue surfacing in OCFS2, specifically related to how we handle system inode locks. There are three key locks in play here:
1. `INODE_ALLOC_SYSTEM_INODE`
2. `EXTENT_ALLOC_SYSTEM_INODE`
3. `ORPHAN_DIR_SYSTEM_INODE`
The lockdep report highlights a circular dependency among these. Let's break down how this circular chain forms:
* **Dependency 1: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE`**: This dependency shows up during `ocfs2_mknod()` in `fs/ocfs2/namei.c`, at line 351. In this function, we first call `ocfs2_reserve_new_inode()` (ultimately via `ocfs2_reserve_suballoc_bits()`, which then acquires the `INODE_ALLOC_SYSTEM_INODE` lock. Then, the next step in this path is `ocfs2_reserve_new_metadata_blocks()`, which subsequently acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. This leads to the first dependency.
* **Dependency 2: `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`**: The most important dependency is with `ocfs2_dio_end_io_write()` which can be found in `fs/ocfs2/aops.c` line 2379. When allocating metadata blocks for unwritten extents, we call `ocfs2_lock_allocators()`, which acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock (stored in the `meta_ac` context). Then, if the inode is orphaned, we call `ocfs2_del_inode_from_orphan()`. `ocfs2_del_inode_from_orphan()` acquires `ORPHAN_DIR_SYSTEM_INODE`. Crucially, `meta_ac` is only freed at the end of the function. This means the lock associated with `EXTENT_ALLOC_SYSTEM_INODE` is held while `ORPHAN_DIR_SYSTEM_INODE` is acquired.
* **Dependency 3: `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`**: In `ocfs2_wipe_inode()` in `fs/ocfs2/inode.c`, the `ORPHAN_DIR_SYSTEM_INODE` lock is acquired first. Then, we call `ocfs2_remove_inode()` to free the inode, acquiring the `INODE_ALLOC_SYSTEM_INODE` lock. (The same dependency can be found in `ocfs2_prep_new_orphaned_file()`).
This sequence creates a circular locking order: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`.
The solution here involves breaking that circular dependency, and it's quite simple. We need to release the `EXTENT_ALLOC_SYSTEM_INODE` lock *before* acquiring the `ORPHAN_DIR_SYSTEM_INODE` lock in `ocfs2_dio_end_io_write()`. We can safely free the allocation contexts (`data_ac` and `meta_ac`) which hold the `EXTENT_ALLOC_SYSTEM_INODE` lock *before* the call to `ocfs2_del_inode_from_orphan()`. This is because the transaction which created these locks has already been commited and the allocation semaphore released, hence these resources are no longer needed.
Here's the code snippet demonstrating the fix, with the relevant changes in `fs/ocfs2/aops.c`:
```c
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2372,6 +2372,16 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+
|
| 79/1 |
2026/05/29 16:59 |
action |
kernel-scratch-checkouter |
0m
Results: map[KernelScratchSrc:/app/workdir/cache/tmp/tmp1500867002]
|
| 80/1 |
2026/05/29 16:59 |
loop |
|
28m
|
| 81/2 |
2026/05/29 16:59 |
iteration |
0 |
28m
|
| 82/3 |
2026/05/29 16:59 |
agent |
patch-generator |
1m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with creating a fix for a kernel bug.
You will be given a crash report, and an initial explanation of the root cause done by another
kernel expert.
Use the codeeditor tool to do code edits.
Note: you will not see your changes when looking at the code using codesearch tools.
Use the patch-diff tool to review the modifications you applied.
Your final reply should contain explanation of what you did in the patch and why
(details not present in the initial explanation of the bug).
Your fix must not just prevent the given crash, but also be the best fix for the underlying
root cause from the software engineering point of view. There can be several ways to fix the
same bug. Consider alternatives, and pick the best one. For example, additional checks may be
added at different locations/functions, it's usually better to place them earlier in the
execution to avoid multiple checks at various locations later.
Frequently the same coding mistake is done in several locations in the source code.
Check if your fix should be extended/applied to similar cases around to fix other similar bugs.
But don't go too wide, don't try to fix problems kernel-wide, fix similar issues
in the same file only.
If you are changing post-conditions of a function, consider all callers of the functions,
and if they need to be updated to handle new post-conditions. For example, if you make
a function that previously never returned a NULL, return NULL, consider if callers
need to be updated to handle NULL return value.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #1 Not tainted
------------------------------------------------------
syz-executor/6069 is trying to acquire lock:
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
but task is already holding lock:
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_del_inode_from_orphan+0x12e/0x7a0 fs/ocfs2/namei.c:2728
ocfs2_dio_end_io_write fs/ocfs2/aops.c:2379 [inline]
ocfs2_dio_end_io+0xf9c/0x1370 fs/ocfs2/aops.c:2418
dio_complete+0x25b/0x790 fs/direct-io.c:281
__blockdev_direct_IO+0x2e5d/0x34e0 fs/direct-io.c:1303
ocfs2_direct_IO+0x251/0x2c0 fs/ocfs2/aops.c:2455
generic_file_direct_write+0x1db/0x3e0 mm/filemap.c:4259
__generic_file_write_iter+0x11d/0x230 mm/filemap.c:4428
ocfs2_file_write_iter+0x1663/0x1e70 fs/ocfs2/file.c:2476
do_iter_readv_writev+0x619/0x8c0 fs/read_write.c:-1
vfs_writev+0x33c/0x990 fs/read_write.c:1059
do_writev+0x154/0x2e0 fs/read_write.c:1105
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_reserve_suballoc_bits+0x16d/0x4840 fs/ocfs2/suballoc.c:882
ocfs2_reserve_new_metadata_blocks+0x415/0x9a0 fs/ocfs2/suballoc.c:1078
ocfs2_mknod+0x10f3/0x2260 fs/ocfs2/namei.c:351
ocfs2_create+0x195/0x460 fs/ocfs2/namei.c:677
lookup_open fs/namei.c:4511 [inline]
open_last_lookups fs/namei.c:4611 [inline]
path_openat+0x1395/0x3860 fs/namei.c:4855
do_file_open+0x23e/0x4a0 fs/namei.c:4887
do_sys_openat2+0x113/0x200 fs/open.c:1364
do_sys_open fs/open.c:1370 [inline]
__do_sys_openat fs/open.c:1386 [inline]
__se_sys_openat fs/open.c:1381 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
*** DEADLOCK ***
4 locks held by syz-executor/6069:
#0: ffff8881161a4410 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:1074 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: __start_dirop fs/namei.c:2914 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: start_dirop fs/namei.c:2938 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: filename_rmdir+0x1cd/0x520 fs/namei.c:5414
#2: ffff8881166b0bc0 (&osb->nfs_sync_rwlock){.+.+}-{4:4}, at: ocfs2_nfs_sync_lock+0x106/0x270 fs/ocfs2/dlmglue.c:2875
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
stack backtrace:
CPU: 1 UID: 0 PID: 6069 Comm: syz-executor Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e1/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f51b819bf77
Code: 77 01 c3 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 b8 07 01 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd5ea06718 EFLAGS: 00000207 ORIG_RAX: 0000000000000107
RAX: ffffffffffffffda RBX: 0000000000000065 RCX: 00007f51b819bf77
RDX: 0000000000000200 RSI: 00007ffd5ea078c0 RDI: 00000000ffffff9c
RBP: 00007f51b82321ca R08: 0000000000018560 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffd5ea078c0
R13: 00007f51b82321ca R14: 000000000001819f R15: 00007ffd5ea09a80
</TASK>
The explanation of the root cause of the bug is:
The lockdep warning reports a circular locking dependency involving three OCFS2 system inode locks (which all belong to the `ocfs2_sysfile_lock_key` lock class, but are distinct locks based on their system inode type).
The three locks involved are:
1. `INODE_ALLOC_SYSTEM_INODE`
2. `EXTENT_ALLOC_SYSTEM_INODE`
3. `ORPHAN_DIR_SYSTEM_INODE`
### Root Cause Analysis
The circular dependency is formed by three separate code paths that establish the following lock ordering:
**1. `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE`**
In `ocfs2_mknod()` (`fs/ocfs2/namei.c`), the code first reserves an inode by calling `ocfs2_reserve_new_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock. Shortly after, it reserves metadata blocks by calling `ocfs2_reserve_new_metadata_blocks()`, which acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Both locks are held concurrently until the end of the function (or upon error), establishing this dependency.
**2. `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`**
In `ocfs2_dio_end_io_write()` (`fs/ocfs2/aops.c`), the code allocates metadata blocks for unwritten extents by calling `ocfs2_lock_allocators()`. This allocates `meta_ac` and acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Later in the same function, if the inode was orphaned, it calls `ocfs2_del_inode_from_orphan()`, which acquires the `ORPHAN_DIR_SYSTEM_INODE` lock. The `meta_ac` context (and thus the `EXTENT_ALLOC_SYSTEM_INODE` lock) is only freed at the very end of the function, meaning it is held while `ORPHAN_DIR_SYSTEM_INODE` is acquired.
**3. `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`**
In `ocfs2_wipe_inode()` (`fs/ocfs2/inode.c`), the `ORPHAN_DIR_SYSTEM_INODE` lock is acquired first to prevent races with recovery completion. While holding this lock, it calls `ocfs2_remove_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock to free the inode. (A similar dependency is also established in `ocfs2_prep_new_orphaned_file()`).
Combining these three paths creates the circular dependency:
`INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`.
### How to Fix
We can break the cycle by addressing the second dependency (`EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`) in `ocfs2_dio_end_io_write()`.
The `data_ac` and `meta_ac` allocation contexts are only needed for the transaction that marks the extents as written. Once the transaction is committed via `ocfs2_commit_trans()` and the allocation semaphore is released via `up_write(&oi->ip_alloc_sem)`, these contexts are no longer needed. We can safely free them (which releases the `EXTENT_ALLOC_SYSTEM_INODE` lock) *before* calling `ocfs2_del_inode_from_orphan()`.
Here is the proposed fix for `fs/ocfs2/aops.c`:
```c
@@ -2372,6 +2372,16 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2393,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
```
This ensures that the `EXTENT_ALLOC_SYSTEM_INODE` lock is dropped before we attempt to acquire the `ORPHAN_DIR_SYSTEM_INODE` lock, successfully breaking the circular dependency.
Reply: I have applied the fix to break the circular locking dependency by modifying `ocfs2_dio_end_io_write()` in `fs/ocfs2/aops.c`.
### What I did:
I moved the freeing of the `data_ac` and `meta_ac` allocation contexts to happen immediately after the transaction is committed and the allocation semaphore is released (`up_write(&oi->ip_alloc_sem)`), but *before* the call to `ocfs2_del_inode_from_orphan()`.
### Why this is the best fix:
The circular dependency is formed by the following lock ordering:
1. `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` (in `ocfs2_mknod()`)
2. `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` (in `ocfs2_dio_end_io_write()`)
3. `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE` (in `ocfs2_wipe_inode()`)
By freeing `data_ac` and `meta_ac` earlier in `ocfs2_dio_end_io_write()`, we release the `EXTENT_ALLOC_SYSTEM_INODE` lock before attempting to acquire the `ORPHAN_DIR_SYSTEM_INODE` lock (which happens inside `ocfs2_del_inode_from_orphan()`). This effectively breaks the `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` dependency, resolving the circular locking issue.
The allocation contexts (`data_ac` and `meta_ac`) are only needed for the transaction that marks the extents as written. Once the transaction is committed and the allocation semaphore is released, they are no longer required. Freeing them early is completely safe and does not affect the subsequent orphan cleanup or deallocation steps.
I also verified other occurrences of `ocfs2_del_inode_from_orphan()` (such as in `ocfs2_recover_orphans()` and `ocfs2_add_inode_to_orphan()`) and confirmed that they do not hold the `EXTENT_ALLOC_SYSTEM_INODE` lock. Similarly, I checked other callers of `ocfs2_lock_allocators()` and confirmed they do not acquire the `ORPHAN_DIR_SYSTEM_INODE` lock while holding the allocation contexts. Therefore, this fix is localized and sufficient to resolve the root cause without introducing new issues.
|
| 83/4 |
2026/05/29 16:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 9932
output: 45
thoughts: 182
Thoughts: **Analyzing a Circular Locking Dependency in OCFS2**
Okay, so I'm looking at this issue in OCFS2 and it seems we have a nasty circular locking dependency. The breakdown is: `INODE_ALLOC_SYSTEM_INODE` is grabbing a lock that `EXTENT_ALLOC_SYSTEM_INODE` requires. Then `EXTENT_ALLOC_SYSTEM_INODE` needs `ORPHAN_DIR_SYSTEM_INODE`, and finally, `ORPHAN_DIR_SYSTEM_INODE` is somehow reaching back and needing `INODE_ALLOC_SYSTEM_INODE`. That's a classic deadlock scenario waiting to happen.
The suggested fix sounds promising. It looks like the proposal is to reorder the freeing of `data_ac` and `meta_ac` within `ocfs2_dio_end_io_write()` to happen *before* calling `ocfs2_del_inode_from_orphan()`. That could break the cycle, which I like the sound of. Let's see... I'll need to dig into the code and verify the rationale behind this. I'll need to open `fs/ocfs2/aops.c` and take a closer look at what's happening within `ocfs2_dio_end_io_write()`. Let's see if this proposed change is the right approach.
|
| 84/4 |
2026/05/29 16:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/aops.c Name:ocfs2_dio_end_io_write]
Results: map[SourceCode:2266: static int ocfs2_dio_end_io_write(struct inode *inode,
2267: struct ocfs2_dio_write_ctxt *dwc,
2268: loff_t offset,
2269: ssize_t bytes)
2270: {
2271: struct ocfs2_cached_dealloc_ctxt dealloc;
2272: struct ocfs2_extent_tree et;
2273: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
2274: struct ocfs2_inode_info *oi = OCFS2_I(inode);
2275: struct ocfs2_unwritten_extent *ue = NULL;
2276: struct buffer_head *di_bh = NULL;
2277: struct ocfs2_dinode *di;
2278: struct ocfs2_alloc_context *data_ac = NULL;
2279: struct ocfs2_alloc_context *meta_ac = NULL;
2280: handle_t *handle = NULL;
2281: loff_t end = offset + bytes;
2282: int ret = 0, credits = 0, batch = 0;
2283:
2284: ocfs2_init_dealloc_ctxt(&dealloc);
2285:
2286: /* We do clear unwritten, delete orphan, change i_size here. If neither
2287: * of these happen, we can skip all this. */
2288: if (list_empty(&dwc->dw_zero_list) &&
2289: end <= i_size_read(inode) &&
2290: !dwc->dw_orphaned)
2291: goto out;
2292:
2293: ret = ocfs2_inode_lock(inode, &di_bh, 1);
2294: if (ret < 0) {
2295: mlog_errno(ret);
2296: goto out;
2297: }
2298:
2299: down_write(&oi->ip_alloc_sem);
2300: di = (struct ocfs2_dinode *)di_bh->b_data;
2301:
2302: ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh);
2303:
2304: /* Attach dealloc with extent tree in case that we may reuse extents
2305: * which are already unlinked from current extent tree due to extent
2306: * rotation and merging.
2307: */
2308: et.et_dealloc = &dealloc;
2309:
2310: ret = ocfs2_lock_allocators(inode, &et, 0, dwc->dw_zero_count*2,
2311: &data_ac, &meta_ac);
2312: if (ret) {
2313: mlog_errno(ret);
2314: goto unlock;
2315: }
2316:
2317: credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
2318:
2319: list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) {
2320: if (!handle) {
2321: handle = ocfs2_start_trans(osb, credits);
2322: if (IS_ERR(handle)) {
2323: ret = PTR_ERR(handle);
2324: mlog_errno(ret);
2325: goto unlock;
2326: }
2327: ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
2328: OCFS2_JOURNAL_ACCESS_WRITE);
2329: if (ret) {
2330: mlog_errno(ret);
2331: goto commit;
2332: }
2333: }
2334: ret = ocfs2_assure_trans_credits(handle, credits);
2335: if (ret < 0) {
2336: mlog_errno(ret);
2337: goto commit;
2338: }
2339: ret = ocfs2_mark_extent_written(inode, &et, handle,
2340: ue->ue_cpos, 1,
2341: ue->ue_phys,
2342: meta_ac, &dealloc);
2343: if (ret < 0) {
2344: mlog_errno(ret);
2345: goto commit;
2346: }
2347:
2348: if (++batch == OCFS2_DIO_MARK_EXTENT_BATCH) {
2349: ocfs2_commit_trans(osb, handle);
2350: handle = NULL;
2351: batch = 0;
2352: }
2353: }
2354:
2355: if (end > i_size_read(inode)) {
2356: if (!handle) {
2357: handle = ocfs2_start_trans(osb, credits);
2358: if (IS_ERR(handle)) {
2359: ret = PTR_ERR(handle);
2360: mlog_errno(ret);
2361: goto unlock;
2362: }
2363: }
2364: ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
2365: if (ret < 0)
2366: mlog_errno(ret);
2367: }
2368:
2369: commit:
2370: if (handle)
2371: ocfs2_commit_trans(osb, handle);
2372: unlock:
2373: up_write(&oi->ip_alloc_sem);
2374:
2375: /* everything looks good, let's start the cleanup */
2376: if (!ret && dwc->dw_orphaned) {
2377: BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
2378:
2379: ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2380: if (ret < 0)
2381: mlog_errno(ret);
2382: }
2383: ocfs2_inode_unlock(inode, 1);
2384: brelse(di_bh);
2385: out:
2386: if (data_ac)
2387: ocfs2_free_alloc_context(data_ac);
2388: if (meta_ac)
2389: ocfs2_free_alloc_context(meta_ac);
2390: ocfs2_run_deallocs(osb, &dealloc);
2391: ocfs2_dio_free_write_ctx(inode, dwc);
2392:
2393: return ret;
2394: }
SourceFile:fs/ocfs2/aops.c]
|
| 85/4 |
2026/05/29 16:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 12504
output: 65
thoughts: 538
Thoughts: **Analyzing a Proposed Fix for OCFS2 DIO Write Path**
Okay, so I'm looking at a proposed change to the `ocfs2_dio_end_io_write` function in the OCFS2 filesystem. The current thinking is that the `ocfs2_free_alloc_context` calls for `data_ac` and `meta_ac` are in the wrong place. The fix proposes moving them up, specifically right after the `up_write(&oi->ip_alloc_sem)` call, and *before* the call to `ocfs2_del_inode_from_orphan()`.
The rationale here is likely related to the potential interaction of these allocation contexts with the orphan inode cleanup process. Moving those `free` calls to immediately after releasing the allocation semaphore suggests there might be a contention issue or a potential use-after-free scenario if the deallocation happens after the orphan inode is touched.
This seems reasonable on the surface, but I need to investigate the implications of this change and whether it addresses a root cause, or is just a band-aid.
Next, it's vital to determine whether these locks, particularly `EXTENT_ALLOC_SYSTEM_INODE` (which I see is acquired in `ocfs2_lock_allocators()`) and `ORPHAN_DIR_SYSTEM_INODE` are held concurrently elsewhere. I need to scan the codebase for other locations where `ocfs2_del_inode_from_orphan()` might be called while an allocation context (`data_ac` or `meta_ac`) is in scope. That's a critical path to examine. This will tell me if this issue is specific to `ocfs2_dio_end_io_write` or a more general problem.
|
| 86/4 |
2026/05/29 17:00 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/ocfs2/aops.c IncludeSnippetLines:10 Name:ocfs2_del_inode_from_orphan SourceTreePrefix:fs/ocfs2/]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_add_inode_to_orphan SourceFile:fs/ocfs2/namei.c SourceLine:2663 SourceSnippet:2653: * If so, manually recover it first.
2654: */
2655: if (unlikely(di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL))) {
2656: status = ocfs2_truncate_file(inode, di_bh, i_size_read(inode));
2657: if (status < 0) {
2658: if (status != -ENOSPC)
2659: mlog_errno(status);
2660: goto bail_unlock_inode;
2661: }
2662:
2663: status = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2664: if (status < 0) {
2665: mlog_errno(status);
2666: goto bail_unlock_inode;
2667: }
2668: }
2669:
2670: status = ocfs2_prepare_orphan_dir(osb, &orphan_dir_inode,
2671: OCFS2_I(inode)->ip_blkno,
2672: orphan_name,
2673: &orphan_insert,
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_dio_end_io_write SourceFile:fs/ocfs2/aops.c SourceLine:2379 SourceSnippet:2369: commit:
2370: if (handle)
2371: ocfs2_commit_trans(osb, handle);
2372: unlock:
2373: up_write(&oi->ip_alloc_sem);
2374:
2375: /* everything looks good, let's start the cleanup */
2376: if (!ret && dwc->dw_orphaned) {
2377: BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
2378:
2379: ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2380: if (ret < 0)
2381: mlog_errno(ret);
2382: }
2383: ocfs2_inode_unlock(inode, 1);
2384: brelse(di_bh);
2385: out:
2386: if (data_ac)
2387: ocfs2_free_alloc_context(data_ac);
2388: if (meta_ac)
2389: ocfs2_free_alloc_context(meta_ac);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_recover_orphans SourceFile:fs/ocfs2/journal.c SourceLine:2345 SourceSnippet:2335:
2336: if (di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL)) {
2337: ret = ocfs2_truncate_file(inode, di_bh,
2338: i_size_read(inode));
2339: if (ret < 0) {
2340: if (ret != -ENOSPC)
2341: mlog_errno(ret);
2342: goto unlock_inode;
2343: }
2344:
2345: ret = ocfs2_del_inode_from_orphan(osb, inode,
2346: di_bh, 0, 0);
2347: if (ret)
2348: mlog_errno(ret);
2349: }
2350: unlock_inode:
2351: ocfs2_inode_unlock(inode, 1);
2352: brelse(di_bh);
2353: di_bh = NULL;
2354: unlock_rw:
2355: ocfs2_rw_unlock(inode, 1);
]] TruncatedOutput:false]
|
| 87/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 14689
output: 45
thoughts: 59
Thoughts: Okay, let's dive into this. Here's how I'd approach this analysis:
**Analyzing Orphan Handling in OCFS2**
Alright, my initial thought is to zero in on how orphaned inodes are handled within the OCFS2 file system. Specifically, I need to check the interplay between `ocfs2_add_inode_to_orphan` and `ocfs2_recover_orphans`, to ensure the `EXTENT_ALLOC_SYSTEM_INODE` flag is considered. It's crucial this flag, representing a system-level inode, is handled correctly during orphan processing.
Now, let's examine what's happening within `ocfs2_add_inode_to_orphan`: I'll need to meticulously follow the logic within this function to see how it interacts with the inode's allocation status, especially when determining whether a system inode is handled correctly. I'll be looking for where this flag is checked, set, or used in any way related to adding an inode to the orphan list.
|
| 88/4 |
2026/05/29 17:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/namei.c Name:ocfs2_add_inode_to_orphan]
Results: map[SourceCode:2633: int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
2634: struct inode *inode)
2635: {
2636: char orphan_name[OCFS2_DIO_ORPHAN_PREFIX_LEN + OCFS2_ORPHAN_NAMELEN + 1];
2637: struct inode *orphan_dir_inode = NULL;
2638: struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
2639: struct buffer_head *di_bh = NULL;
2640: int status = 0;
2641: handle_t *handle = NULL;
2642: struct ocfs2_dinode *di = NULL;
2643:
2644: status = ocfs2_inode_lock(inode, &di_bh, 1);
2645: if (status < 0) {
2646: mlog_errno(status);
2647: goto bail;
2648: }
2649:
2650: di = (struct ocfs2_dinode *) di_bh->b_data;
2651: /*
2652: * Another append dio crashed?
2653: * If so, manually recover it first.
2654: */
2655: if (unlikely(di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL))) {
2656: status = ocfs2_truncate_file(inode, di_bh, i_size_read(inode));
2657: if (status < 0) {
2658: if (status != -ENOSPC)
2659: mlog_errno(status);
2660: goto bail_unlock_inode;
2661: }
2662:
2663: status = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
2664: if (status < 0) {
2665: mlog_errno(status);
2666: goto bail_unlock_inode;
2667: }
2668: }
2669:
2670: status = ocfs2_prepare_orphan_dir(osb, &orphan_dir_inode,
2671: OCFS2_I(inode)->ip_blkno,
2672: orphan_name,
2673: &orphan_insert,
2674: true);
2675: if (status < 0) {
2676: mlog_errno(status);
2677: goto bail_unlock_inode;
2678: }
2679:
2680: handle = ocfs2_start_trans(osb,
2681: OCFS2_INODE_ADD_TO_ORPHAN_CREDITS);
2682: if (IS_ERR(handle)) {
2683: status = PTR_ERR(handle);
2684: goto bail_unlock_orphan;
2685: }
2686:
2687: status = ocfs2_orphan_add(osb, handle, inode, di_bh, orphan_name,
2688: &orphan_insert, orphan_dir_inode, true);
2689: if (status)
2690: mlog_errno(status);
2691:
2692: ocfs2_commit_trans(osb, handle);
2693:
2694: bail_unlock_orphan:
2695: ocfs2_inode_unlock(orphan_dir_inode, 1);
2696: inode_unlock(orphan_dir_inode);
2697: iput(orphan_dir_inode);
2698:
2699: ocfs2_free_dir_lookup_result(&orphan_insert);
2700:
2701: bail_unlock_inode:
2702: ocfs2_inode_unlock(inode, 1);
2703: brelse(di_bh);
2704:
2705: bail:
2706: return status;
2707: }
SourceFile:fs/ocfs2/namei.c]
|
| 89/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 16195
output: 41
thoughts: 41
Thoughts: Okay, here's my interpretation of those thoughts, framed as my own:
**Analyzing Orphan Handling in OCFS2**
Alright, let's break this down. In looking at the orphan inode handling within OCFS2, I'm specifically examining the function `ocfs2_add_inode_to_orphan`. My immediate observation is that this particular function *doesn't* acquire either the `data_ac` or the `meta_ac` locks. This is a crucial detail, immediately flagging how it fits into the broader picture of atomic operations.
Now, shifting gears to `ocfs2_recover_orphans`, I need to understand how this function interacts with the previous one. I'm now asking myself: how does the lack of locking in `ocfs2_add_inode_to_orphan` influence the behavior of the recovery process? Is this a deliberate design choice related to performance, or is there a specific, subtle race condition risk I need to be aware of? Understanding the synchronization points between these two functions is paramount to ensure data consistency, particularly given the potential for orphaned inodes after a crash or unclean shutdown. I need to dig deeper into the locking schemes used elsewhere in the orphan recovery process.
|
| 90/4 |
2026/05/29 17:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/journal.c Name:ocfs2_recover_orphans]
Results: map[SourceCode:2269: /*
2270: * Orphan recovery. Each mounted node has it's own orphan dir which we
2271: * must run during recovery. Our strategy here is to build a list of
2272: * the inodes in the orphan dir and iget/iput them. The VFS does
2273: * (most) of the rest of the work.
2274: *
2275: * Orphan recovery can happen at any time, not just mount so we have a
2276: * couple of extra considerations.
2277: *
2278: * - We grab as many inodes as we can under the orphan dir lock -
2279: * doing iget() outside the orphan dir risks getting a reference on
2280: * an invalid inode.
2281: * - We must be sure not to deadlock with other processes on the
2282: * system wanting to run delete_inode(). This can happen when they go
2283: * to lock the orphan dir and the orphan recovery process attempts to
2284: * iget() inside the orphan dir lock. This can be avoided by
2285: * advertising our state to ocfs2_delete_inode().
2286: */
2287: static int ocfs2_recover_orphans(struct ocfs2_super *osb,
2288: int slot,
2289: enum ocfs2_orphan_reco_type orphan_reco_type)
2290: {
2291: int ret = 0;
2292: struct inode *inode = NULL;
2293: struct inode *iter;
2294: struct ocfs2_inode_info *oi;
2295: struct buffer_head *di_bh = NULL;
2296: struct ocfs2_dinode *di = NULL;
2297:
2298: trace_ocfs2_recover_orphans(slot);
2299:
2300: ocfs2_mark_recovering_orphan_dir(osb, slot);
2301: ret = ocfs2_queue_orphans(osb, slot, &inode, orphan_reco_type);
2302: ocfs2_clear_recovering_orphan_dir(osb, slot);
2303:
2304: /* Error here should be noted, but we want to continue with as
2305: * many queued inodes as we've got. */
2306: if (ret)
2307: mlog_errno(ret);
2308:
2309: while (inode) {
2310: oi = OCFS2_I(inode);
2311: trace_ocfs2_recover_orphans_iput(
2312: (unsigned long long)oi->ip_blkno);
2313:
2314: iter = oi->ip_next_orphan;
2315: oi->ip_next_orphan = NULL;
2316:
2317: if (oi->ip_flags & OCFS2_INODE_DIO_ORPHAN_ENTRY) {
2318: inode_lock(inode);
2319: ret = ocfs2_rw_lock(inode, 1);
2320: if (ret < 0) {
2321: mlog_errno(ret);
2322: goto unlock_mutex;
2323: }
2324: /*
2325: * We need to take and drop the inode lock to
2326: * force read inode from disk.
2327: */
2328: ret = ocfs2_inode_lock(inode, &di_bh, 1);
2329: if (ret) {
2330: mlog_errno(ret);
2331: goto unlock_rw;
2332: }
2333:
2334: di = (struct ocfs2_dinode *)di_bh->b_data;
2335:
2336: if (di->i_flags & cpu_to_le32(OCFS2_DIO_ORPHANED_FL)) {
2337: ret = ocfs2_truncate_file(inode, di_bh,
2338: i_size_read(inode));
2339: if (ret < 0) {
2340: if (ret != -ENOSPC)
2341: mlog_errno(ret);
2342: goto unlock_inode;
2343: }
2344:
2345: ret = ocfs2_del_inode_from_orphan(osb, inode,
2346: di_bh, 0, 0);
2347: if (ret)
2348: mlog_errno(ret);
2349: }
2350: unlock_inode:
2351: ocfs2_inode_unlock(inode, 1);
2352: brelse(di_bh);
2353: di_bh = NULL;
2354: unlock_rw:
2355: ocfs2_rw_unlock(inode, 1);
2356: unlock_mutex:
2357: inode_unlock(inode);
2358:
2359: /* clear dio flag in ocfs2_inode_info */
2360: oi->ip_flags &= ~OCFS2_INODE_DIO_ORPHAN_ENTRY;
2361: } else {
2362: spin_lock(&oi->ip_lock);
2363: /* Set the proper information to get us going into
2364: * ocfs2_delete_inode. */
2365: oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED;
2366: spin_unlock(&oi->ip_lock);
2367: }
2368:
2369: iput(inode);
2370: inode = iter;
2371: }
2372:
2373: return ret;
2374: }
SourceFile:fs/ocfs2/journal.c]
|
| 91/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 18215
output: 599
thoughts: 537
Thoughts: **Analyzing Potential Deadlock in OCFS2 Orphan Recovery**
Okay, so I'm digging into this `ocfs2_recover_orphans` function, and something's bugging me. It doesn't seem to hold either the `data_ac` or `meta_ac` allocation contexts. This means the only place where the `EXTENT_ALLOC_SYSTEM_INODE` lock is held concurrently with the `ORPHAN_DIR_SYSTEM_INODE` lock is within `ocfs2_dio_end_io_write`.
Let me re-examine that function, specifically the section at the end. I see the current lock and unlock sequence: first commit the transaction if there is a handle, then unlock the inode allocation semaphore. Following that, there's a check for orphan status. If there are any orphans, a routine to delete the inode from orphan list is executed, then the inode lock is released and the buffer is released. Finally the allocation contexts are freed.
My thinking is, if I move the calls to `ocfs2_free_alloc_context(data_ac)` and `ocfs2_free_alloc_context(meta_ac)` right after `up_write(&oi->ip_alloc_sem)`, I'll drop the `EXTENT_ALLOC_SYSTEM_INODE` lock *before* calling `ocfs2_del_inode_from_orphan`. This should avoid any potential deadlock scenario.
A quick check β is there any dependency on the alloc contexts after the deallocs are run? No, `ocfs2_free_alloc_context` *is* called *before* `ocfs2_run_deallocs` in the original code. So it should be safe to move these calls upwards. Good, I think I've got a workable solution. Time to make the code edit.
|
| 92/4 |
2026/05/29 17:00 |
tool |
codeeditor |
0m
Args: map[CurrentCode: commit:
if (handle)
ocfs2_commit_trans(osb, handle);
unlock:
up_write(&oi->ip_alloc_sem);
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
if (ret < 0)
mlog_errno(ret);
}
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
if (data_ac)
ocfs2_free_alloc_context(data_ac);
if (meta_ac)
ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
return ret;
} NewCode: commit:
if (handle)
ocfs2_commit_trans(osb, handle);
unlock:
up_write(&oi->ip_alloc_sem);
if (data_ac) {
ocfs2_free_alloc_context(data_ac);
data_ac = NULL;
}
if (meta_ac) {
ocfs2_free_alloc_context(meta_ac);
meta_ac = NULL;
}
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
if (ret < 0)
mlog_errno(ret);
}
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
return ret;
} SourceFile:fs/ocfs2/aops.c]
Results:
|
| 93/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 19755
output: 25
thoughts: 28
Thoughts: Okay, here's my summary, taking on the persona you've described:
**Digging into the Filesystem Code**
Alright, I need to understand this better. Before I start going down any rabbit holes with my analysis, I need to see if this specific scenario, or something *very* close to it, has already been addressed. Given the context, my initial thought is to check `fs/ocfs2/aops.c`, as that seems like the most immediate and relevant place to begin. However, I won't limit myself to that file alone. I'll need to expand my search to other related code within the OCFS2 filesystem source to see if similar operations are handled elsewhere. This will hopefully provide insight into the existing design patterns and any potential solutions that are already in place. It's best to avoid reinventing the wheel when an established method might be right at hand. Time to get my grep on.
|
| 94/4 |
2026/05/29 17:00 |
tool |
grepper |
0m
Args: map[Expression:ocfs2_del_inode_from_orphan]
Results: map[Output:fs/ocfs2/aops.c=2266=static int ocfs2_dio_end_io_write(struct inode *inode,
--
fs/ocfs2/aops.c-2378-
fs/ocfs2/aops.c:2379: ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
fs/ocfs2/aops.c-2380- if (ret < 0)
--
fs/ocfs2/journal.c=2287=static int ocfs2_recover_orphans(struct ocfs2_super *osb,
--
fs/ocfs2/journal.c-2344-
fs/ocfs2/journal.c:2345: ret = ocfs2_del_inode_from_orphan(osb, inode,
fs/ocfs2/journal.c-2346- di_bh, 0, 0);
--
fs/ocfs2/namei.c=2633=int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
--
fs/ocfs2/namei.c-2662-
fs/ocfs2/namei.c:2663: status = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
fs/ocfs2/namei.c-2664- if (status < 0) {
--
fs/ocfs2/namei.c-2708-
fs/ocfs2/namei.c:2709:int ocfs2_del_inode_from_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.c-2710- struct inode *inode, struct buffer_head *di_bh,
--
fs/ocfs2/namei.h=29=int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.h-30- struct inode *inode);
fs/ocfs2/namei.h:31:int ocfs2_del_inode_from_orphan(struct ocfs2_super *osb,
fs/ocfs2/namei.h-32- struct inode *inode, struct buffer_head *di_bh,
]
|
| 95/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 20618
output: 61
thoughts: 820
Thoughts: **Analyzing a Potential Deadlock in OCFS2's Inode Allocation**
Okay, so I'm digging into a possible deadlock situation in the OCFS2 file system. The key here is understanding the locking order, and I'm focusing on the relationship between these system inode locks: `EXTENT_ALLOC_SYSTEM_INODE`, `ORPHAN_DIR_SYSTEM_INODE`, and `INODE_ALLOC_SYSTEM_INODE`.
Initially, I pinpointed the places that call `ocfs2_del_inode_from_orphan`, because that function seems to be at the heart of the issue. Those calls are in `ocfs2_dio_end_io_write`, `ocfs2_recover_orphans`, and `ocfs2_add_inode_to_orphan`. We had already checked `ocfs2_recover_orphans` and `ocfs2_add_inode_to_orphan`, and those functions did not hold `data_ac` or `meta_ac`. So, the remaining function called, `ocfs2_dio_end_io_write` is the problematic call.
I then went through a list of functions where `ORPHAN_DIR_SYSTEM_INODE` is acquired, looking for overlaps. The list includes `ocfs2_del_inode_from_orphan`, `ocfs2_add_inode_to_orphan`, `ocfs2_recover_orphans`, `ocfs2_wipe_inode`, `ocfs2_prep_new_orphaned_file`, `ocfs2_orphan_add`, `ocfs2_orphan_del`, and `ocfs2_orphan_recovery_can_continue`. These all eventually call `ocfs2_inode_lock` on the orphan directory inode.
Now, my attention went to `ocfs2_del_inode_from_orphan` itself. It calls `ocfs2_inode_lock` on the `orphan_dir_inode`, which is retrieved via `ocfs2_get_system_file_inode` with the `ORPHAN_DIR_SYSTEM_INODE` identifier. This is where things start to smell fishy.
A lockdep report revealed a concerning circular dependency: `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`. That's a classic recipe for a deadlock!
Let's break down each step:
1. `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE`: This is normal. In `ocfs2_mknod()`, you allocate an inode using `ocfs2_reserve_new_inode()` (acquiring `INODE_ALLOC_SYSTEM_INODE`) and then allocate metadata blocks using `ocfs2_reserve_new_metadata_blocks()` (acquiring `EXTENT_ALLOC_SYSTEM_INODE`). Seems logical.
2. `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`: This is the crucial part that I need to fix. In `ocfs2_dio_end_io_write()`, `ocfs2_lock_allocators()` takes `EXTENT_ALLOC_SYSTEM_INODE`. Then, `ocfs2_del_inode_from_orphan()` acquires `ORPHAN_DIR_SYSTEM_INODE`. This is the problematic dependency.
3. `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`: This is also normal. In `ocfs2_wipe_inode()`, `ocfs2_inode_lock()` acquires `ORPHAN_DIR_SYSTEM_INODE`, and `ocfs2_remove_inode()` acquires `INODE_ALLOC_SYSTEM_INODE`. It makes sense: remove the inode from the orphan dir and then free the inode itself.
So, the second dependency is the culprit. Fixing it would break the cycle. I need to make sure that `EXTENT_ALLOC_SYSTEM_INODE` isn't held when `ORPHAN_DIR_SYSTEM_INODE` is acquired.
I need to double-check that there aren't any other places where `ocfs2_lock_allocators` is called and then somehow lead into a call to `ocfs2_del_inode_from_orphan` or similar functions, to ensure the fix is comprehensive.
|
| 96/4 |
2026/05/29 17:00 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:fs/ocfs2/suballoc.c IncludeSnippetLines:0 Name:ocfs2_lock_allocators SourceTreePrefix:fs/ocfs2/]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_dio_end_io_write SourceFile:fs/ocfs2/aops.c SourceLine:2310] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_dx_dir_rebalance SourceFile:fs/ocfs2/dir.c SourceLine:3801] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_extend_allocation SourceFile:fs/ocfs2/file.c SourceLine:590] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_rm_xattr_cluster SourceFile:fs/ocfs2/xattr.c SourceLine:5476] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ocfs2_write_begin_nolock SourceFile:fs/ocfs2/aops.c SourceLine:1720]] TruncatedOutput:false]
|
| 97/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 22793
output: 43
thoughts: 103
Thoughts: **Investigating Potential Orphan Inode Interactions**
Okay, let's dive into this. My immediate concern is understanding the interplay between a few key OCFS2 functions and the orphan inode management mechanisms. I need to know if `ocfs2_dx_dir_rebalance`, `ocfs2_extend_allocation`, `ocfs2_rm_xattr_cluster`, and `ocfs2_write_begin_nolock` are touching the orphan lists at all. Specifically, I need to check if they're calling `ocfs2_del_inode_from_orphan`, `ocfs2_add_inode_to_orphan`, or those newer aliases `ocfs2_orphan_add` or `ocfs2_orphan_del`. I'm looking for direct modifications to the orphan inode lists, or any indirect calls that could lead to unexpected behavior in orphan inode recovery or management. This is the starting point for potentially understanding a much larger problem.
|
| 98/4 |
2026/05/29 17:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/dir.c Name:ocfs2_dx_dir_rebalance]
Results: map[SourceCode:3741: /*
3742: * Find the median value in dx_leaf_bh and allocate a new leaf to move
3743: * half our entries into.
3744: */
3745: static int ocfs2_dx_dir_rebalance(struct ocfs2_super *osb, struct inode *dir,
3746: struct buffer_head *dx_root_bh,
3747: struct buffer_head *dx_leaf_bh,
3748: struct ocfs2_dx_hinfo *hinfo, u32 leaf_cpos,
3749: u64 leaf_blkno)
3750: {
3751: struct ocfs2_dx_leaf *dx_leaf = (struct ocfs2_dx_leaf *)dx_leaf_bh->b_data;
3752: int credits, ret, i, num_used, did_quota = 0;
3753: u32 cpos, split_hash, insert_hash = hinfo->major_hash;
3754: u64 orig_leaves_start;
3755: int num_dx_leaves;
3756: struct buffer_head **orig_dx_leaves = NULL;
3757: struct buffer_head **new_dx_leaves = NULL;
3758: struct ocfs2_alloc_context *data_ac = NULL, *meta_ac = NULL;
3759: struct ocfs2_extent_tree et;
3760: handle_t *handle = NULL;
3761: struct ocfs2_dx_root_block *dx_root;
3762: struct ocfs2_dx_leaf *tmp_dx_leaf = NULL;
3763:
3764: trace_ocfs2_dx_dir_rebalance((unsigned long long)OCFS2_I(dir)->ip_blkno,
3765: (unsigned long long)leaf_blkno,
3766: insert_hash);
3767:
3768: ocfs2_init_dx_root_extent_tree(&et, INODE_CACHE(dir), dx_root_bh);
3769:
3770: dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data;
3771: /*
3772: * XXX: This is a rather large limit. We should use a more
3773: * realistic value.
3774: */
3775: if (le32_to_cpu(dx_root->dr_clusters) == UINT_MAX)
3776: return -ENOSPC;
3777:
3778: num_used = le16_to_cpu(dx_leaf->dl_list.de_num_used);
3779: if (num_used < le16_to_cpu(dx_leaf->dl_list.de_count)) {
3780: mlog(ML_ERROR, "DX Dir: %llu, Asked to rebalance empty leaf: "
3781: "%llu, %d\n", (unsigned long long)OCFS2_I(dir)->ip_blkno,
3782: (unsigned long long)leaf_blkno, num_used);
3783: ret = -EIO;
3784: goto out;
3785: }
3786:
3787: orig_dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->sb, &num_dx_leaves);
3788: if (!orig_dx_leaves) {
3789: ret = -ENOMEM;
3790: mlog_errno(ret);
3791: goto out;
3792: }
3793:
3794: new_dx_leaves = ocfs2_dx_dir_kmalloc_leaves(osb->sb, NULL);
3795: if (!new_dx_leaves) {
3796: ret = -ENOMEM;
3797: mlog_errno(ret);
3798: goto out;
3799: }
3800:
3801: ret = ocfs2_lock_allocators(dir, &et, 1, 0, &data_ac, &meta_ac);
3802: if (ret) {
3803: if (ret != -ENOSPC)
3804: mlog_errno(ret);
3805: goto out;
3806: }
3807:
3808: credits = ocfs2_dx_dir_rebalance_credits(osb, dx_root);
3809: handle = ocfs2_start_trans(osb, credits);
3810: if (IS_ERR(handle)) {
3811: ret = PTR_ERR(handle);
3812: handle = NULL;
3813: mlog_errno(ret);
3814: goto out;
3815: }
3816:
3817: ret = dquot_alloc_space_nodirty(dir,
3818: ocfs2_clusters_to_bytes(dir->i_sb, 1));
3819: if (ret)
3820: goto out_commit;
3821: did_quota = 1;
3822:
3823: ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir), dx_leaf_bh,
3824: OCFS2_JOURNAL_ACCESS_WRITE);
3825: if (ret) {
3826: mlog_errno(ret);
3827: goto out_commit;
3828: }
3829:
3830: /*
3831: * This block is changing anyway, so we can sort it in place.
3832: */
3833: sort(dx_leaf->dl_list.de_entries, num_used,
3834: sizeof(struct ocfs2_dx_entry), dx_leaf_sort_cmp,
3835: NULL);
3836:
3837: ocfs2_journal_dirty(handle, dx_leaf_bh);
3838:
3839: ret = ocfs2_dx_dir_find_leaf_split(dx_leaf, leaf_cpos, insert_hash,
3840: &split_hash);
3841: if (ret) {
3842: mlog_errno(ret);
3843: goto out_commit;
3844: }
3845:
3846: trace_ocfs2_dx_dir_rebalance_split(leaf_cpos, split_hash, insert_hash);
3847:
3848: /*
3849: * We have to carefully order operations here. There are items
3850: * which want to be in the new cluster before insert, but in
3851: * order to put those items in the new cluster, we alter the
3852: * old cluster. A failure to insert gets nasty.
3853: *
3854: * So, start by reserving writes to the old
3855: * cluster. ocfs2_dx_dir_new_cluster will reserve writes on
3856: * the new cluster for us, before inserting it. The insert
3857: * won't happen if there's an error before that. Once the
3858: * insert is done then, we can transfer from one leaf into the
3859: * other without fear of hitting any error.
3860: */
3861:
3862: /*
3863: * The leaf transfer wants some scratch space so that we don't
3864: * wind up doing a bunch of expensive memmove().
3865: */
3866: tmp_dx_leaf = kmalloc(osb->sb->s_blocksize, GFP_NOFS);
3867: if (!tmp_dx_leaf) {
3868: ret = -ENOMEM;
3869: mlog_errno(ret);
3870: goto out_commit;
3871: }
3872:
3873: orig_leaves_start = ocfs2_block_to_cluster_start(dir->i_sb, leaf_blkno);
3874: ret = ocfs2_read_dx_leaves(dir, orig_leaves_start, num_dx_leaves,
3875: orig_dx_leaves);
3876: if (ret) {
3877: mlog_errno(ret);
3878: goto out_commit;
3879: }
3880:
3881: cpos = split_hash;
3882: ret = ocfs2_dx_dir_new_cluster(dir, &et, cpos, handle,
3883: data_ac, meta_ac, new_dx_leaves,
3884: num_dx_leaves);
3885: if (ret) {
3886: mlog_errno(ret);
3887: goto out_commit;
3888: }
3889:
3890: for (i = 0; i < num_dx_leaves; i++) {
3891: ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir),
3892: orig_dx_leaves[i],
3893: OCFS2_JOURNAL_ACCESS_WRITE);
3894: if (ret) {
3895: mlog_errno(ret);
3896: goto out_commit;
3897: }
3898:
3899: ret = ocfs2_journal_access_dl(handle, INODE_CACHE(dir),
3900: new_dx_leaves[i],
3901: OCFS2_JOURNAL_ACCESS_WRITE);
3902: if (ret) {
3903: mlog_errno(ret);
3904: goto out_commit;
3905: }
3906: }
3907:
3908: ocfs2_dx_dir_transfer_leaf(dir, split_hash, handle, tmp_dx_leaf,
3909: orig_dx_leaves, new_dx_leaves, num_dx_leaves);
3910:
3911: out_commit:
3912: if (ret < 0 && did_quota)
3913: dquot_free_space_nodirty(dir,
3914: ocfs2_clusters_to_bytes(dir->i_sb, 1));
3915:
3916: ocfs2_update_inode_fsync_trans(handle, dir, 1);
3917: ocfs2_commit_trans(osb, handle);
3918:
3919: out:
3920: if (orig_dx_leaves || new_dx_leaves) {
3921: for (i = 0; i < num_dx_leaves; i++) {
3922: if (orig_dx_leaves)
3923: brelse(orig_dx_leaves[i]);
3924: if (new_dx_leaves)
3925: brelse(new_dx_leaves[i]);
3926: }
3927: kfree(orig_dx_leaves);
3928: kfree(new_dx_leaves);
3929: }
3930:
3931: if (meta_ac)
3932: ocfs2_free_alloc_context(meta_ac);
3933: if (data_ac)
3934: ocfs2_free_alloc_context(data_ac);
3935:
3936: kfree(tmp_dx_leaf);
3937: return ret;
3938: }
SourceFile:fs/ocfs2/dir.c]
|
| 99/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 26414
output: 40
thoughts: 93
Thoughts: Here's my analysis of the provided code snippet:
**Analyzing the Directory Rebalancing Function**
Okay, so I'm looking at `ocfs2_dx_dir_rebalance` and what's immediately striking is the pattern of allocation management. It appears this function is managing resources efficiently by grabbing allocators with `ocfs2_lock_allocators`, setting up a transaction, working through the changes with `ocfs2_start_trans`, and finishing with `ocfs2_commit_trans`. Afterward, the function cleanly releases the `meta_ac` and `data_ac` access control structures. That looks pretty standard for these types of operations.
However, I don't see any calls to `ocfs2_del_inode_from_orphan` or similar orphan cleanup procedures within this function. That's something I need to keep in mind, as it could be relevant to how orphans are handled during rebalancing. I'll need to remember to check how that is handled elsewhere, or if there is something implicitly going on.
Now, my next step is to switch gears and examine `ocfs2_extend_allocation`. I need to understand how the allocation extensions are managed, how the code actually allocates space in the file system.
|
| 100/4 |
2026/05/29 17:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/file.c Name:ocfs2_extend_allocation]
Results: map[SourceCode: 556: static int ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
557: u32 clusters_to_add, int mark_unwritten)
558: {
559: int status = 0;
560: int restart_func = 0;
561: int credits;
562: u32 prev_clusters;
563: struct buffer_head *bh = NULL;
564: struct ocfs2_dinode *fe = NULL;
565: handle_t *handle = NULL;
566: struct ocfs2_alloc_context *data_ac = NULL;
567: struct ocfs2_alloc_context *meta_ac = NULL;
568: enum ocfs2_alloc_restarted why = RESTART_NONE;
569: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
570: struct ocfs2_extent_tree et;
571: int did_quota = 0;
572:
573: /*
574: * Unwritten extent only exists for file systems which
575: * support holes.
576: */
577: BUG_ON(mark_unwritten && !ocfs2_sparse_alloc(osb));
578:
579: status = ocfs2_read_inode_block(inode, &bh);
580: if (status < 0) {
581: mlog_errno(status);
582: goto leave;
583: }
584: fe = (struct ocfs2_dinode *) bh->b_data;
585:
586: restart_all:
587: BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters);
588:
589: ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), bh);
590: status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
591: &data_ac, &meta_ac);
592: if (status) {
593: mlog_errno(status);
594: goto leave;
595: }
596:
597: credits = ocfs2_calc_extend_credits(osb->sb, &fe->id2.i_list);
598: handle = ocfs2_start_trans(osb, credits);
599: if (IS_ERR(handle)) {
600: status = PTR_ERR(handle);
601: handle = NULL;
602: mlog_errno(status);
603: goto leave;
604: }
605:
606: restarted_transaction:
607: trace_ocfs2_extend_allocation(
608: (unsigned long long)OCFS2_I(inode)->ip_blkno,
609: (unsigned long long)i_size_read(inode),
610: le32_to_cpu(fe->i_clusters), clusters_to_add,
611: why, restart_func);
612:
613: status = dquot_alloc_space_nodirty(inode,
614: ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
615: if (status)
616: goto leave;
617: did_quota = 1;
618:
619: /* reserve a write to the file entry early on - that we if we
620: * run out of credits in the allocation path, we can still
621: * update i_size. */
622: status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), bh,
623: OCFS2_JOURNAL_ACCESS_WRITE);
624: if (status < 0) {
625: mlog_errno(status);
626: goto leave;
627: }
628:
629: prev_clusters = OCFS2_I(inode)->ip_clusters;
630:
631: status = ocfs2_add_inode_data(osb,
632: inode,
633: &logical_start,
634: clusters_to_add,
635: mark_unwritten,
636: bh,
637: handle,
638: data_ac,
639: meta_ac,
640: &why);
641: if ((status < 0) && (status != -EAGAIN)) {
642: if (status != -ENOSPC)
643: mlog_errno(status);
644: goto leave;
645: }
646: ocfs2_update_inode_fsync_trans(handle, inode, 1);
647: ocfs2_journal_dirty(handle, bh);
648:
649: spin_lock(&OCFS2_I(inode)->ip_lock);
650: clusters_to_add -= (OCFS2_I(inode)->ip_clusters - prev_clusters);
651: spin_unlock(&OCFS2_I(inode)->ip_lock);
652: /* Release unused quota reservation */
653: dquot_free_space(inode,
654: ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
655: did_quota = 0;
656:
657: if (why != RESTART_NONE && clusters_to_add) {
658: if (why == RESTART_META) {
659: restart_func = 1;
660: status = 0;
661: } else {
662: BUG_ON(why != RESTART_TRANS);
663:
664: status = ocfs2_allocate_extend_trans(handle, 1);
665: if (status < 0) {
666: /* handle still has to be committed at
667: * this point. */
668: status = -ENOMEM;
669: mlog_errno(status);
670: goto leave;
671: }
672: goto restarted_transaction;
673: }
674: }
675:
676: trace_ocfs2_extend_allocation_end(OCFS2_I(inode)->ip_blkno,
677: le32_to_cpu(fe->i_clusters),
678: (unsigned long long)le64_to_cpu(fe->i_size),
679: OCFS2_I(inode)->ip_clusters,
680: (unsigned long long)i_size_read(inode));
681:
682: leave:
683: if (status < 0 && did_quota)
684: dquot_free_space(inode,
685: ocfs2_clusters_to_bytes(osb->sb, clusters_to_add));
686: if (handle) {
687: ocfs2_commit_trans(osb, handle);
688: handle = NULL;
689: }
690: if (data_ac) {
691: ocfs2_free_alloc_context(data_ac);
692: data_ac = NULL;
693: }
694: if (meta_ac) {
695: ocfs2_free_alloc_context(meta_ac);
696: meta_ac = NULL;
697: }
698: if ((!status) && restart_func) {
699: restart_func = 0;
700: goto restart_all;
701: }
702: brelse(bh);
703: bh = NULL;
704:
705: return status;
706: }
SourceFile:fs/ocfs2/file.c]
|
| 101/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 29169
output: 44
thoughts: 63
Thoughts: Here's my summary, as the expert:
**Investigating Potential Resource Leaks**
Okay, so I'm looking at `ocfs2_extend_allocation` and I'm a bit concerned. It seems like it's freeing `data_ac` and `meta_ac` at the very end, but crucially, it *doesn't* appear to be calling `ocfs2_del_inode_from_orphan`. I need to understand the implications of this. It immediately triggers a red flag, because orphan cleanup is *critical* in distributed file systems. A missing cleanup call here suggests a potential leak or at least a path to data corruption under specific failure scenarios. I need to figure out why this design decision was made, and if there's an implicit mechanism that's handling the orphan removal in another place. It could be something I'm missing.
Let me pivot to examining `ocfs2_rm_xattr_cluster`. I'm going to look at how it deals with resource management in relation to xattrs, and see if I can glean any insight that might relate back to the orphan inode issue in `ocfs2_extend_allocation`. I'll focus on how it handles atomicity, consistency, and error paths, in the hopes that they might illuminate the logic of allocation extension.
|
| 102/4 |
2026/05/29 17:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/xattr.c Name:ocfs2_rm_xattr_cluster]
Results: map[SourceCode:5441: static int ocfs2_rm_xattr_cluster(struct inode *inode,
5442: struct buffer_head *root_bh,
5443: u64 blkno,
5444: u32 cpos,
5445: u32 len,
5446: void *para)
5447: {
5448: int ret;
5449: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5450: struct inode *tl_inode = osb->osb_tl_inode;
5451: handle_t *handle;
5452: struct ocfs2_xattr_block *xb =
5453: (struct ocfs2_xattr_block *)root_bh->b_data;
5454: struct ocfs2_alloc_context *meta_ac = NULL;
5455: struct ocfs2_cached_dealloc_ctxt dealloc;
5456: struct ocfs2_extent_tree et;
5457:
5458: ret = ocfs2_iterate_xattr_buckets(inode, blkno, len,
5459: ocfs2_delete_xattr_in_bucket, para);
5460: if (ret) {
5461: mlog_errno(ret);
5462: return ret;
5463: }
5464:
5465: ocfs2_init_xattr_tree_extent_tree(&et, INODE_CACHE(inode), root_bh);
5466:
5467: ocfs2_init_dealloc_ctxt(&dealloc);
5468:
5469: trace_ocfs2_rm_xattr_cluster(
5470: (unsigned long long)OCFS2_I(inode)->ip_blkno,
5471: (unsigned long long)blkno, cpos, len);
5472:
5473: ocfs2_remove_xattr_clusters_from_cache(INODE_CACHE(inode), blkno,
5474: len);
5475:
5476: ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
5477: if (ret) {
5478: mlog_errno(ret);
5479: return ret;
5480: }
5481:
5482: inode_lock(tl_inode);
5483:
5484: if (ocfs2_truncate_log_needs_flush(osb)) {
5485: ret = __ocfs2_flush_truncate_log(osb);
5486: if (ret < 0) {
5487: mlog_errno(ret);
5488: goto out;
5489: }
5490: }
5491:
5492: handle = ocfs2_start_trans(osb, ocfs2_remove_extent_credits(osb->sb));
5493: if (IS_ERR(handle)) {
5494: ret = -ENOMEM;
5495: mlog_errno(ret);
5496: goto out;
5497: }
5498:
5499: ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode), root_bh,
5500: OCFS2_JOURNAL_ACCESS_WRITE);
5501: if (ret) {
5502: mlog_errno(ret);
5503: goto out_commit;
5504: }
5505:
5506: ret = ocfs2_remove_extent(handle, &et, cpos, len, meta_ac,
5507: &dealloc);
5508: if (ret) {
5509: mlog_errno(ret);
5510: goto out_commit;
5511: }
5512:
5513: le32_add_cpu(&xb->xb_attrs.xb_root.xt_clusters, -len);
5514: ocfs2_journal_dirty(handle, root_bh);
5515:
5516: ret = ocfs2_truncate_log_append(osb, handle, blkno, len);
5517: if (ret)
5518: mlog_errno(ret);
5519: ocfs2_update_inode_fsync_trans(handle, inode, 0);
5520:
5521: out_commit:
5522: ocfs2_commit_trans(osb, handle);
5523: out:
5524: ocfs2_schedule_truncate_log_flush(osb, 1);
5525:
5526: inode_unlock(tl_inode);
5527:
5528: if (meta_ac)
5529: ocfs2_free_alloc_context(meta_ac);
5530:
5531: ocfs2_run_deallocs(osb, &dealloc);
5532:
5533: return ret;
5534: }
SourceFile:fs/ocfs2/xattr.c]
|
| 103/4 |
2026/05/29 17:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 31032
output: 44
thoughts: 45
Thoughts: Okay, here's my take on those thoughts, framed as an expert's understanding of the code:
**Analyzing `ocfs2_rm_xattr_cluster` and `ocfs2_write_begin_nolock`**
Right, so I see that in the `ocfs2_rm_xattr_cluster` function, the `meta_ac` structure is freed at the very end. That's good; it's the expected behavior. No obvious memory leaks or orphan operations are immediately apparent there. It looks like the cleanup is correctly handled after the xattr removal. Always good to confirm these basics.
Now, let's shift our focus and take a closer look at `ocfs2_write_begin_nolock`. I need to understand how the write operations are initiated, especially in the context of avoiding lock contention, which could be relevant to the previous xattr operation if there's any overlap in resource usage. I want to see how the cluster is managing the beginning of write operations in a potentially unlocked environment. This function is key to understand how atomicity, consistency and concurrency is maintained when we deal with writes.
|
| 104/4 |
2026/05/29 17:01 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/ocfs2/aops.c Name:ocfs2_write_begin_nolock]
Results: map[SourceCode:1625: int ocfs2_write_begin_nolock(struct address_space *mapping,
1626: loff_t pos, unsigned len, ocfs2_write_type_t type,
1627: struct folio **foliop, void **fsdata,
1628: struct buffer_head *di_bh, struct folio *mmap_folio)
1629: {
1630: int ret, cluster_of_pages, credits = OCFS2_INODE_UPDATE_CREDITS;
1631: unsigned int clusters_to_alloc, extents_to_split, clusters_need = 0;
1632: struct ocfs2_write_ctxt *wc;
1633: struct inode *inode = mapping->host;
1634: struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1635: struct ocfs2_dinode *di;
1636: struct ocfs2_alloc_context *data_ac = NULL;
1637: struct ocfs2_alloc_context *meta_ac = NULL;
1638: handle_t *handle;
1639: struct ocfs2_extent_tree et;
1640: int try_free = 1, ret1;
1641:
1642: try_again:
1643: ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, type, di_bh);
1644: if (ret) {
1645: mlog_errno(ret);
1646: return ret;
1647: }
1648:
1649: if (ocfs2_supports_inline_data(osb)) {
1650: ret = ocfs2_try_to_write_inline_data(mapping, inode, pos, len,
1651: mmap_folio, wc);
1652: if (ret == 1) {
1653: ret = 0;
1654: goto success;
1655: }
1656: if (ret < 0) {
1657: mlog_errno(ret);
1658: goto out;
1659: }
1660: }
1661:
1662: /* Direct io change i_size late, should not zero tail here. */
1663: if (type != OCFS2_WRITE_DIRECT) {
1664: if (ocfs2_sparse_alloc(osb))
1665: ret = ocfs2_zero_tail(inode, di_bh, pos);
1666: else
1667: ret = ocfs2_expand_nonsparse_inode(inode, di_bh, pos,
1668: len, wc);
1669: if (ret) {
1670: mlog_errno(ret);
1671: goto out;
1672: }
1673: }
1674:
1675: ret = ocfs2_check_range_for_refcount(inode, pos, len);
1676: if (ret < 0) {
1677: mlog_errno(ret);
1678: goto out;
1679: } else if (ret == 1) {
1680: clusters_need = wc->w_clen;
1681: ret = ocfs2_refcount_cow(inode, di_bh,
1682: wc->w_cpos, wc->w_clen, UINT_MAX);
1683: if (ret) {
1684: mlog_errno(ret);
1685: goto out;
1686: }
1687: }
1688:
1689: ret = ocfs2_populate_write_desc(inode, wc, &clusters_to_alloc,
1690: &extents_to_split);
1691: if (ret) {
1692: mlog_errno(ret);
1693: goto out;
1694: }
1695: clusters_need += clusters_to_alloc;
1696:
1697: di = (struct ocfs2_dinode *)wc->w_di_bh->b_data;
1698:
1699: trace_ocfs2_write_begin_nolock(
1700: (unsigned long long)OCFS2_I(inode)->ip_blkno,
1701: (long long)i_size_read(inode),
1702: le32_to_cpu(di->i_clusters),
1703: pos, len, type, mmap_folio,
1704: clusters_to_alloc, extents_to_split);
1705:
1706: /*
1707: * We set w_target_from, w_target_to here so that
1708: * ocfs2_write_end() knows which range in the target page to
1709: * write out. An allocation requires that we write the entire
1710: * cluster range.
1711: */
1712: if (clusters_to_alloc || extents_to_split) {
1713: /*
1714: * XXX: We are stretching the limits of
1715: * ocfs2_lock_allocators(). It greatly over-estimates
1716: * the work to be done.
1717: */
1718: ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode),
1719: wc->w_di_bh);
1720: ret = ocfs2_lock_allocators(inode, &et,
1721: clusters_to_alloc, extents_to_split,
1722: &data_ac, &meta_ac);
1723: if (ret) {
1724: mlog_errno(ret);
1725: goto out;
1726: }
1727:
1728: if (data_ac)
1729: data_ac->ac_resv = &OCFS2_I(inode)->ip_la_data_resv;
1730:
1731: credits = ocfs2_calc_extend_credits(inode->i_sb,
1732: &di->id2.i_list);
1733: } else if (type == OCFS2_WRITE_DIRECT)
1734: /* direct write needs not to start trans if no extents alloc. */
1735: goto success;
1736:
1737: /*
1738: * We have to zero sparse allocated clusters, unwritten extent clusters,
1739: * and non-sparse clusters we just extended. For non-sparse writes,
1740: * we know zeros will only be needed in the first and/or last cluster.
1741: */
1742: if (wc->w_clen && (wc->w_desc[0].c_needs_zero ||
1743: wc->w_desc[wc->w_clen - 1].c_needs_zero))
1744: cluster_of_pages = 1;
1745: else
1746: cluster_of_pages = 0;
1747:
1748: ocfs2_set_target_boundaries(osb, wc, pos, len, cluster_of_pages);
1749:
1750: handle = ocfs2_start_trans(osb, credits);
1751: if (IS_ERR(handle)) {
1752: ret = PTR_ERR(handle);
1753: mlog_errno(ret);
1754: goto out;
1755: }
1756:
1757: wc->w_handle = handle;
1758:
1759: if (clusters_to_alloc) {
1760: ret = dquot_alloc_space_nodirty(inode,
1761: ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc));
1762: if (ret)
1763: goto out_commit;
1764: }
1765:
1766: ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), wc->w_di_bh,
1767: OCFS2_JOURNAL_ACCESS_WRITE);
1768: if (ret) {
1769: mlog_errno(ret);
1770: goto out_quota;
1771: }
1772:
1773: /*
1774: * Fill our folio array first. That way we've grabbed enough so
1775: * that we can zero and flush if we error after adding the
1776: * extent.
1777: */
1778: ret = ocfs2_grab_folios_for_write(mapping, wc, wc->w_cpos, pos, len,
1779: cluster_of_pages, mmap_folio);
1780: if (ret) {
1781: /*
1782: * ocfs2_grab_folios_for_write() returns -EAGAIN if it
1783: * could not lock the target folio. In this case, we exit
1784: * with no error and no target folio. This will trigger
1785: * the caller, page_mkwrite(), to re-try the operation.
1786: */
1787: if (type == OCFS2_WRITE_MMAP && ret == -EAGAIN) {
1788: BUG_ON(wc->w_target_folio);
1789: ret = 0;
1790: goto out_quota;
1791: }
1792:
1793: mlog_errno(ret);
1794: goto out_quota;
1795: }
1796:
1797: ret = ocfs2_write_cluster_by_desc(mapping, data_ac, meta_ac, wc, pos,
1798: len);
1799: if (ret) {
1800: mlog_errno(ret);
1801: goto out_quota;
1802: }
1803:
1804: if (data_ac)
1805: ocfs2_free_alloc_context(data_ac);
1806: if (meta_ac)
1807: ocfs2_free_alloc_context(meta_ac);
1808:
1809: success:
1810: if (foliop)
1811: *foliop = wc->w_target_folio;
1812: *fsdata = wc;
1813: return 0;
1814: out_quota:
1815: if (clusters_to_alloc)
1816: dquot_free_space(inode,
1817: ocfs2_clusters_to_bytes(osb->sb, clusters_to_alloc));
1818: out_commit:
1819: ocfs2_commit_trans(osb, handle);
1820:
1821: out:
1822: /*
1823: * The mmapped page won't be unlocked in ocfs2_free_write_ctxt(),
1824: * even in case of error here like ENOSPC and ENOMEM. So, we need
1825: * to unlock the target page manually to prevent deadlocks when
1826: * retrying again on ENOSPC, or when returning non-VM_FAULT_LOCKED
1827: * to VM code.
1828: */
1829: if (wc->w_target_locked)
1830: folio_unlock(mmap_folio);
1831:
1832: ocfs2_free_write_ctxt(inode, wc);
1833:
1834: if (data_ac) {
1835: ocfs2_free_alloc_context(data_ac);
1836: data_ac = NULL;
1837: }
1838: if (meta_ac) {
1839: ocfs2_free_alloc_context(meta_ac);
1840: meta_ac = NULL;
1841: }
1842:
1843: if (ret == -ENOSPC && try_free) {
1844: /*
1845: * Try to free some truncate log so that we can have enough
1846: * clusters to allocate.
1847: */
1848: try_free = 0;
1849:
1850: ret1 = ocfs2_try_to_free_truncate_log(osb, clusters_need);
1851: if (ret1 == 1)
1852: goto try_again;
1853:
1854: if (ret1 < 0)
1855: mlog_errno(ret1);
1856: }
1857:
1858: return ret;
1859: }
SourceFile:fs/ocfs2/aops.c]
|
| 105/4 |
2026/05/29 17:01 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 35007
output: 15
thoughts: 90
Thoughts: Here's my analysis of this code snippet:
**Potential Concurrency Issue in OCFS2 Write Operations**
Okay, so I'm looking at `ocfs2_write_begin_nolock`, and the first thing that jumps out is that it releases both `data_ac` and `meta_ac` before returning. No orphan operations are involved here. That seems fine, a pretty standard pattern. But this makes me think a bit more deeply about where these two locks, `EXTENT_ALLOC_SYSTEM_INODE` and `ORPHAN_DIR_SYSTEM_INODE`, could possibly collide.
Based on this, it looks like the *only* place where `EXTENT_ALLOC_SYSTEM_INODE` might be held concurrently with the acquisition of `ORPHAN_DIR_SYSTEM_INODE` is within `ocfs2_dio_end_io_write`. That's the critical section to examine more closely. It's time to dig into that function and trace the lock acquisition patterns within a bit more carefully. I'll need to review that patch diff more precisely.
|
| 106/4 |
2026/05/29 17:01 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 6ec198bda..fe1339fbd 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2266,139 +2266,144 @@ static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
static int ocfs2_dio_end_io_write(struct inode *inode,
struct ocfs2_dio_write_ctxt *dwc,
loff_t offset,
ssize_t bytes)
{
struct ocfs2_cached_dealloc_ctxt dealloc;
struct ocfs2_extent_tree et;
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
struct ocfs2_inode_info *oi = OCFS2_I(inode);
struct ocfs2_unwritten_extent *ue = NULL;
struct buffer_head *di_bh = NULL;
struct ocfs2_dinode *di;
struct ocfs2_alloc_context *data_ac = NULL;
struct ocfs2_alloc_context *meta_ac = NULL;
handle_t *handle = NULL;
loff_t end = offset + bytes;
int ret = 0, credits = 0, batch = 0;
ocfs2_init_dealloc_ctxt(&dealloc);
/* We do clear unwritten, delete orphan, change i_size here. If neither
* of these happen, we can skip all this. */
if (list_empty(&dwc->dw_zero_list) &&
end <= i_size_read(inode) &&
!dwc->dw_orphaned)
goto out;
ret = ocfs2_inode_lock(inode, &di_bh, 1);
if (ret < 0) {
mlog_errno(ret);
goto out;
}
down_write(&oi->ip_alloc_sem);
di = (struct ocfs2_dinode *)di_bh->b_data;
ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh);
/* Attach dealloc with extent tree in case that we may reuse extents
* which are already unlinked from current extent tree due to extent
* rotation and merging.
*/
et.et_dealloc = &dealloc;
ret = ocfs2_lock_allocators(inode, &et, 0, dwc->dw_zero_count*2,
&data_ac, &meta_ac);
if (ret) {
mlog_errno(ret);
goto unlock;
}
credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) {
if (!handle) {
handle = ocfs2_start_trans(osb, credits);
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
mlog_errno(ret);
goto unlock;
}
ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) {
mlog_errno(ret);
goto commit;
}
}
ret = ocfs2_assure_trans_credits(handle, credits);
if (ret < 0) {
mlog_errno(ret);
goto commit;
}
ret = ocfs2_mark_extent_written(inode, &et, handle,
ue->ue_cpos, 1,
ue->ue_phys,
meta_ac, &dealloc);
if (ret < 0) {
mlog_errno(ret);
goto commit;
}
if (++batch == OCFS2_DIO_MARK_EXTENT_BATCH) {
ocfs2_commit_trans(osb, handle);
handle = NULL;
batch = 0;
}
}
if (end > i_size_read(inode)) {
if (!handle) {
handle = ocfs2_start_trans(osb, credits);
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
mlog_errno(ret);
goto unlock;
}
}
ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
if (ret < 0)
mlog_errno(ret);
}
-commit:
- if (handle)
- ocfs2_commit_trans(osb, handle);
-unlock:
- up_write(&oi->ip_alloc_sem);
+ commit:
+ if (handle)
+ ocfs2_commit_trans(osb, handle);
+ unlock:
+ up_write(&oi->ip_alloc_sem);
- /* everything looks good, let's start the cleanup */
- if (!ret && dwc->dw_orphaned) {
- BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
- ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
- if (ret < 0)
- mlog_errno(ret);
- }
- ocfs2_inode_unlock(inode, 1);
- brelse(di_bh);
-out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
- ocfs2_run_deallocs(osb, &dealloc);
- ocfs2_dio_free_write_ctx(inode, dwc);
+ /* everything looks good, let's start the cleanup */
+ if (!ret && dwc->dw_orphaned) {
+ BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
- return ret;
-}
+ ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
+ if (ret < 0)
+ mlog_errno(ret);
+ }
+ ocfs2_inode_unlock(inode, 1);
+ brelse(di_bh);
+ out:
+ ocfs2_run_deallocs(osb, &dealloc);
+ ocfs2_dio_free_write_ctx(inode, dwc);
+
+ return ret;
+ }
/*
* ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
* particularly interested in the aio/dio case. We use the rw_lock DLM lock
* to protect io on one node from truncation on another.
*/
static int ocfs2_dio_end_io(struct kiocb *iocb,
loff_t offset,
ssize_t bytes,
void *private)
]
|
| 107/4 |
2026/05/29 17:01 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 37407
output: 619
thoughts: 37
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Debugging Indentation Anomalies**
Alright, looking at this code or configuration output, my initial impression is that the indentation on these labels β `commit:`, `unlock:`, and `out:` β is off. It's immediately noticeable, and my instinct is that they should be flush left, starting at the beginning of their respective lines. Clearly, that is where the labels should be rendered, so I should ensure that is how they are. Given the context, the current formatting is likely a bug. So, let's address that indentation problem directly. I should go in and correct it.
|
| 108/4 |
2026/05/29 17:01 |
tool |
codeeditor |
0m
Args: map[CurrentCode: commit:
if (handle)
ocfs2_commit_trans(osb, handle);
unlock:
up_write(&oi->ip_alloc_sem);
if (data_ac) {
ocfs2_free_alloc_context(data_ac);
data_ac = NULL;
}
if (meta_ac) {
ocfs2_free_alloc_context(meta_ac);
meta_ac = NULL;
}
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
if (ret < 0)
mlog_errno(ret);
}
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
return ret;
} NewCode:commit:
if (handle)
ocfs2_commit_trans(osb, handle);
unlock:
up_write(&oi->ip_alloc_sem);
if (data_ac) {
ocfs2_free_alloc_context(data_ac);
data_ac = NULL;
}
if (meta_ac) {
ocfs2_free_alloc_context(meta_ac);
meta_ac = NULL;
}
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
if (ret < 0)
mlog_errno(ret);
}
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
return ret;
} SourceFile:fs/ocfs2/aops.c]
Results:
|
| 109/4 |
2026/05/29 17:01 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 38212
output: 15
thoughts: 9
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:
**Re-Examining the Diff**
Alright, before I dive into the granular details and start making assumptions, let's take another pass over this patch diff. I need to make absolutely sure I haven't missed any subtle implications or unintended consequences, especially in the areas I flagged earlier. It's easy to get caught up in the specifics, the elegance of the new code, or the immediate problem it solves, and overlook something deeper. This is where experience kicks in; I want to focus on ensuring that this will integrate smoothly with the existing architecture and doesn't introduce any unforeseen performance bottlenecks or security vulnerabilities. A second, more deliberate review is always a good idea before proceeding.
|
| 110/4 |
2026/05/29 17:01 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 6ec198bda..4acdbb708 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2266,135 +2266,140 @@ static int ocfs2_dio_wr_get_block(struct inode *inode, sector_t iblock,
static int ocfs2_dio_end_io_write(struct inode *inode,
struct ocfs2_dio_write_ctxt *dwc,
loff_t offset,
ssize_t bytes)
{
struct ocfs2_cached_dealloc_ctxt dealloc;
struct ocfs2_extent_tree et;
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
struct ocfs2_inode_info *oi = OCFS2_I(inode);
struct ocfs2_unwritten_extent *ue = NULL;
struct buffer_head *di_bh = NULL;
struct ocfs2_dinode *di;
struct ocfs2_alloc_context *data_ac = NULL;
struct ocfs2_alloc_context *meta_ac = NULL;
handle_t *handle = NULL;
loff_t end = offset + bytes;
int ret = 0, credits = 0, batch = 0;
ocfs2_init_dealloc_ctxt(&dealloc);
/* We do clear unwritten, delete orphan, change i_size here. If neither
* of these happen, we can skip all this. */
if (list_empty(&dwc->dw_zero_list) &&
end <= i_size_read(inode) &&
!dwc->dw_orphaned)
goto out;
ret = ocfs2_inode_lock(inode, &di_bh, 1);
if (ret < 0) {
mlog_errno(ret);
goto out;
}
down_write(&oi->ip_alloc_sem);
di = (struct ocfs2_dinode *)di_bh->b_data;
ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh);
/* Attach dealloc with extent tree in case that we may reuse extents
* which are already unlinked from current extent tree due to extent
* rotation and merging.
*/
et.et_dealloc = &dealloc;
ret = ocfs2_lock_allocators(inode, &et, 0, dwc->dw_zero_count*2,
&data_ac, &meta_ac);
if (ret) {
mlog_errno(ret);
goto unlock;
}
credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) {
if (!handle) {
handle = ocfs2_start_trans(osb, credits);
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
mlog_errno(ret);
goto unlock;
}
ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) {
mlog_errno(ret);
goto commit;
}
}
ret = ocfs2_assure_trans_credits(handle, credits);
if (ret < 0) {
mlog_errno(ret);
goto commit;
}
ret = ocfs2_mark_extent_written(inode, &et, handle,
ue->ue_cpos, 1,
ue->ue_phys,
meta_ac, &dealloc);
if (ret < 0) {
mlog_errno(ret);
goto commit;
}
if (++batch == OCFS2_DIO_MARK_EXTENT_BATCH) {
ocfs2_commit_trans(osb, handle);
handle = NULL;
batch = 0;
}
}
if (end > i_size_read(inode)) {
if (!handle) {
handle = ocfs2_start_trans(osb, credits);
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
mlog_errno(ret);
goto unlock;
}
}
ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
if (ret < 0)
mlog_errno(ret);
}
commit:
if (handle)
ocfs2_commit_trans(osb, handle);
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
if (ret < 0)
mlog_errno(ret);
}
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
return ret;
}
/*
* ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
* particularly interested in the aio/dio case. We use the rw_lock DLM lock
* to protect io on one node from truncation on another.
*/
]
|
| 111/4 |
2026/05/29 17:01 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 40172
output: 571
thoughts: 567
Thoughts: **My Analysis of the OCFS2 Lockdep Warning Fix**
Okay, so I've looked over this patch, and it seems clean and correct β the code looks good. The issue, as I understand it, is a lockdep warning related to a circular dependency with three OCFS2 system inode locks: `INODE_ALLOC_SYSTEM_INODE`, `EXTENT_ALLOC_SYSTEM_INODE`, and `ORPHAN_DIR_SYSTEM_INODE`.
The problem arises from three specific code paths: `ocfs2_mknod()` establishes `INODE_ALLOC_SYSTEM_INODE` before `EXTENT_ALLOC_SYSTEM_INODE`, `ocfs2_dio_end_io_write()` has `EXTENT_ALLOC_SYSTEM_INODE` before `ORPHAN_DIR_SYSTEM_INODE`, and then `ocfs2_wipe_inode()` does `ORPHAN_DIR_SYSTEM_INODE` then `INODE_ALLOC_SYSTEM_INODE`, making a cycle.
The solution is to break this cycle by addressing the dependency in `ocfs2_dio_end_io_write()`. The key insight is that the `data_ac` and `meta_ac` allocation contexts, which hold the `EXTENT_ALLOC_SYSTEM_INODE` lock, are only needed for the transaction marking extents as written. Once `ocfs2_commit_trans()` completes and the allocation semaphore is released via `up_write(&oi->ip_alloc_sem)`, those contexts are no longer necessary. So, the patch proposes freeing those allocation contexts *before* calling `ocfs2_del_inode_from_orphan()`, thereby releasing `EXTENT_ALLOC_SYSTEM_INODE`.
I've made the code change in `fs/ocfs2/aops.c` as described, moving the freeing of the allocation contexts right after the `up_write` call and before the call to `ocfs2_del_inode_from_orphan()`. I've also carefully reviewed the other calls to `ocfs2_del_inode_from_orphan()` in `ocfs2_recover_orphans` and `ocfs2_add_inode_to_orphan()` and confirmed that they don't hold `EXTENT_ALLOC_SYSTEM_INODE` at all. Furthermore, I checked other locations where `ocfs2_lock_allocators()` is used and can confirm that they don't acquire the `ORPHAN_DIR_SYSTEM_INODE` while holding the allocation contexts, which would negate this fix.
This looks like a solid fix to me. It elegantly breaks the lock dependency without introducing any new locking issues, so I think this will resolve the lockdep warning.
|
| 112/3 |
2026/05/29 17:01 |
action |
test-patch |
26m
Results: map[PatchDiff:diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 6ec198bda..4acdbb708 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2372,6 +2372,15 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2392,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
TestError:]
|
| 113/1 |
2026/05/29 17:28 |
agent |
fixes-finder |
1m
Model:
Results: map[FixesHash:d647c5b2fbf81560818dacade360abc8c00a9665]
Instruction:
You are an experienced Linux kernel developer tasked with identifying the commit
that introduced the bug being fixed. Identifying the correct buggy commit is crucial
for proper kernel maintenance (backporting to stable trees, etc.).
Your investigation strategy:
1. Examine the patch that fixes the bug. Use git tools (like git-log or git-blame)
to trace the history of the lines or functions modified by the patch.
2. Analyze the stack trace in the crash report. Identify the key files and functions
involved in the crash and investigate their history to see when the problematic
logic was introduced.
3. Compare the bug explanation with the commit history to find the point where
the described logic error first appeared.
A bug is typically introduced when a piece of code is first written, or when
a refactoring changed its logic in a way that introduced the bug.
Trace the history of relevant symbols or find when specific code patterns were introduced/removed.
You must provide exactly one bug-introducing commit hash.
If you are unable to confidently determine the bug-introducing commit after investigation,
return an empty string rather than guessing.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The crash is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #1 Not tainted
------------------------------------------------------
syz-executor/6069 is trying to acquire lock:
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
but task is already holding lock:
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_del_inode_from_orphan+0x12e/0x7a0 fs/ocfs2/namei.c:2728
ocfs2_dio_end_io_write fs/ocfs2/aops.c:2379 [inline]
ocfs2_dio_end_io+0xf9c/0x1370 fs/ocfs2/aops.c:2418
dio_complete+0x25b/0x790 fs/direct-io.c:281
__blockdev_direct_IO+0x2e5d/0x34e0 fs/direct-io.c:1303
ocfs2_direct_IO+0x251/0x2c0 fs/ocfs2/aops.c:2455
generic_file_direct_write+0x1db/0x3e0 mm/filemap.c:4259
__generic_file_write_iter+0x11d/0x230 mm/filemap.c:4428
ocfs2_file_write_iter+0x1663/0x1e70 fs/ocfs2/file.c:2476
do_iter_readv_writev+0x619/0x8c0 fs/read_write.c:-1
vfs_writev+0x33c/0x990 fs/read_write.c:1059
do_writev+0x154/0x2e0 fs/read_write.c:1105
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_reserve_suballoc_bits+0x16d/0x4840 fs/ocfs2/suballoc.c:882
ocfs2_reserve_new_metadata_blocks+0x415/0x9a0 fs/ocfs2/suballoc.c:1078
ocfs2_mknod+0x10f3/0x2260 fs/ocfs2/namei.c:351
ocfs2_create+0x195/0x460 fs/ocfs2/namei.c:677
lookup_open fs/namei.c:4511 [inline]
open_last_lookups fs/namei.c:4611 [inline]
path_openat+0x1395/0x3860 fs/namei.c:4855
do_file_open+0x23e/0x4a0 fs/namei.c:4887
do_sys_openat2+0x113/0x200 fs/open.c:1364
do_sys_open fs/open.c:1370 [inline]
__do_sys_openat fs/open.c:1386 [inline]
__se_sys_openat fs/open.c:1381 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
*** DEADLOCK ***
4 locks held by syz-executor/6069:
#0: ffff8881161a4410 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:1074 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: __start_dirop fs/namei.c:2914 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: start_dirop fs/namei.c:2938 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: filename_rmdir+0x1cd/0x520 fs/namei.c:5414
#2: ffff8881166b0bc0 (&osb->nfs_sync_rwlock){.+.+}-{4:4}, at: ocfs2_nfs_sync_lock+0x106/0x270 fs/ocfs2/dlmglue.c:2875
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
stack backtrace:
CPU: 1 UID: 0 PID: 6069 Comm: syz-executor Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e1/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f51b819bf77
Code: 77 01 c3 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 b8 07 01 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd5ea06718 EFLAGS: 00000207 ORIG_RAX: 0000000000000107
RAX: ffffffffffffffda RBX: 0000000000000065 RCX: 00007f51b819bf77
RDX: 0000000000000200 RSI: 00007ffd5ea078c0 RDI: 00000000ffffff9c
RBP: 00007f51b82321ca R08: 0000000000018560 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffd5ea078c0
R13: 00007f51b82321ca R14: 000000000001819f R15: 00007ffd5ea09a80
</TASK>
The explanation of the root cause is:
The lockdep warning reports a circular locking dependency involving three OCFS2 system inode locks (which all belong to the `ocfs2_sysfile_lock_key` lock class, but are distinct locks based on their system inode type).
The three locks involved are:
1. `INODE_ALLOC_SYSTEM_INODE`
2. `EXTENT_ALLOC_SYSTEM_INODE`
3. `ORPHAN_DIR_SYSTEM_INODE`
### Root Cause Analysis
The circular dependency is formed by three separate code paths that establish the following lock ordering:
**1. `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE`**
In `ocfs2_mknod()` (`fs/ocfs2/namei.c`), the code first reserves an inode by calling `ocfs2_reserve_new_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock. Shortly after, it reserves metadata blocks by calling `ocfs2_reserve_new_metadata_blocks()`, which acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Both locks are held concurrently until the end of the function (or upon error), establishing this dependency.
**2. `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`**
In `ocfs2_dio_end_io_write()` (`fs/ocfs2/aops.c`), the code allocates metadata blocks for unwritten extents by calling `ocfs2_lock_allocators()`. This allocates `meta_ac` and acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Later in the same function, if the inode was orphaned, it calls `ocfs2_del_inode_from_orphan()`, which acquires the `ORPHAN_DIR_SYSTEM_INODE` lock. The `meta_ac` context (and thus the `EXTENT_ALLOC_SYSTEM_INODE` lock) is only freed at the very end of the function, meaning it is held while `ORPHAN_DIR_SYSTEM_INODE` is acquired.
**3. `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`**
In `ocfs2_wipe_inode()` (`fs/ocfs2/inode.c`), the `ORPHAN_DIR_SYSTEM_INODE` lock is acquired first to prevent races with recovery completion. While holding this lock, it calls `ocfs2_remove_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock to free the inode. (A similar dependency is also established in `ocfs2_prep_new_orphaned_file()`).
Combining these three paths creates the circular dependency:
`INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`.
### How to Fix
We can break the cycle by addressing the second dependency (`EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`) in `ocfs2_dio_end_io_write()`.
The `data_ac` and `meta_ac` allocation contexts are only needed for the transaction that marks the extents as written. Once the transaction is committed via `ocfs2_commit_trans()` and the allocation semaphore is released via `up_write(&oi->ip_alloc_sem)`, these contexts are no longer needed. We can safely free them (which releases the `EXTENT_ALLOC_SYSTEM_INODE` lock) *before* calling `ocfs2_del_inode_from_orphan()`.
Here is the proposed fix for `fs/ocfs2/aops.c`:
```c
@@ -2372,6 +2372,16 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2393,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
```
This ensures that the `EXTENT_ALLOC_SYSTEM_INODE` lock is dropped before we attempt to acquire the `ORPHAN_DIR_SYSTEM_INODE` lock, successfully breaking the circular dependency.
The patch that fixes the bug is:
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 6ec198bda..4acdbb708 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2372,6 +2372,15 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2392,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
Search for the commit(s) that introduced this bug.
|
| 114/2 |
2026/05/29 17:28 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 10059
output: 43
thoughts: 214
Thoughts: **Tracing the Bug's Origins**
Okay, so we've got a patch that's fixing a bug, and it looks like the issue stems from the order of operations in `ocfs2_dio_end_io_write` within `fs/ocfs2/aops.c`. Specifically, it seems like freeing some allocation contexts β `data_ac` and `meta_ac` (which releases the `EXTENT_ALLOC_SYSTEM_INODE` lock) β was happening *after* calling `ocfs2_del_inode_from_orphan()` (which grabs the `ORPHAN_DIR_SYSTEM_INODE` lock). That's a classic locking order issue, and my gut says this reordering is the key.
My immediate thought is to find the exact commit that introduced this particular problematic sequencing. So, I need to zero in on the history of this specific function. The code in `ocfs2_dio_end_io_write` is the target, and I need to figure out when this logic was introduced or modified to *be* in this state.
Right, `git log` is the perfect tool for this. I'll use it to trace the history of `ocfs2_dio_end_io_write` within `fs/ocfs2/aops.c`, and I'll hopefully find the culprit commit pretty quickly that I can then analyze in more detail.
|
| 115/2 |
2026/05/29 17:28 |
tool |
git-log |
0m
Args: map[SourcePath:fs/ocfs2/aops.c SymbolName:ocfs2_dio_end_io_write]
Results: map[Output:d647c5b2fbf8 ocfs2: split transactions in dio completion to avoid credit exhaustion
b02da26a992d ocfs2: fix possible deadlock between unlink and dio_end_io_write
be346c1a6eeb ocfs2: fix DIO failure due to insufficient transaction credits
137cebf9432e fs/ocfs2: fix comments mentioning i_mutex
90bd070aae6c ocfs2: fix deadlock between setattr and dio_end_io_write
71a36944042b ocfs2: try to reuse extent block in dealloc without meta_alloc
aef73a61c01a ocfs2: fix bad pointer cast
085549553dca ocfs2: don't eat io errors during _dio_end_io_write
7b9743eb8932 ocfs2: don't open-code inode_lock/inode_unlock
28888681b4f6 ocfs2: fix a deadlock issue in ocfs2_dio_end_io_write()
]
|
| 116/2 |
2026/05/29 17:29 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 10905
output: 44
thoughts: 146
Thoughts: **Analyzing a Potential Deadlock in OCFS2**
Okay, let's dive into this. I need to understand this potential deadlock situation. My initial focus is on commit `b02da26a992d` which is labelled "ocfs2: fix possible deadlock between unlink and dio_end_io_write" and also `28888681b4f6`, "ocfs2: fix a deadlock issue in ocfs2_dio_end_io_write()". Hmm, based on the description, the core of the problem seems to be `ocfs2_del_inode_from_orphan` being called while holding both `meta_ac` and `data_ac`. The key here is to see when `ocfs2_del_inode_from_orphan` was introduced into the execution path of `ocfs2_dio_end_io_write`. Understanding this will be crucial to tracing the code's evolution and what changes were made in relation to this function call.
|
| 117/2 |
2026/05/29 17:29 |
tool |
git-log |
0m
Args: map[CodeRegexp:ocfs2_del_inode_from_orphan PathPrefix:fs/ocfs2/aops.c]
Results: map[Output:d647c5b2fbf8 ocfs2: split transactions in dio completion to avoid credit exhaustion
c15471f79506 ocfs2: fix sparse file & data ordering issue in direct io
cf1776a9e834 ocfs2: fix a tiny race when truncate dio orohaned entry
24c40b329e03 ocfs2: implement ocfs2_direct_IO_write
]
|
| 118/2 |
2026/05/29 17:29 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 11434
output: 27
thoughts: 33
Thoughts: Okay, here's my interpretation of those thoughts, crafted with the understanding that I'm speaking to a fellow expert:
**Investigating Potential Anomalies**
Alright, my internal radar is pinging. I need to take a look at these two commits immediately. Let's dig into `c15471f79506` and `24c40b329e03`. Something in my gut tells me these warrant closer scrutiny. I suspect they may be related to the issue we're tracking, or perhaps represent an unexpected deviation from the norm. Let's see what these commits are hiding.
|
| 119/2 |
2026/05/29 17:29 |
tool |
git-show |
0m
Args:
Results: map[Output:commit c15471f79506830f80eca0e7fe09b8213953ab5f
Author: Ryan Ding <ryan.ding@oracle.com>
Date: Fri Mar 25 14:21:09 2016 -0700
ocfs2: fix sparse file & data ordering issue in direct io
There are mainly three issues in the direct io code path after commit
24c40b329e03 ("ocfs2: implement ocfs2_direct_IO_write"):
* Does not support sparse file.
* Does not support data ordering. eg: when write to a file hole, it
will alloc extent first. If system crashed before io finished, data
will corrupt.
* Potential risk when doing aio+dio. The -EIOCBQUEUED return value is
likely to be ignored by ocfs2_direct_IO_write().
To resolve above problems, re-design direct io code with following ideas:
* Use buffer io to fill in holes. And this will make better
performance also.
* Clear unwritten after direct write finished. So we can make sure
meta data changes after data write to disk. (Unwritten extent is
invisible to user, from user's view, meta data is not changed when
allocate an unwritten extent.)
* Clear ocfs2_direct_IO_write(). Do all ending work in end_io.
This patch has passed fs,dio,ltp-aiodio.part1,ltp-aiodio.part2,ltp-aiodio.part4
test cases of ltp.
For performance improvement, see following test result:
ocfs2 cluster size 1MB, ocfs2 volume is mounted on /mnt/.
The original way:
+ rm /mnt/test.img -f
+ dd if=/dev/zero of=/mnt/test.img bs=4K count=1048576 oflag=direct
1048576+0 records in
1048576+0 records out
4294967296 bytes (4.3 GB) copied, 1707.83 s, 2.5 MB/s
+ rm /mnt/test.img -f
+ dd if=/dev/zero of=/mnt/test.img bs=256K count=16384 oflag=direct
16384+0 records in
16384+0 records out
4294967296 bytes (4.3 GB) copied, 582.705 s, 7.4 MB/s
After this patch:
+ rm /mnt/test.img -f
+ dd if=/dev/zero of=/mnt/test.img bs=4K count=1048576 oflag=direct
1048576+0 records in
1048576+0 records out
4294967296 bytes (4.3 GB) copied, 64.6412 s, 66.4 MB/s
+ rm /mnt/test.img -f
+ dd if=/dev/zero of=/mnt/test.img bs=256K count=16384 oflag=direct
16384+0 records in
16384+0 records out
4294967296 bytes (4.3 GB) copied, 34.7611 s, 124 MB/s
Signed-off-by: Ryan Ding <ryan.ding@oracle.com>
Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Joseph Qi <joseph.qi@huawei.com>
Cc: Mark Fasheh <mfasheh@suse.de>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index c29d06634fd6..578ce225cf83 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -499,158 +499,6 @@ static sector_t ocfs2_bmap(struct address_space *mapping, sector_t block)
return status;
}
-/*
- * TODO: Make this into a generic get_blocks function.
- *
- * From do_direct_io in direct-io.c:
- * "So what we do is to permit the ->get_blocks function to populate
- * bh.b_size with the size of IO which is permitted at this offset and
- * this i_blkbits."
- *
- * This function is called directly from get_more_blocks in direct-io.c.
- *
- * called like this: dio->get_blocks(dio->inode, fs_startblk,
- * fs_count, map_bh, dio->rw == WRITE);
- */
-static int ocfs2_direct_IO_get_blocks(struct inode *inode, sector_t iblock,
- struct buffer_head *bh_result, int create)
-{
- int ret;
- u32 cpos = 0;
- int alloc_locked = 0;
- u64 p_blkno, inode_blocks, contig_blocks;
- unsigned int ext_flags;
- unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
- unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
- unsigned long len = bh_result->b_size;
- unsigned int clusters_to_alloc = 0, contig_clusters = 0;
-
- cpos = ocfs2_blocks_to_clusters(inode->i_sb, iblock);
-
- /* This function won't even be called if the request isn't all
- * nicely aligned and of the right size, so there's no need
- * for us to check any of that. */
-
- inode_blocks = ocfs2_blocks_for_bytes(inode->i_sb, i_size_read(inode));
-
- down_read(&OCFS2_I(inode)->ip_alloc_sem);
-
- /* This figures out the size of the next contiguous block, and
- * our logical offset */
- ret = ocfs2_extent_map_get_blocks(inode, iblock, &p_blkno,
- &contig_blocks, &ext_flags);
- up_read(&OCFS2_I(inode)->ip_alloc_sem);
-
- if (ret) {
- mlog(ML_ERROR, "get_blocks() failed iblock=%llu\n",
- (unsigned long long)iblock);
- ret = -EIO;
- goto bail;
- }
-
- /* We should already CoW the refcounted extent in case of create. */
- BUG_ON(create && (ext_flags & OCFS2_EXT_REFCOUNTED));
-
- /* allocate blocks if no p_blkno is found, and create == 1 */
- if (!p_blkno && create) {
- ret = ocfs2_inode_lock(inode, NULL, 1);
- if (ret < 0) {
- mlog_errno(ret);
- goto bail;
- }
-
- alloc_locked = 1;
-
- down_write(&OCFS2_I(inode)->ip_alloc_sem);
-
- /* fill hole, allocate blocks can't be larger than the size
- * of the hole */
- clusters_to_alloc = ocfs2_clusters_for_bytes(inode->i_sb, len);
- contig_clusters = ocfs2_clusters_for_blocks(inode->i_sb,
- contig_blocks);
- if (clusters_to_alloc > contig_clusters)
- clusters_to_alloc = contig_clusters;
-
- /* allocate extent and insert them into the extent tree */
- ret = ocfs2_extend_allocation(inode, cpos,
- clusters_to_alloc, 0);
- if (ret < 0) {
- up_write(&OCFS2_I(inode)->ip_alloc_sem);
- mlog_errno(ret);
- goto bail;
- }
-
- ret = ocfs2_extent_map_get_blocks(inode, iblock, &p_blkno,
- &contig_blocks, &ext_flags);
- if (ret < 0) {
- up_write(&OCFS2_I(inode)->ip_alloc_sem);
- mlog(ML_ERROR, "get_blocks() failed iblock=%llu\n",
- (unsigned long long)iblock);
- ret = -EIO;
- goto bail;
- }
- set_buffer_new(bh_result);
- up_write(&OCFS2_I(inode)->ip_alloc_sem);
- }
-
- /*
- * get_more_blocks() expects us to describe a hole by clearing
- * the mapped bit on bh_result().
- *
- * Consider an unwritten extent as a hole.
- */
- if (p_blkno && !(ext_flags & OCFS2_EXT_UNWRITTEN))
- map_bh(bh_result, inode->i_sb, p_blkno);
- else
- clear_buffer_mapped(bh_result);
-
- /* make sure we don't map more than max_blocks blocks here as
- that's all the kernel will handle at this point. */
- if (max_blocks < contig_blocks)
- contig_blocks = max_blocks;
- bh_result->b_size = contig_blocks << blocksize_bits;
-bail:
- if (alloc_locked)
- ocfs2_inode_unlock(inode, 1);
- return ret;
-}
-
-/*
- * ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
- * particularly interested in the aio/dio case. We use the rw_lock DLM lock
- * to protect io on one node from truncation on another.
- */
-static int ocfs2_dio_end_io(struct kiocb *iocb,
- loff_t offset,
- ssize_t bytes,
- void *private)
-{
- struct inode *inode = file_inode(iocb->ki_filp);
- int level;
-
- if (bytes <= 0)
- return 0;
-
- /* this io's submitter should not have unlocked this before we could */
- BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
-
- if (ocfs2_iocb_is_unaligned_aio(iocb)) {
- ocfs2_iocb_clear_unaligned_aio(iocb);
-
- mutex_unlock(&OCFS2_I(inode)->ip_unaligned_aio);
- }
-
- /* Let rw unlock to be done later to protect append direct io write */
- if (offset + bytes <= i_size_read(inode)) {
- ocfs2_iocb_clear_rw_locked(iocb);
-
- level = ocfs2_iocb_rw_locked_level(iocb);
- ocfs2_rw_unlock(inode, level);
- }
-
- return 0;
-}
-
static int ocfs2_releasepage(struct page *page, gfp_t wait)
{
if (!page_has_buffers(page))
@@ -658,363 +506,6 @@ static int ocfs2_releasepage(struct page *page, gfp_t wait)
return try_to_free_buffers(page);
}
-static int ocfs2_is_overwrite(struct ocfs2_super *osb,
- struct inode *inode, loff_t offset)
-{
- int ret = 0;
- u32 v_cpos = 0;
- u32 p_cpos = 0;
- unsigned int num_clusters = 0;
- unsigned int ext_flags = 0;
-
- v_cpos = ocfs2_bytes_to_clusters(osb->sb, offset);
- ret = ocfs2_get_clusters(inode, v_cpos, &p_cpos,
- &num_clusters, &ext_flags);
- if (ret < 0) {
- mlog_errno(ret);
- return ret;
- }
-
- if (p_cpos && !(ext_flags & OCFS2_EXT_UNWRITTEN))
- return 1;
-
- return 0;
-}
-
-static int ocfs2_direct_IO_zero_extend(struct ocfs2_super *osb,
- struct inode *inode, loff_t offset,
- u64 zero_len, int cluster_align)
-{
- u32 p_cpos = 0;
- u32 v_cpos = ocfs2_bytes_to_clusters(osb->sb, i_size_read(inode));
- unsigned int num_clusters = 0;
- unsigned int ext_flags = 0;
- int ret = 0;
-
- if (offset <= i_size_read(inode) || cluster_align)
- return 0;
-
- ret = ocfs2_get_clusters(inode, v_cpos, &p_cpos, &num_clusters,
- &ext_flags);
- if (ret < 0) {
- mlog_errno(ret);
- return ret;
- }
-
- if (p_cpos && !(ext_flags & OCFS2_EXT_UNWRITTEN)) {
- u64 s = i_size_read(inode);
- sector_t sector = ((u64)p_cpos << (osb->s_clustersize_bits - 9)) +
- (do_div(s, osb->s_clustersize) >> 9);
-
- ret = blkdev_issue_zeroout(osb->sb->s_bdev, sector,
- zero_len >> 9, GFP_NOFS, false);
- if (ret < 0)
- mlog_errno(ret);
- }
-
- return ret;
-}
-
-static int ocfs2_direct_IO_extend_no_holes(struct ocfs2_super *osb,
- struct inode *inode, loff_t offset)
-{
- u64 zero_start, zero_len, total_zero_len;
- u32 p_cpos = 0, clusters_to_add;
- u32 v_cpos = ocfs2_bytes_to_clusters(osb->sb, i_size_read(inode));
- unsigned int num_clusters = 0;
- unsigned int ext_flags = 0;
- u32 size_div, offset_div;
- int ret = 0;
-
- {
- u64 o = offset;
- u64 s = i_size_read(inode);
-
- offset_div = do_div(o, osb->s_clustersize);
- size_div = do_div(s, osb->s_clustersize);
- }
-
- if (offset <= i_size_read(inode))
- return 0;
-
- clusters_to_add = ocfs2_bytes_to_clusters(inode->i_sb, offset) -
- ocfs2_bytes_to_clusters(inode->i_sb, i_size_read(inode));
- total_zero_len = offset - i_size_read(inode);
- if (clusters_to_add)
- total_zero_len -= offset_div;
-
- /* Allocate clusters to fill out holes, and this is only needed
- * when we add more than one clusters. Otherwise the cluster will
- * be allocated during direct IO */
- if (clusters_to_add > 1) {
- ret = ocfs2_extend_allocation(inode,
- OCFS2_I(inode)->ip_clusters,
- clusters_to_add - 1, 0);
- if (ret) {
- mlog_errno(ret);
- goto out;
- }
- }
-
- while (total_zero_len) {
- ret = ocfs2_get_clusters(inode, v_cpos, &p_cpos, &num_clusters,
- &ext_flags);
- if (ret < 0) {
- mlog_errno(ret);
- goto out;
- }
-
- zero_start = ocfs2_clusters_to_bytes(osb->sb, p_cpos) +
- size_div;
- zero_len = ocfs2_clusters_to_bytes(osb->sb, num_clusters) -
- size_div;
- zero_len = min(total_zero_len, zero_len);
-
- if (p_cpos && !(ext_flags & OCFS2_EXT_UNWRITTEN)) {
- ret = blkdev_issue_zeroout(osb->sb->s_bdev,
- zero_start >> 9, zero_len >> 9,
- GFP_NOFS, false);
- if (ret < 0) {
- mlog_errno(ret);
- goto out;
- }
- }
-
- total_zero_len -= zero_len;
- v_cpos += ocfs2_bytes_to_clusters(osb->sb, zero_len + size_div);
-
- /* Only at first iteration can be cluster not aligned.
- * So set size_div to 0 for the rest */
- size_div = 0;
- }
-
-out:
- return ret;
-}
-
-static ssize_t ocfs2_direct_IO_write(struct kiocb *iocb,
- struct iov_iter *iter,
- loff_t offset)
-{
- ssize_t ret = 0;
- ssize_t written = 0;
- bool orphaned = false;
- int is_overwrite = 0;
- struct file *file = iocb->ki_filp;
- struct inode *inode = file_inode(file)->i_mapping->host;
- struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
- struct buffer_head *di_bh = NULL;
- size_t count = iter->count;
- journal_t *journal = osb->journal->j_journal;
- u64 zero_len_head, zero_len_tail;
- int cluster_align_head, cluster_align_tail;
- loff_t final_size = offset + count;
- int append_write = offset >= i_size_read(inode) ? 1 : 0;
- unsigned int num_clusters = 0;
- unsigned int ext_flags = 0;
-
- {
- u64 o = offset;
- u64 s = i_size_read(inode);
-
- zero_len_head = do_div(o, 1 << osb->s_clustersize_bits);
- cluster_align_head = !zero_len_head;
-
- zero_len_tail = osb->s_clustersize -
- do_div(s, osb->s_clustersize);
- if ((offset - i_size_read(inode)) < zero_len_tail)
- zero_len_tail = offset - i_size_read(inode);
- cluster_align_tail = !zero_len_tail;
- }
-
- /*
- * when final_size > inode->i_size, inode->i_size will be
- * updated after direct write, so add the inode to orphan
- * dir first.
- */
- if (final_size > i_size_read(inode)) {
- ret = ocfs2_add_inode_to_orphan(osb, inode);
- if (ret < 0) {
- mlog_errno(ret);
- goto out;
- }
- orphaned = true;
- }
-
- if (append_write) {
- ret = ocfs2_inode_lock(inode, NULL, 1);
- if (ret < 0) {
- mlog_errno(ret);
- goto clean_orphan;
- }
-
- /* zeroing out the previously allocated cluster tail
- * that but not zeroed */
- if (ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb))) {
- down_read(&OCFS2_I(inode)->ip_alloc_sem);
- ret = ocfs2_direct_IO_zero_extend(osb, inode, offset,
- zero_len_tail, cluster_align_tail);
- up_read(&OCFS2_I(inode)->ip_alloc_sem);
- } else {
- down_write(&OCFS2_I(inode)->ip_alloc_sem);
- ret = ocfs2_direct_IO_extend_no_holes(osb, inode,
- offset);
- up_write(&OCFS2_I(inode)->ip_alloc_sem);
- }
- if (ret < 0) {
- mlog_errno(ret);
- ocfs2_inode_unlock(inode, 1);
- goto clean_orphan;
- }
-
- is_overwrite = ocfs2_is_overwrite(osb, inode, offset);
- if (is_overwrite < 0) {
- mlog_errno(is_overwrite);
- ret = is_overwrite;
- ocfs2_inode_unlock(inode, 1);
- goto clean_orphan;
- }
-
- ocfs2_inode_unlock(inode, 1);
- }
-
- written = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
- offset, ocfs2_direct_IO_get_blocks,
- ocfs2_dio_end_io, NULL, 0);
- /* overwrite aio may return -EIOCBQUEUED, and it is not an error */
- if ((written < 0) && (written != -EIOCBQUEUED)) {
- loff_t i_size = i_size_read(inode);
-
- if (offset + count > i_size) {
- ret = ocfs2_inode_lock(inode, &di_bh, 1);
- if (ret < 0) {
- mlog_errno(ret);
- goto clean_orphan;
- }
-
- if (i_size == i_size_read(inode)) {
- ret = ocfs2_truncate_file(inode, di_bh,
- i_size);
- if (ret < 0) {
- if (ret != -ENOSPC)
- mlog_errno(ret);
-
- ocfs2_inode_unlock(inode, 1);
- brelse(di_bh);
- di_bh = NULL;
- goto clean_orphan;
- }
- }
-
- ocfs2_inode_unlock(inode, 1);
- brelse(di_bh);
- di_bh = NULL;
-
- ret = jbd2_journal_force_commit(journal);
- if (ret < 0)
- mlog_errno(ret);
- }
- } else if (written > 0 && append_write && !is_overwrite &&
- !cluster_align_head) {
- /* zeroing out the allocated cluster head */
- u32 p_cpos = 0;
- u32 v_cpos = ocfs2_bytes_to_clusters(osb->sb, offset);
-
- ret = ocfs2_inode_lock(inode, NULL, 0);
- if (ret < 0) {
- mlog_errno(ret);
- goto clean_orphan;
- }
-
- ret = ocfs2_get_clusters(inode, v_cpos, &p_cpos,
- &num_clusters, &ext_flags);
- if (ret < 0) {
- mlog_errno(ret);
- ocfs2_inode_unlock(inode, 0);
- goto clean_orphan;
- }
-
- BUG_ON(!p_cpos || (ext_flags & OCFS2_EXT_UNWRITTEN));
-
- ret = blkdev_issue_zeroout(osb->sb->s_bdev,
- (u64)p_cpos << (osb->s_clustersize_bits - 9),
- zero_len_head >> 9, GFP_NOFS, false);
- if (ret < 0)
- mlog_errno(ret);
-
- ocfs2_inode_unlock(inode, 0);
- }
-
-clean_orphan:
- if (orphaned) {
- int tmp_ret;
- int update_isize = written > 0 ? 1 : 0;
- loff_t end = update_isize ? offset + written : 0;
-
- tmp_ret = ocfs2_inode_lock(inode, &di_bh, 1);
- if (tmp_ret < 0) {
- ret = tmp_ret;
- mlog_errno(ret);
- goto out;
- }
-
- tmp_ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh,
- update_isize, end);
- if (tmp_ret < 0) {
- ocfs2_inode_unlock(inode, 1);
- ret = tmp_ret;
- mlog_errno(ret);
- brelse(di_bh);
- goto out;
- }
-
- ocfs2_inode_unlock(inode, 1);
- brelse(di_bh);
-
- tmp_ret = jbd2_journal_force_commit(journal);
- if (tmp_ret < 0) {
- ret = tmp_ret;
- mlog_errno(tmp_ret);
- }
- }
-
-out:
- if (ret >= 0)
- ret = written;
- return ret;
-}
-
-static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
- loff_t offset)
-{
- struct file *file = iocb->ki_filp;
- struct inode *inode = file_inode(file)->i_mapping->host;
- struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
- int full_coherency = !(osb->s_mount_opt &
- OCFS2_MOUNT_COHERENCY_BUFFERED);
-
- /*
- * Fallback to buffered I/O if we see an inode without
- * extents.
- */
- if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
- return 0;
-
- /* Fallback to buffered I/O if we are appending and
- * concurrent O_DIRECT writes are allowed.
- */
- if (i_size_read(inode) <= offset && !full_coherency)
- return 0;
-
- if (iov_iter_rw(iter) == READ)
- return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
- iter, offset,
- ocfs2_direct_IO_get_blocks,
- ocfs2_dio_end_io, NULL, 0);
- else
- return ocfs2_direct_IO_write(iocb, iter, offset);
-}
-
static void ocfs2_figure_cluster_boundaries(struct ocfs2_super *osb,
u32 cpos,
unsigned int *start,
@@ -1326,14 +817,14 @@ static void ocfs2_free_unwritten_list(struct inode *inode,
struct list_head *head)
{
struct ocfs2_inode_info *oi = OCFS2_I(inode);
- struct ocfs2_unwritten_extent *dz = NULL, *tmp = NULL;
+ struct ocfs2_unwritten_extent *ue = NULL, *tmp = NULL;
- list_for_each_entry_safe(dz, tmp, head, ue_node) {
- list_del(&dz->ue_node);
+ list_for_each_entry_safe(ue, tmp, head, ue_node) {
+ list_del(&ue->ue_node);
spin_lock(&oi->ip_lock);
- list_del(&dz->ue_ip_node);
+ list_del(&ue->ue_ip_node);
spin_unlock(&oi->ip_lock);
- kfree(dz);
+ kfree(ue);
}
}
@@ -1834,7 +1325,7 @@ static int ocfs2_unwritten_check(struct inode *inode,
struct ocfs2_write_cluster_desc *desc)
{
struct ocfs2_inode_info *oi = OCFS2_I(inode);
- struct ocfs2_unwritten_extent *dz = NULL, *new = NULL;
+ struct ocfs2_unwritten_extent *ue = NULL, *new = NULL;
int ret = 0;
if (!desc->c_needs_zero)
@@ -1845,8 +1336,8 @@ static int ocfs2_unwritten_check(struct inode *inode,
/* Needs not to zero no metter buffer or direct. The one who is zero
* the cluster is doing zero. And he will clear unwritten after all
* cluster io finished. */
- list_for_each_entry(dz, &oi->ip_unwritten_list, ue_ip_node) {
- if (desc->c_cpos == dz->ue_cpos) {
+ list_for_each_entry(ue, &oi->ip_unwritten_list, ue_ip_node) {
+ if (desc->c_cpos == ue->ue_cpos) {
BUG_ON(desc->c_new);
desc->c_needs_zero = 0;
desc->c_clear_unwritten = 0;
@@ -2608,6 +2099,344 @@ static int ocfs2_write_end(struct file *file, struct address_space *mapping,
return ret;
}
+struct ocfs2_dio_write_ctxt {
+ struct list_head dw_zero_list;
+ unsigned dw_zero_count;
+ int dw_orphaned;
+ pid_t dw_writer_pid;
+};
+
+static struct ocfs2_dio_write_ctxt *
+ocfs2_dio_alloc_write_ctx(struct buffer_head *bh, int *alloc)
+{
+ struct ocfs2_dio_write_ctxt *dwc = NULL;
+
+ if (bh->b_private)
+ return bh->b_private;
+
+ dwc = kmalloc(sizeof(struct ocfs2_dio_write_ctxt), GFP_NOFS);
+ if (dwc == NULL)
+ return NULL;
+ INIT_LIST_HEAD(&dwc->dw_zero_list);
+ dwc->dw_zero_count = 0;
+ dwc->dw_orphaned = 0;
+ dwc->dw_writer_pid = task_pid_nr(current);
+ bh->b_private = dwc;
+ *alloc = 1;
+
+ return dwc;
+}
+
+static void ocfs2_dio_free_write_ctx(struct inode *inode,
+ struct ocfs2_dio_write_ctxt *dwc)
+{
+ ocfs2_free_unwritten_list(inode, &dwc->dw_zero_list);
+ kfree(dwc);
+}
+
+/*
+ * TODO: Make this into a generic get_blocks function.
+ *
+ * From do_direct_io in direct-io.c:
+ * "So what we do is to permit the ->get_blocks function to populate
+ * bh.b_size with the size of IO which is permitted at this offset and
+ * this i_blkbits."
+ *
+ * This function is called directly from get_more_blocks in direct-io.c.
+ *
+ * called like this: dio->get_blocks(dio->inode, fs_startblk,
+ * fs_count, map_bh, dio->rw == WRITE);
+ */
+static int ocfs2_dio_get_block(struct inode *inode, sector_t iblock,
+ struct buffer_head *bh_result, int create)
+{
+ struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+ struct ocfs2_write_ctxt *wc;
+ struct ocfs2_write_cluster_desc *desc = NULL;
+ struct ocfs2_dio_write_ctxt *dwc = NULL;
+ struct buffer_head *di_bh = NULL;
+ u64 p_blkno;
+ loff_t pos = iblock << inode->i_sb->s_blocksize_bits;
+ unsigned len, total_len = bh_result->b_size;
+ int ret = 0, first_get_block = 0;
+
+ len = osb->s_clustersize - (pos & (osb->s_clustersize - 1));
+ len = min(total_len, len);
+
+ mlog(0, "get block of %lu at %llu:%u req %u\n",
+ inode->i_ino, pos, len, total_len);
+
+ /* This is the fast path for re-write. */
+ ret = ocfs2_get_block(inode, iblock, bh_result, create);
+
+ if (buffer_mapped(bh_result) &&
+ !buffer_new(bh_result) &&
+ ret == 0)
+ goto out;
+
+ /* Clear state set by ocfs2_get_block. */
+ bh_result->b_state = 0;
+
+ dwc = ocfs2_dio_alloc_write_ctx(bh_result, &first_get_block);
+ if (unlikely(dwc == NULL)) {
+ ret = -ENOMEM;
+ mlog_errno(ret);
+ goto out;
+ }
+
+ if (ocfs2_clusters_for_bytes(inode->i_sb, pos + total_len) >
+ ocfs2_clusters_for_bytes(inode->i_sb, i_size_read(inode)) &&
+ !dwc->dw_orphaned) {
+ /*
+ * when we are going to alloc extents beyond file size, add the
+ * inode to orphan dir, so we can recall those spaces when
+ * system crashed during write.
+ */
+ ret = ocfs2_add_inode_to_orphan(osb, inode);
+ if (ret < 0) {
+ mlog_errno(ret);
+ goto out;
+ }
+ dwc->dw_orphaned = 1;
+ }
+
+ ret = ocfs2_inode_lock(inode, &di_bh, 1);
+ if (ret) {
+ mlog_errno(ret);
+ goto out;
+ }
+
+ if (first_get_block) {
+ if (ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb)))
+ ret = ocfs2_zero_tail(inode, di_bh, pos);
+ else
+ ret = ocfs2_expand_nonsparse_inode(inode, di_bh, pos,
+ total_len, NULL);
+ if (ret < 0) {
+ mlog_errno(ret);
+ goto unlock;
+ }
+ }
+
+ ret = ocfs2_write_begin_nolock(inode->i_mapping, pos, len,
+ OCFS2_WRITE_DIRECT, NULL,
+ (void **)&wc, di_bh, NULL);
+ if (ret) {
+ mlog_errno(ret);
+ goto unlock;
+ }
+
+ desc = &wc->w_desc[0];
+
+ p_blkno = ocfs2_clusters_to_blocks(inode->i_sb, desc->c_phys);
+ BUG_ON(p_blkno == 0);
+ p_blkno += iblock & (u64)(ocfs2_clusters_to_blocks(inode->i_sb, 1) - 1);
+
+ map_bh(bh_result, inode->i_sb, p_blkno);
+ bh_result->b_size = len;
+ if (desc->c_needs_zero)
+ set_buffer_new(bh_result);
+
+ /* May sleep in end_io. It should not happen in a irq context. So defer
+ * it to dio work queue. */
+ set_buffer_defer_completion(bh_result);
+
+ if (!list_empty(&wc->w_unwritten_list)) {
+ struct ocfs2_unwritten_extent *ue = NULL;
+
+ ue = list_first_entry(&wc->w_unwritten_list,
+ struct ocfs2_unwritten_extent,
+ ue_node);
+ BUG_ON(ue->ue_cpos != desc->c_cpos);
+ /* The physical address may be 0, fill it. */
+ ue->ue_phys = desc->c_phys;
+
+ list_splice_tail_init(&wc->w_unwritten_list, &dwc->dw_zero_list);
+ dwc->dw_zero_count++;
+ }
+
+ ret = ocfs2_write_end_nolock(inode->i_mapping, pos, len, len, NULL, wc);
+ BUG_ON(ret != len);
+ ret = 0;
+unlock:
+ ocfs2_inode_unlock(inode, 1);
+ brelse(di_bh);
+out:
+ if (ret < 0)
+ ret = -EIO;
+ return ret;
+}
+
+static void ocfs2_dio_end_io_write(struct inode *inode,
+ struct ocfs2_dio_write_ctxt *dwc,
+ loff_t offset,
+ ssize_t bytes)
+{
+ struct ocfs2_cached_dealloc_ctxt dealloc;
+ struct ocfs2_extent_tree et;
+ struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+ struct ocfs2_unwritten_extent *ue = NULL;
+ struct buffer_head *di_bh = NULL;
+ struct ocfs2_dinode *di;
+ struct ocfs2_alloc_context *data_ac = NULL;
+ struct ocfs2_alloc_context *meta_ac = NULL;
+ handle_t *handle = NULL;
+ loff_t end = offset + bytes;
+ int ret = 0, credits = 0, locked = 0;
+
+ ocfs2_init_dealloc_ctxt(&dealloc);
+
+ /* We do clear unwritten, delete orphan, change i_size here. If neither
+ * of these happen, we can skip all this. */
+ if (list_empty(&dwc->dw_zero_list) &&
+ end <= i_size_read(inode) &&
+ !dwc->dw_orphaned)
+ goto out;
+
+ ret = ocfs2_inode_lock(inode, &di_bh, 1);
+ if (ret < 0) {
+ mlog_errno(ret);
+ goto out;
+ }
+
+ /* ocfs2_file_write_iter will get i_mutex, so we need not lock if we
+ * are in that context. */
+ if (dwc->dw_writer_pid != task_pid_nr(current)) {
+ mutex_lock(&inode->i_mutex);
+ locked = 1;
+ }
+
+ /* Delete orphan before acquire i_mutex. */
+ if (dwc->dw_orphaned) {
+ BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
+
+ end = end > i_size_read(inode) ? end : 0;
+
+ ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh,
+ !!end, end);
+ if (ret < 0)
+ mlog_errno(ret);
+ }
+
+ di = (struct ocfs2_dinode *)di_bh;
+
+ ocfs2_init_dinode_extent_tree(&et, INODE_CACHE(inode), di_bh);
+
+ ret = ocfs2_lock_allocators(inode, &et, 0, dwc->dw_zero_count*2,
+ &data_ac, &meta_ac);
+
+ credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
+
+ handle = ocfs2_start_trans(osb, credits);
+ if (IS_ERR(handle)) {
+ ret = PTR_ERR(handle);
+ mlog_errno(ret);
+ goto unlock;
+ }
+ ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
+ OCFS2_JOURNAL_ACCESS_WRITE);
+ if (ret) {
+ mlog_errno(ret);
+ goto commit;
+ }
+
+ list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) {
+ ret = ocfs2_mark_extent_written(inode, &et, handle,
+ ue->ue_cpos, 1,
+ ue->ue_phys,
+ meta_ac, &dealloc);
+ if (ret < 0) {
+ mlog_errno(ret);
+ break;
+ }
+ }
+
+ if (end > i_size_read(inode)) {
+ ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
+ if (ret < 0)
+ mlog_errno(ret);
+ }
+commit:
+ ocfs2_commit_trans(osb, handle);
+unlock:
+ ocfs2_inode_unlock(inode, 1);
+ brelse(di_bh);
+out:
+ ocfs2_run_deallocs(osb, &dealloc);
+ if (locked)
+ mutex_unlock(&inode->i_mutex);
+ ocfs2_dio_free_write_ctx(inode, dwc);
+ if (data_ac)
+ ocfs2_free_alloc_context(data_ac);
+ if (meta_ac)
+ ocfs2_free_alloc_context(meta_ac);
+}
+
+/*
+ * ocfs2_dio_end_io is called by the dio core when a dio is finished. We're
+ * particularly interested in the aio/dio case. We use the rw_lock DLM lock
+ * to protect io on one node from truncation on another.
+ */
+static int ocfs2_dio_end_io(struct kiocb *iocb,
+ loff_t offset,
+ ssize_t bytes,
+ void *private)
+{
+ struct inode *inode = file_inode(iocb->ki_filp);
+ int level;
+
+ if (bytes <= 0)
+ return 0;
+
+ /* this io's submitter should not have unlocked this before we could */
+ BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
+
+ if (ocfs2_iocb_is_unaligned_aio(iocb)) {
+ ocfs2_iocb_clear_unaligned_aio(iocb);
+
+ mutex_unlock(&OCFS2_I(inode)->ip_unaligned_aio);
+ }
+
+ if (private)
+ ocfs2_dio_end_io_write(inode, private, offset, bytes);
+
+ ocfs2_iocb_clear_rw_locked(iocb);
+
+ level = ocfs2_iocb_rw_locked_level(iocb);
+ ocfs2_rw_unlock(inode, level);
+ return 0;
+}
+
+static ssize_t ocfs2_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
+ loff_t offset)
+{
+ struct file *file = iocb->ki_filp;
+ struct inode *inode = file_inode(file)->i_mapping->host;
+ struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+ loff_t end = offset + iter->count;
+ get_block_t *get_block;
+
+ /*
+ * Fallback to buffered I/O if we see an inode without
+ * extents.
+ */
+ if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL)
+ return 0;
+
+ /* Fallback to buffered I/O if we do not support append dio. */
+ if (end > i_size_read(inode) && !ocfs2_supports_append_dio(osb))
+ return 0;
+
+ if (iov_iter_rw(iter) == READ)
+ get_block = ocfs2_get_block;
+ else
+ get_block = ocfs2_dio_get_block;
+
+ return __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
+ iter, offset, get_block,
+ ocfs2_dio_end_io, NULL, 0);
+}
+
const struct address_space_operations ocfs2_aops = {
.readpage = ocfs2_readpage,
.readpages = ocfs2_readpages,
]
|
| 120/2 |
2026/05/29 17:29 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 23673
output: 44
thoughts: 446
Thoughts: **Analyzing Orphaned Inode Deletion in OCFS2**
Okay, let's dive into this code. I'm looking at `c15471f79506830f80eca0e7fe09b8213953ab5f` and specifically how `ocfs2_dio_end_io_write` handles orphaned inodes. My initial thought was to see if `ocfs2_del_inode_from_orphan` was called while holding the `meta_ac` and `data_ac` locks. It's a critical point to understand the locking order here to avoid potential race conditions.
Reading the code snippet, it's pretty clear: the orphan deletion logic, including the call to `ocfs2_del_inode_from_orphan`, happens *before* the call to `ocfs2_lock_allocators`. That means the `meta_ac` and `data_ac` allocation context locks are *not* held during the orphan deletion. Thatβs a significant point. It's not what I initially expected. I need to be certain about this.
Now, my next step is to trace back when this ordering of operations was established. I need to understand if the order was intentional from the start or if there was a commit that changed the order of those operations and the associated implications. I need to investigate further to understand the rationale behind this design.
|
| 121/2 |
2026/05/29 17:29 |
tool |
git-log |
0m
Args: map[CodeRegexp:ocfs2_del_inode_from_orphan PathPrefix:fs/ocfs2/aops.c]
Results: map[Output:d647c5b2fbf8 ocfs2: split transactions in dio completion to avoid credit exhaustion
c15471f79506 ocfs2: fix sparse file & data ordering issue in direct io
cf1776a9e834 ocfs2: fix a tiny race when truncate dio orohaned entry
24c40b329e03 ocfs2: implement ocfs2_direct_IO_write
]
|
| 122/2 |
2026/05/29 17:29 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 24590
output: 26
thoughts: 17
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:
**Investigating a Hash β Initial Probe**
Alright, I've been given `d647c5b2fbf8`. Immediately, my mental gears start turning. This looks like a cryptographic hash, likely a SHA-1 or MD5 based on its length, though a more modern hashing algorithm like SHA-256 is certainly possible. The first question I'm asking myself is *why* am I looking at this? What's the context? Is this from an investigation, a security audit, or maybe just a data integrity check? Knowing the source is critical for determining the appropriate investigative path.
Next, I need to understand the likely function of this hash. Was it produced from a file, a string, a database record, or something else entirely? The context will provide crucial clues here. Are there any known vulnerabilities associated with the hashing algorithm itself that might make it immediately suspicious, like collision attacks? Does the context suggest I should be looking at rainbow tables or pre-computed hash databases?
I'm mentally preparing for a few different approaches. I'll need to use tools to quickly identify the hash type, assuming it's straightforward. Then, I may need to attempt to reverse the hash or find the original input, depending on the goal. Are we trying to identify the file itself, the key that produced it, or are we just looking to verify its integrity? My goal will inform if I go looking for known-hash databases or consider more sophisticated techniques like brute-forcing, if the context permits. Finally, I'll need to correlate this hash to any available logs, metadata, or other related artifacts to find more data. I'm ready to dig in and find some answers.
|
| 123/2 |
2026/05/29 17:29 |
tool |
git-show |
0m
Args:
Results: map[Output:commit d647c5b2fbf81560818dacade360abc8c00a9665
Author: Heming Zhao <heming.zhao@suse.com>
Date: Thu Apr 2 21:43:27 2026 +0800
ocfs2: split transactions in dio completion to avoid credit exhaustion
During ocfs2 dio operations, JBD2 may report warnings via following
call trace:
ocfs2_dio_end_io_write
ocfs2_mark_extent_written
ocfs2_change_extent_flag
ocfs2_split_extent
ocfs2_try_to_merge_extent
ocfs2_extend_rotate_transaction
ocfs2_extend_trans
jbd2__journal_restart
start_this_handle
output: JBD2: kworker/6:2 wants too many credits credits:5450 rsv_credits:0 max:5449
To prevent exceeding the credits limit, modify ocfs2_dio_end_io_write() to
handle extents in a batch of transaction.
Additionally, relocate ocfs2_del_inode_from_orphan(). The orphan inode
should only be removed from the orphan list after the extent tree update
is complete. This ensures that if a crash occurs in the middle of extent
tree updates, we won't leave stale blocks beyond EOF.
This patch also changes the logic for updating the inode size and removing
orphan, making it similar to ext4_dio_write_end_io(). Both operations are
performed only when everything looks good.
Finally, thanks to Jans and Joseph for providing the bug fix prototype and
suggestions.
Link: https://lkml.kernel.org/r/20260402134328.27334-2-heming.zhao@suse.com
Signed-off-by: Heming Zhao <heming.zhao@suse.com>
Suggested-by: Jan Kara <jack@suse.cz>
Suggested-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 09146b43d1f0..c6dbec1693b1 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -37,6 +37,8 @@
#include "namei.h"
#include "sysfile.h"
+#define OCFS2_DIO_MARK_EXTENT_BATCH 200
+
static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create)
{
@@ -2277,7 +2279,7 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
struct ocfs2_alloc_context *meta_ac = NULL;
handle_t *handle = NULL;
loff_t end = offset + bytes;
- int ret = 0, credits = 0;
+ int ret = 0, credits = 0, batch = 0;
ocfs2_init_dealloc_ctxt(&dealloc);
@@ -2294,18 +2296,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
goto out;
}
- /* Delete orphan before acquire i_rwsem. */
- if (dwc->dw_orphaned) {
- BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
-
- end = end > i_size_read(inode) ? end : 0;
-
- ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh,
- !!end, end);
- if (ret < 0)
- mlog_errno(ret);
- }
-
down_write(&oi->ip_alloc_sem);
di = (struct ocfs2_dinode *)di_bh->b_data;
@@ -2326,24 +2316,25 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
- handle = ocfs2_start_trans(osb, credits);
- if (IS_ERR(handle)) {
- ret = PTR_ERR(handle);
- mlog_errno(ret);
- goto unlock;
- }
- ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
- OCFS2_JOURNAL_ACCESS_WRITE);
- if (ret) {
- mlog_errno(ret);
- goto commit;
- }
-
list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) {
+ if (!handle) {
+ handle = ocfs2_start_trans(osb, credits);
+ if (IS_ERR(handle)) {
+ ret = PTR_ERR(handle);
+ mlog_errno(ret);
+ goto unlock;
+ }
+ ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
+ OCFS2_JOURNAL_ACCESS_WRITE);
+ if (ret) {
+ mlog_errno(ret);
+ goto commit;
+ }
+ }
ret = ocfs2_assure_trans_credits(handle, credits);
if (ret < 0) {
mlog_errno(ret);
- break;
+ goto commit;
}
ret = ocfs2_mark_extent_written(inode, &et, handle,
ue->ue_cpos, 1,
@@ -2351,19 +2342,44 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
meta_ac, &dealloc);
if (ret < 0) {
mlog_errno(ret);
- break;
+ goto commit;
+ }
+
+ if (++batch == OCFS2_DIO_MARK_EXTENT_BATCH) {
+ ocfs2_commit_trans(osb, handle);
+ handle = NULL;
+ batch = 0;
}
}
if (end > i_size_read(inode)) {
+ if (!handle) {
+ handle = ocfs2_start_trans(osb, credits);
+ if (IS_ERR(handle)) {
+ ret = PTR_ERR(handle);
+ mlog_errno(ret);
+ goto unlock;
+ }
+ }
ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
if (ret < 0)
mlog_errno(ret);
}
+
commit:
- ocfs2_commit_trans(osb, handle);
+ if (handle)
+ ocfs2_commit_trans(osb, handle);
unlock:
up_write(&oi->ip_alloc_sem);
+
+ /* everything looks good, let's start the cleanup */
+ if (!ret && dwc->dw_orphaned) {
+ BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
+
+ ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
+ if (ret < 0)
+ mlog_errno(ret);
+ }
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
]
|
| 124/2 |
2026/05/29 17:29 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 27209
output: 48
thoughts: 1517
Thoughts: **Analyzing a Circular Locking Dependency in OCFS2**
Okay, let's break this down. In commit `d647c5b2fbf81560818dacade360abc8c00a9665`, the developer moved the call to `ocfs2_del_inode_from_orphan` to the end of `ocfs2_dio_end_io_write`. My immediate thought was to understand the implications of this change. Peering into the diff, I noticed that `ocfs2_del_inode_from_orphan` now occurs *before* `out:`, the label where `data_ac` and `meta_ac` are freed.
This triggers alarm bells. Those allocation contexts (`data_ac` and `meta_ac`) hold the `EXTENT_ALLOC_SYSTEM_INODE` lock. At the same time, `ocfs2_del_inode_from_orphan` acquires the `ORPHAN_DIR_SYSTEM_INODE` lock. Thus, the change introduces a locking dependency: `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`.
To verify this, I went back and confirmed that before the commit, `ocfs2_del_inode_from_orphan` was called earlier, before the allocators were locked. The commit moved the call *after* the allocators were locked, but *before* they were unlocked. Therefore, that commit, `d647c5b2fbf81560818dacade360abc8c00a9665`, introduced the circular dependency.
I then examined the subsequent patch that fixed the issue. Bingo! It moved the freeing of `data_ac` and `meta_ac` *before* the call to `ocfs2_del_inode_from_orphan`, resolving the circular dependency that was introduced.
Finally, I revisited the original commit message for `d647c5b2fbf81560818dacade360abc8c00a9665`. The stated reason for the move was to ensure the orphan inode is only removed after extent tree updates. While the intent was sound, the implementation placed the cleanup at the wrong point, creating this unintended consequence. The commit's logic was correct in terms of ensuring data integrity, but it inadvertently introduced a circular locking dependency by putting the code in the wrong order. A classic case of functionality vs. concurrency! I will need to confirm the commit hash `d647c5b2fbf81560818dacade360abc8c00a9665` to be sure.
|
| 125/2 |
2026/05/29 17:29 |
tool |
git-show |
0m
Args: map[Commit:d647c5b2fbf81560818dacade360abc8c00a9665]
Results: map[Output:commit d647c5b2fbf81560818dacade360abc8c00a9665
Author: Heming Zhao <heming.zhao@suse.com>
Date: Thu Apr 2 21:43:27 2026 +0800
ocfs2: split transactions in dio completion to avoid credit exhaustion
During ocfs2 dio operations, JBD2 may report warnings via following
call trace:
ocfs2_dio_end_io_write
ocfs2_mark_extent_written
ocfs2_change_extent_flag
ocfs2_split_extent
ocfs2_try_to_merge_extent
ocfs2_extend_rotate_transaction
ocfs2_extend_trans
jbd2__journal_restart
start_this_handle
output: JBD2: kworker/6:2 wants too many credits credits:5450 rsv_credits:0 max:5449
To prevent exceeding the credits limit, modify ocfs2_dio_end_io_write() to
handle extents in a batch of transaction.
Additionally, relocate ocfs2_del_inode_from_orphan(). The orphan inode
should only be removed from the orphan list after the extent tree update
is complete. This ensures that if a crash occurs in the middle of extent
tree updates, we won't leave stale blocks beyond EOF.
This patch also changes the logic for updating the inode size and removing
orphan, making it similar to ext4_dio_write_end_io(). Both operations are
performed only when everything looks good.
Finally, thanks to Jans and Joseph for providing the bug fix prototype and
suggestions.
Link: https://lkml.kernel.org/r/20260402134328.27334-2-heming.zhao@suse.com
Signed-off-by: Heming Zhao <heming.zhao@suse.com>
Suggested-by: Jan Kara <jack@suse.cz>
Suggested-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 09146b43d1f0..c6dbec1693b1 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -37,6 +37,8 @@
#include "namei.h"
#include "sysfile.h"
+#define OCFS2_DIO_MARK_EXTENT_BATCH 200
+
static int ocfs2_symlink_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create)
{
@@ -2277,7 +2279,7 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
struct ocfs2_alloc_context *meta_ac = NULL;
handle_t *handle = NULL;
loff_t end = offset + bytes;
- int ret = 0, credits = 0;
+ int ret = 0, credits = 0, batch = 0;
ocfs2_init_dealloc_ctxt(&dealloc);
@@ -2294,18 +2296,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
goto out;
}
- /* Delete orphan before acquire i_rwsem. */
- if (dwc->dw_orphaned) {
- BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
-
- end = end > i_size_read(inode) ? end : 0;
-
- ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh,
- !!end, end);
- if (ret < 0)
- mlog_errno(ret);
- }
-
down_write(&oi->ip_alloc_sem);
di = (struct ocfs2_dinode *)di_bh->b_data;
@@ -2326,24 +2316,25 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
credits = ocfs2_calc_extend_credits(inode->i_sb, &di->id2.i_list);
- handle = ocfs2_start_trans(osb, credits);
- if (IS_ERR(handle)) {
- ret = PTR_ERR(handle);
- mlog_errno(ret);
- goto unlock;
- }
- ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
- OCFS2_JOURNAL_ACCESS_WRITE);
- if (ret) {
- mlog_errno(ret);
- goto commit;
- }
-
list_for_each_entry(ue, &dwc->dw_zero_list, ue_node) {
+ if (!handle) {
+ handle = ocfs2_start_trans(osb, credits);
+ if (IS_ERR(handle)) {
+ ret = PTR_ERR(handle);
+ mlog_errno(ret);
+ goto unlock;
+ }
+ ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
+ OCFS2_JOURNAL_ACCESS_WRITE);
+ if (ret) {
+ mlog_errno(ret);
+ goto commit;
+ }
+ }
ret = ocfs2_assure_trans_credits(handle, credits);
if (ret < 0) {
mlog_errno(ret);
- break;
+ goto commit;
}
ret = ocfs2_mark_extent_written(inode, &et, handle,
ue->ue_cpos, 1,
@@ -2351,19 +2342,44 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
meta_ac, &dealloc);
if (ret < 0) {
mlog_errno(ret);
- break;
+ goto commit;
+ }
+
+ if (++batch == OCFS2_DIO_MARK_EXTENT_BATCH) {
+ ocfs2_commit_trans(osb, handle);
+ handle = NULL;
+ batch = 0;
}
}
if (end > i_size_read(inode)) {
+ if (!handle) {
+ handle = ocfs2_start_trans(osb, credits);
+ if (IS_ERR(handle)) {
+ ret = PTR_ERR(handle);
+ mlog_errno(ret);
+ goto unlock;
+ }
+ }
ret = ocfs2_set_inode_size(handle, inode, di_bh, end);
if (ret < 0)
mlog_errno(ret);
}
+
commit:
- ocfs2_commit_trans(osb, handle);
+ if (handle)
+ ocfs2_commit_trans(osb, handle);
unlock:
up_write(&oi->ip_alloc_sem);
+
+ /* everything looks good, let's start the cleanup */
+ if (!ret && dwc->dw_orphaned) {
+ BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
+
+ ret = ocfs2_del_inode_from_orphan(osb, inode, di_bh, 0, 0);
+ if (ret < 0)
+ mlog_errno(ret);
+ }
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
]
|
| 126/2 |
2026/05/29 17:29 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 31559
output: 50
thoughts: 687
Thoughts: **Analyzing the Root Cause of a Circular Locking Dependency**
Okay, so I've been digging into this bug, and I'm pretty sure I've nailed down the culprit. Looking at the commit history, `d647c5b2fbf81560818dacade360abc8c00a9665` is the one that introduced the circular locking dependency. My reasoning is solid. This commit moved the call to `ocfs2_del_inode_from_orphan` to after `up_write(&oi->ip_alloc_sem);` but before the `out:` label, which is critical.
This placement means that the `data_ac` and `meta_ac` allocation contexts are still active when `ocfs2_del_inode_from_orphan` is called. Now, `ocfs2_del_inode_from_orphan` acquires the `ORPHAN_DIR_SYSTEM_INODE` lock. At the same time, `data_ac` and `meta_ac` hold the `EXTENT_ALLOC_SYSTEM_INODE` lock. Boom β circular dependency!
Let's quickly confirm that there aren't any other contributing factors. The bug report is helpful here, it shows a clear path of lock acquisition that matches what I'm seeing: `EXTENT_ALLOC_SYSTEM_INODE` is acquired before `ORPHAN_DIR_SYSTEM_INODE`. Specifically, the report calls out `ocfs2_dio_end_io_write()` where metadata blocks are allocated using `ocfs2_lock_allocators()`, which acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Then, if the inode is orphaned, `ocfs2_del_inode_from_orphan()` is called, acquiring the `ORPHAN_DIR_SYSTEM_INODE` lock. The report correctly points out that `meta_ac` and thus the `EXTENT_ALLOC_SYSTEM_INODE` lock is held until the very end, while the `ORPHAN_DIR_SYSTEM_INODE` is acquired. This confirms the exact scenario that `d647c5b2fbf81560818dacade360abc8c00a9665` created.
Before that commit, `ocfs2_del_inode_from_orphan` was called *before* `ocfs2_lock_allocators()`, so `meta_ac` was not held when the orphaned inode was handled.
Now, let's verify the fix. The fix commit is smart β it moves the `ocfs2_free_alloc_context(data_ac)` and `ocfs2_free_alloc_context(meta_ac)` calls right after `up_write(&oi->ip_alloc_sem);` and *before* the call to `ocfs2_del_inode_from_orphan()`. This is precisely what's needed to break the dependency, because the allocation contexts are freed before the function acquires the `ORPHAN_DIR_SYSTEM_INODE` lock.
Therefore, my conclusion stands: the bug-introducing commit is definitely `d647c5b2fbf81560818dacade360abc8c00a9665`. We can now move forward with confidence.
|
| 127/2 |
2026/05/29 17:30 |
tool |
set-results |
0m
Args: map[FixesHash:d647c5b2fbf81560818dacade360abc8c00a9665]
Results: map[FixesHash:d647c5b2fbf81560818dacade360abc8c00a9665]
|
| 128/1 |
2026/05/29 17:30 |
action |
format-fixes |
0m
Results: map[Fixes:map[Hash:d647c5b2fbf81560818dacade360abc8c00a9665 Title:ocfs2: split transactions in dio completion to avoid credit exhaustion]]
|
| 129/1 |
2026/05/29 17:30 |
action |
get-maintainers |
0m
Results: map[Recipients:[map[Email:jlbec@evilplan.org Name:Joel Becker To:true] map[Email:joseph.qi@linux.alibaba.com Name:Joseph Qi To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:mark@fasheh.com Name:Mark Fasheh To:true] map[Email:ocfs2-devel@lists.linux.dev Name: To:true]]]
|
| 130/1 |
2026/05/29 17:30 |
action |
get-recent-commits |
0m
Results: map[RecentCommits:ocfs2: split transactions in dio completion to avoid credit exhaustion
ocfs2: fix possible deadlock between unlink and dio_end_io_write
treewide: change inode->i_ino from unsigned long to u64
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
fs: change write_begin/write_end interface to take struct kiocb *
ocfs2: reset folio to NULL when get folio fails
ocfs2: use memcpy_to_folio() in ocfs2_symlink_get_block()
fs: convert block_commit_write() to take a folio
ocfs2: convert ocfs2_read_inline_data() to take a folio
ocfs2: use an array of folios instead of an array of pages
ocfs2: convert ocfs2_clear_page_regions() to ocfs2_clear_folio_regions()
ocfs2: convert ocfs2_map_page_blocks() to ocfs2_map_folio_blocks()
ocfs2: use a folio in ocfs2_prepare_page_for_write()
ocfs2: use a folio in ocfs2_write_end_nolock()
ocfs2: convert ocfs2_write_failure() to use a folio
ocfs2: convert w_pages to w_folios
ocfs2: convert ocfs2_inode_lock_with_page() to ocfs2_inode_lock_with_folio()
ocfs2: convert ocfs2_readpage_inline() to take a folio
ocfs2: pass mmap_folio around instead of mmap_page
ocfs2: use a folio in ocfs2_write_begin_inline()
]
|
| 131/1 |
2026/05/29 17:30 |
agent |
description-generator |
0m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with writing a commit description for
a kernel bug fixing commit. The description should start with a one-line summary,
and then include description of the bug being fixed, and how it's fixed by the provided patch.
The one-line summary should describe the change being made, rather than mention the tool that
detected the bug.
The description must not contain lines starting with '#' because they will dropped by git as comments.
The description must not contain lines starting with '--' or '---' (including inline code diffs)
because they may confuse git/patch utilities.
Your final reply should contain only the text of the commit description.
The one-line summary must be not longer than 72 characters.
IMPORTANT: Do not wrap lines manually (e.g., at 80 characters); we will reformat the text
automatically, so keep paragraphs as single lines without newlines.
Generally try to phrase the description without mentioning syzkaller
(avoid phrases like "the bug was triggered by syzkaller" or "the bug was triggered by fuzzer", etc).
How the bug was triggered is generally an irrelevant detail.
Any bug triggered by a fuzzer can also be triggered by a malicious user, or a buggy program.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #1 Not tainted
------------------------------------------------------
syz-executor/6069 is trying to acquire lock:
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196ab3a0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
but task is already holding lock:
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_del_inode_from_orphan+0x12e/0x7a0 fs/ocfs2/namei.c:2728
ocfs2_dio_end_io_write fs/ocfs2/aops.c:2379 [inline]
ocfs2_dio_end_io+0xf9c/0x1370 fs/ocfs2/aops.c:2418
dio_complete+0x25b/0x790 fs/direct-io.c:281
__blockdev_direct_IO+0x2e5d/0x34e0 fs/direct-io.c:1303
ocfs2_direct_IO+0x251/0x2c0 fs/ocfs2/aops.c:2455
generic_file_direct_write+0x1db/0x3e0 mm/filemap.c:4259
__generic_file_write_iter+0x11d/0x230 mm/filemap.c:4428
ocfs2_file_write_iter+0x1663/0x1e70 fs/ocfs2/file.c:2476
do_iter_readv_writev+0x619/0x8c0 fs/read_write.c:-1
vfs_writev+0x33c/0x990 fs/read_write.c:1059
do_writev+0x154/0x2e0 fs/read_write.c:1105
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_reserve_suballoc_bits+0x16d/0x4840 fs/ocfs2/suballoc.c:882
ocfs2_reserve_new_metadata_blocks+0x415/0x9a0 fs/ocfs2/suballoc.c:1078
ocfs2_mknod+0x10f3/0x2260 fs/ocfs2/namei.c:351
ocfs2_create+0x195/0x460 fs/ocfs2/namei.c:677
lookup_open fs/namei.c:4511 [inline]
open_last_lookups fs/namei.c:4611 [inline]
path_openat+0x1395/0x3860 fs/namei.c:4855
do_file_open+0x23e/0x4a0 fs/namei.c:4887
do_sys_openat2+0x113/0x200 fs/open.c:1364
do_sys_open fs/open.c:1370 [inline]
__do_sys_openat fs/open.c:1386 [inline]
__se_sys_openat fs/open.c:1381 [inline]
__x64_sys_openat+0x138/0x170 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #0 (&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]){+.+.}-{4:4}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE] --> &ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[EXTENT_ALLOC_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]);
lock(&ocfs2_sysfile_lock_key[INODE_ALLOC_SYSTEM_INODE]);
*** DEADLOCK ***
4 locks held by syz-executor/6069:
#0: ffff8881161a4410 (sb_writers#12){.+.+}-{0:0}, at: mnt_want_write+0x41/0x90 fs/namespace.c:493
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: inode_lock_nested include/linux/fs.h:1074 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: __start_dirop fs/namei.c:2914 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: start_dirop fs/namei.c:2938 [inline]
#1: ffff88811958a5a0 (&type->i_mutex_dir_key#8/1){+.+.}-{4:4}, at: filename_rmdir+0x1cd/0x520 fs/namei.c:5414
#2: ffff8881166b0bc0 (&osb->nfs_sync_rwlock){.+.+}-{4:4}, at: ocfs2_nfs_sync_lock+0x106/0x270 fs/ocfs2/dlmglue.c:2875
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: inode_lock include/linux/fs.h:1029 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_wipe_inode fs/ocfs2/inode.c:854 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
#3: ffff8881196acfa0 (&ocfs2_sysfile_lock_key[ORPHAN_DIR_SYSTEM_INODE]){+.+.}-{4:4}, at: ocfs2_evict_inode+0xe97/0x43b0 fs/ocfs2/inode.c:1299
stack backtrace:
CPU: 1 UID: 0 PID: 6069 Comm: syz-executor Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e1/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
down_write+0x96/0x200 kernel/locking/rwsem.c:1625
inode_lock include/linux/fs.h:1029 [inline]
ocfs2_remove_inode fs/ocfs2/inode.c:733 [inline]
ocfs2_wipe_inode fs/ocfs2/inode.c:896 [inline]
ocfs2_delete_inode fs/ocfs2/inode.c:1157 [inline]
ocfs2_evict_inode+0x1539/0x43b0 fs/ocfs2/inode.c:1299
evict+0x61e/0xb10 fs/inode.c:841
d_delete_notify include/linux/fsnotify.h:377 [inline]
vfs_rmdir+0x42a/0x6e0 fs/namei.c:5379
filename_rmdir+0x292/0x520 fs/namei.c:5421
__do_sys_unlinkat fs/namei.c:5596 [inline]
__se_sys_unlinkat+0x71/0x1a0 fs/namei.c:5589
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0x560 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f51b819bf77
Code: 77 01 c3 48 c7 c2 e8 ff ff ff f7 d8 64 89 02 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 b8 07 01 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd5ea06718 EFLAGS: 00000207 ORIG_RAX: 0000000000000107
RAX: ffffffffffffffda RBX: 0000000000000065 RCX: 00007f51b819bf77
RDX: 0000000000000200 RSI: 00007ffd5ea078c0 RDI: 00000000ffffff9c
RBP: 00007f51b82321ca R08: 0000000000018560 R09: 0000000000000001
R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffd5ea078c0
R13: 00007f51b82321ca R14: 000000000001819f R15: 00007ffd5ea09a80
</TASK>
The explanation of the root cause of the bug is:
The lockdep warning reports a circular locking dependency involving three OCFS2 system inode locks (which all belong to the `ocfs2_sysfile_lock_key` lock class, but are distinct locks based on their system inode type).
The three locks involved are:
1. `INODE_ALLOC_SYSTEM_INODE`
2. `EXTENT_ALLOC_SYSTEM_INODE`
3. `ORPHAN_DIR_SYSTEM_INODE`
### Root Cause Analysis
The circular dependency is formed by three separate code paths that establish the following lock ordering:
**1. `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE`**
In `ocfs2_mknod()` (`fs/ocfs2/namei.c`), the code first reserves an inode by calling `ocfs2_reserve_new_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock. Shortly after, it reserves metadata blocks by calling `ocfs2_reserve_new_metadata_blocks()`, which acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Both locks are held concurrently until the end of the function (or upon error), establishing this dependency.
**2. `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`**
In `ocfs2_dio_end_io_write()` (`fs/ocfs2/aops.c`), the code allocates metadata blocks for unwritten extents by calling `ocfs2_lock_allocators()`. This allocates `meta_ac` and acquires the `EXTENT_ALLOC_SYSTEM_INODE` lock. Later in the same function, if the inode was orphaned, it calls `ocfs2_del_inode_from_orphan()`, which acquires the `ORPHAN_DIR_SYSTEM_INODE` lock. The `meta_ac` context (and thus the `EXTENT_ALLOC_SYSTEM_INODE` lock) is only freed at the very end of the function, meaning it is held while `ORPHAN_DIR_SYSTEM_INODE` is acquired.
**3. `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`**
In `ocfs2_wipe_inode()` (`fs/ocfs2/inode.c`), the `ORPHAN_DIR_SYSTEM_INODE` lock is acquired first to prevent races with recovery completion. While holding this lock, it calls `ocfs2_remove_inode()`, which acquires the `INODE_ALLOC_SYSTEM_INODE` lock to free the inode. (A similar dependency is also established in `ocfs2_prep_new_orphaned_file()`).
Combining these three paths creates the circular dependency:
`INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE`.
### How to Fix
We can break the cycle by addressing the second dependency (`EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE`) in `ocfs2_dio_end_io_write()`.
The `data_ac` and `meta_ac` allocation contexts are only needed for the transaction that marks the extents as written. Once the transaction is committed via `ocfs2_commit_trans()` and the allocation semaphore is released via `up_write(&oi->ip_alloc_sem)`, these contexts are no longer needed. We can safely free them (which releases the `EXTENT_ALLOC_SYSTEM_INODE` lock) *before* calling `ocfs2_del_inode_from_orphan()`.
Here is the proposed fix for `fs/ocfs2/aops.c`:
```c
@@ -2372,6 +2372,16 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2393,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
```
This ensures that the `EXTENT_ALLOC_SYSTEM_INODE` lock is dropped before we attempt to acquire the `ORPHAN_DIR_SYSTEM_INODE` lock, successfully breaking the circular dependency.
The diff of the bug fix is:
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 6ec198bda..4acdbb708 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -2372,6 +2372,15 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
unlock:
up_write(&oi->ip_alloc_sem);
+ if (data_ac) {
+ ocfs2_free_alloc_context(data_ac);
+ data_ac = NULL;
+ }
+ if (meta_ac) {
+ ocfs2_free_alloc_context(meta_ac);
+ meta_ac = NULL;
+ }
+
/* everything looks good, let's start the cleanup */
if (!ret && dwc->dw_orphaned) {
BUG_ON(dwc->dw_writer_pid != task_pid_nr(current));
@@ -2383,10 +2392,6 @@ static int ocfs2_dio_end_io_write(struct inode *inode,
ocfs2_inode_unlock(inode, 1);
brelse(di_bh);
out:
- if (data_ac)
- ocfs2_free_alloc_context(data_ac);
- if (meta_ac)
- ocfs2_free_alloc_context(meta_ac);
ocfs2_run_deallocs(osb, &dealloc);
ocfs2_dio_free_write_ctx(inode, dwc);
Additional description of the patch:
I have applied the fix to break the circular locking dependency by modifying `ocfs2_dio_end_io_write()` in `fs/ocfs2/aops.c`.
### What I did:
I moved the freeing of the `data_ac` and `meta_ac` allocation contexts to happen immediately after the transaction is committed and the allocation semaphore is released (`up_write(&oi->ip_alloc_sem)`), but *before* the call to `ocfs2_del_inode_from_orphan()`.
### Why this is the best fix:
The circular dependency is formed by the following lock ordering:
1. `INODE_ALLOC_SYSTEM_INODE` -> `EXTENT_ALLOC_SYSTEM_INODE` (in `ocfs2_mknod()`)
2. `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` (in `ocfs2_dio_end_io_write()`)
3. `ORPHAN_DIR_SYSTEM_INODE` -> `INODE_ALLOC_SYSTEM_INODE` (in `ocfs2_wipe_inode()`)
By freeing `data_ac` and `meta_ac` earlier in `ocfs2_dio_end_io_write()`, we release the `EXTENT_ALLOC_SYSTEM_INODE` lock before attempting to acquire the `ORPHAN_DIR_SYSTEM_INODE` lock (which happens inside `ocfs2_del_inode_from_orphan()`). This effectively breaks the `EXTENT_ALLOC_SYSTEM_INODE` -> `ORPHAN_DIR_SYSTEM_INODE` dependency, resolving the circular locking issue.
The allocation contexts (`data_ac` and `meta_ac`) are only needed for the transaction that marks the extents as written. Once the transaction is committed and the allocation semaphore is released, they are no longer required. Freeing them early is completely safe and does not affect the subsequent orphan cleanup or deallocation steps.
I also verified other occurrences of `ocfs2_del_inode_from_orphan()` (such as in `ocfs2_recover_orphans()` and `ocfs2_add_inode_to_orphan()`) and confirmed that they do not hold the `EXTENT_ALLOC_SYSTEM_INODE` lock. Similarly, I checked other callers of `ocfs2_lock_allocators()` and confirmed they do not acquire the `ORPHAN_DIR_SYSTEM_INODE` lock while holding the allocation contexts. Therefore, this fix is localized and sufficient to resolve the root cause without introducing new issues.
Here are summaries of recent commits that touched the same files.
Format the summary line consistently with these, look how prefixes
are specified, letter capitalization, style, etc.
ocfs2: split transactions in dio completion to avoid credit exhaustion
ocfs2: fix possible deadlock between unlink and dio_end_io_write
treewide: change inode->i_ino from unsigned long to u64
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
fs: change write_begin/write_end interface to take struct kiocb *
ocfs2: reset folio to NULL when get folio fails
ocfs2: use memcpy_to_folio() in ocfs2_symlink_get_block()
fs: convert block_commit_write() to take a folio
ocfs2: convert ocfs2_read_inline_data() to take a folio
ocfs2: use an array of folios instead of an array of pages
ocfs2: convert ocfs2_clear_page_regions() to ocfs2_clear_folio_regions()
ocfs2: convert ocfs2_map_page_blocks() to ocfs2_map_folio_blocks()
ocfs2: use a folio in ocfs2_prepare_page_for_write()
ocfs2: use a folio in ocfs2_write_end_nolock()
ocfs2: convert ocfs2_write_failure() to use a folio
ocfs2: convert w_pages to w_folios
ocfs2: convert ocfs2_inode_lock_with_page() to ocfs2_inode_lock_with_folio()
ocfs2: convert ocfs2_readpage_inline() to take a folio
ocfs2: pass mmap_folio around instead of mmap_page
ocfs2: use a folio in ocfs2_write_begin_inline()
Reply: ocfs2: fix circular locking dependency in ocfs2_dio_end_io_write()
A circular locking dependency can occur involving three OCFS2 system inode
locks: INODE_ALLOC_SYSTEM_INODE, EXTENT_ALLOC_SYSTEM_INODE, and
ORPHAN_DIR_SYSTEM_INODE.
The circular dependency is formed by three separate code paths. First, in
ocfs2_mknod(), the code reserves an inode by acquiring the
INODE_ALLOC_SYSTEM_INODE lock, and then reserves metadata blocks by
acquiring the EXTENT_ALLOC_SYSTEM_INODE lock. Second, in
ocfs2_dio_end_io_write(), the code allocates metadata blocks for unwritten
extents, acquiring the EXTENT_ALLOC_SYSTEM_INODE lock. Later in the same
function, if the inode was orphaned, it calls
ocfs2_del_inode_from_orphan(), which acquires the ORPHAN_DIR_SYSTEM_INODE
lock. The allocation context is only freed at the end of the function,
meaning the EXTENT_ALLOC_SYSTEM_INODE lock is held while
ORPHAN_DIR_SYSTEM_INODE is acquired. Third, in ocfs2_wipe_inode(), the
ORPHAN_DIR_SYSTEM_INODE lock is acquired first to prevent races with
recovery completion, and then it calls ocfs2_remove_inode(), which acquires
the INODE_ALLOC_SYSTEM_INODE lock to free the inode.
This patch breaks the cycle by addressing the dependency in
ocfs2_dio_end_io_write(). The data_ac and meta_ac allocation contexts are
only needed for the transaction that marks the extents as written. Once the
transaction is committed and the allocation semaphore is released, these
contexts are no longer needed. We can safely free them, which releases the
EXTENT_ALLOC_SYSTEM_INODE lock, before calling
ocfs2_del_inode_from_orphan(). This ensures that the
EXTENT_ALLOC_SYSTEM_INODE lock is dropped before we attempt to acquire the
ORPHAN_DIR_SYSTEM_INODE lock, successfully breaking the circular
dependency.
|
| 132/2 |
2026/05/29 17:30 |
llm |
description-generator |
0m
Model:
Tokens:
input: 10953
output: 455
thoughts: 1592
Thoughts: **OCFS2 Circular Locking Dependency Fix**
Okay, here's the breakdown. I need to document a fix for a circular locking dependency in the OCFS2 code. My initial thought is to make the one-line summary something like "ocfs2: fix circular locking dependency in ocfs2_dio_end_io_write()", aiming for conciseness and keeping the commit style consistent. That's 65 characters, within the limit. I have to avoid any lines starting with the comment characters in git.
The heart of the issue is a circular dependency involving these three locks: `INODE_ALLOC_SYSTEM_INODE`, `EXTENT_ALLOC_SYSTEM_INODE`, and `ORPHAN_DIR_SYSTEM_INODE`. The cycle starts with `ocfs2_mknod()` where `INODE_ALLOC_SYSTEM_INODE` is acquired before `EXTENT_ALLOC_SYSTEM_INODE`. Then, in `ocfs2_dio_end_io_write()`, `EXTENT_ALLOC_SYSTEM_INODE` is acquired and if the inode is orphaned, `ORPHAN_DIR_SYSTEM_INODE` is acquired later in the function. Finally, in `ocfs2_wipe_inode()`, `ORPHAN_DIR_SYSTEM_INODE` is grabbed and then `INODE_ALLOC_SYSTEM_INODE` is needed to free the inode. The critical point is in `ocfs2_dio_end_io_write()`, where `EXTENT_ALLOC_SYSTEM_INODE` is held while potentially acquiring `ORPHAN_DIR_SYSTEM_INODE`.
The solution is to break this cycle within `ocfs2_dio_end_io_write()`. We can free the `data_ac` and `meta_ac` allocation contexts, which release `EXTENT_ALLOC_SYSTEM_INODE`, *before* calling `ocfs2_del_inode_from_orphan()`. These contexts aren't needed after the transaction is complete, so it's a safe and effective way to release the lock early. Doing so ensures `EXTENT_ALLOC_SYSTEM_INODE` is dropped *before* `ORPHAN_DIR_SYSTEM_INODE` is acquired, severing the dependency loop. The text has been checked against the prompt's constraints.
|