61 Commits

Author SHA1 Message Date
Arshad Hussain
4beaabdd2f
Revert "Backport to kernel version 3.10" 2021-02-11 11:47:53 +05:30
Arshad Hussain
4b5576cec7 Backport to kernel version 3.10
This patch backports simplefs to kernel version 3.10.
current_time(struct inode *) was introduced from kernel
version 4.9. This patch backports simplefs to kernel
version 3.10 (Centos 7.5) by replacing current_time()
by CURRENT_TIME macro. The idea is to 'tag' this version
such that is becomes easy to experiment on commanly used
distribution which comes with little dated kernel.

After Patch:
~~~~~~~~~~~~
$ cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

$ make
make -C /lib/modules/3.10.0-957.el7.x86_64/build M=/root/dev_world/simplefs modules
make[1]: Entering directory `/usr/src/kernels/3.10.0-957.el7.x86_64'
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: Leaving directory `/usr/src/kernels/3.10.0-957.el7.x86_64'
$

$ insmod simplefs.ko

$ lsmod | grep simplefs
simplefs               18383  0
jbd2                  107478  2 ext4,simplefs

Signed-off-by: Arshad Hussain <arshad.super@gmail.com>
2021-02-10 15:17:17 +05:30
Tim Gates
60ac9bfa17
docs: fix simple typo, insted -> instead (#12)
There is a small typo in simple.c.

Should read `instead` rather than `insted`.
2020-12-13 08:51:24 +05:30
Brian Henning
70b56643d4 added initialization of a variable 2019-10-26 17:11:23 -05:00
Azat Khuzhin
df5314f27d Use current_time() over CURRENT_TIME macro
And this wasn't done undef #ifdef due to we already had current_time()
users
2018-04-20 02:30:19 +03:00
Barry Song
90e4702d37 fix ‘struct file’ has no member named ‘f_dentry’
Removed-in: torvalds/linux@78d28e651f
("kill f_dentry macro")

Signed-off-by: Barry Song <21cnbao@gmail.com>
Closes: #10 (picked)
2018-04-20 02:30:19 +03:00
Shrikant Giridhar
38669257c5 Fix usage of CURRENT_TIME macro.
The CURRENT_TIME macro is no longer valid with the latest kernel
(commit bfe1c566453a0979c0b3cd3728d0de962272f034). Replace usage
with current_time() function.
2017-06-14 00:38:19 -04:00
Azat Khuzhin
4c486f751b simplefs_write: install h_sync (sync on close) for jbd2 handle
This will make simplefs journaling more robust.

+ head -n100 /proc/fs/jbd2/loop0/info
7 transactions (7 requested), each up to 640 blocks
average:
  0ms waiting for transaction
  10ms request delay
  26ms running transaction
  0ms transaction was being locked
  0ms flushing data (in ordered mode)
  0ms logging transaction
  3459us average transaction commit time
  1 handles per transaction
  1 blocks per transaction
  2 logged blocks per transaction
2014-10-02 02:20:37 +04:00
Azat Khuzhin
49937e8acf Use max available journal size with jbd2_journal_init_dev()
Avoid next error:
JBD2: journal file too short
2014-10-02 02:20:37 +04:00
Azat Khuzhin
cb833cd591 Handle bdevs for journal_path= mount flag 2014-10-02 02:20:37 +04:00
Azat Khuzhin
87e3751725 Actually load journal by calling jbd2_journal_load() 2014-10-02 02:20:37 +04:00
Azat Khuzhin
33f5f117df Implement journal_path option 2014-10-02 02:20:37 +04:00
Azat Khuzhin
fd1dc7a951 Add loader for internal journal (we need to update mkfs to support this)
For internal journal we need enhance mkfs to use ext2fs lib, that will
allow us to create journal (with proper header).
2014-10-02 02:20:37 +04:00
Azat Khuzhin
bd1188801c Add sfs_trace for lookup and compare inside it 2014-10-02 02:20:37 +04:00
Azat Khuzhin
a619accdc7 Check that journal was initialized successfully
Otherwise you will next trace:
[  964.775061] The magic number obtained in disk is: [268640275]
[  964.775554] simplefs filesystem of version [1] formatted with a block size of [4096] detected in the device.
[  964.776308] Loading journal devnum: 63
[  964.776724] Journal device is: unknown-block(0,63)
[  964.779494] simplefs superblock is destroyed. Unmount succesful.
[  964.781366] Freeing private data of inode ffff88007babe3a8 (1)
[  964.781903] simplefs is succesfully mounted on [/dev/loop0]
[  964.782393] BUG: unable to handle kernel NULL pointer dereference at 0000000000000069
[  964.783381] IP: [<ffffffff8112f0b3>] mount_fs+0x71/0x148
[  964.783977] PGD 7a545067 PUD 7a514067 PMD 0
[  964.784814] Oops: 0000 [#1] PREEMPT SMP
[  964.785176] Modules linked in: simplefs(PO) loop fuse joydev hid_generic usbhid hid snd_pcm microcode snd_timer snd psmouse soundcore evdev pcspkr serio_raw ohci_pci ohci_hcd ehci_hcd processor parport_pc usbcore button battery ac thermal_sys parport i2c_piix4 usb_common i2c_core ext4 crc16 jbd2 mbcache sg sd_mod sr_mod crc_t10dif cdrom crct10dif_common ata_generic ahci libahci ata_piix libata scsi_mod e1000 [last unloaded: simplefs]
[  964.785176] CPU: 0 PID: 3507 Comm: mount Tainted: P           O 3.14.0-rc6+ #101
[  964.785176] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[  964.785176] task: ffff88007cb8c6d0 ti: ffff88007ad04000 task.ti: ffff88007ad04000
[  964.785176] RIP: 0010:[<ffffffff8112f0b3>]  [<ffffffff8112f0b3>] mount_fs+0x71/0x148
[  964.785176] RSP: 0018:ffff88007ad05e40  EFLAGS: 00010203
[  964.785176] RAX: 0000000000000001 RBX: ffff88007c0fd000 RCX: 0000000000000007
[  964.785176] RDX: 0000000000000001 RSI: 0000000000000046 RDI: 00000000ffffffff
[  964.785176] RBP: ffff88007ad05e70 R08: 0000000000000004 R09: ffff8800000bbca0
[  964.785176] R10: fffffff000007bf4 R11: 0000000000000000 R12: ffff88007a329000
[  964.785176] R13: 0000000000000001 R14: ffffffffa01d2000 R15: 0000000000000000
[  964.785176] FS:  00007f195521f840(0000) GS:ffff88007fc00000(0000) knlGS:0000000000000000
[  964.785176] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[  964.785176] CR2: 0000000000000069 CR3: 000000007a540000 CR4: 00000000000006f0
[  964.785176] Stack:
[  964.785176]  ffff88007a1de080 ffff88007a1de080 ffffffffa01d2000 ffff8800377b2220
[  964.785176]  ffff88007c0fd000 ffffffffa01d2000 ffff88007ad05ea8 ffffffff81143628
[  964.785176]  0000000081142d1b ffff88007c0fd000 ffff8800377b2220 0000000000000027
[  964.785176] Call Trace:
[  964.785176]  [<ffffffff81143628>] vfs_kern_mount+0x5f/0xd3
[  964.785176]  [<ffffffff811458e9>] do_mount+0x6f9/0x7f0
[  964.785176]  [<ffffffff81145c01>] SyS_mount+0x80/0xb9
[  964.785176]  [<ffffffff813d2262>] system_call_fastpath+0x16/0x1b
[  964.785176] Code: cf 06 00 85 c0 0f 85 d0 00 00 00 4c 89 ea 48 89 d9 44 89 fe 4c 89 f7 41 ff 56 10 49 89 c5 49 81 fd 00 f0 ff ff 0f 87 b0 00 00 00 <49> 8b 5d 68 48 85 db 75 02 0f 0b 48 83 bb d0 00 00 00 00 75 11
[  964.785176] RIP  [<ffffffff8112f0b3>] mount_fs+0x71/0x148
[  964.785176]  RSP <ffff88007ad05e40>
[  964.785176] CR2: 0000000000000069
[  964.820009] ---[ end trace fc63610f0693bff7 ]---
2014-10-02 02:20:37 +04:00
Azat Khuzhin
aa630d8e0f Write journal device name 2014-10-02 02:20:37 +04:00
Azat Khuzhin
57a1e15c0f Implement external journal device instead of internal 2014-10-02 02:20:37 +04:00
Azat Khuzhin
f8009d2223 simplefs_write: add journaling using jbd2 2014-10-02 02:20:37 +04:00
Azat Khuzhin
dad5b1c50e Initial support of journaling
- Reorder block numbers to make it more sequental for mkfs
- mkfs: adjust writing, to make it correct write journal blocks and ino too
- simplefs_iget: use fops for journal inode
- simplefs_iget: check sfs_inode->mode instead of i_mode (not initialized yet)
2014-10-02 02:20:37 +04:00
Azat Khuzhin
bb70d76497 Add BUG_ON() after each sb_bread() to avoid NULL dereferencing
If mkfs-simple will have bugs, than it could obtain illegal block number, and
sb_bread() will return NULL, even without it could return NULL, so since this
fs is just for testing, simply add bug_on() to avoid going further.

[ 1247.861163] The magic number obtained in disk is: [268640275]
[ 1247.861165] simplefs filesystem of version [1] formatted with a block size of [4096] detected in the device.
[ 1247.861194] simplefs is succesfully mounted on [/dev/loop0]
[ 1247.886800] BUG: unable to handle kernel NULL pointer dereference at           (null)
[ 1247.886804] IP: [<ffffffffa00ca695>] simplefs_lookup+0xb5/0x180 [simplefs]
[ 1247.886808] PGD 5eda6067 PUD 5eda5067 PMD 0
[ 1247.886810] Oops: 0000 [#1] SMP
[ 1247.886812] Modules linked in: simplefs(POE) snd_intel8x0 snd_ac97_codec ac97_bus snd_pcm snd_seq_midi snd_seq_midi_event snd_rawmidi snd_seq snd_seq_device intel_rapl snd_timer joydev snd rfcomm bnep bluetooth 6lowpan_iphc serio_raw i2c_piix4 mac_hid soundcore parport_pc ppdev lp parport hid_generic usbhid hid psmouse ahci libahci e1000 pata_acpi [last unloaded: simplefs]
[ 1247.886826] CPU: 0 PID: 9467 Comm: cat Tainted: P           OE 3.15.0-6-generic #11-Ubuntu
[ 1247.886827] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 1247.886828] task: ffff88005e72cb90 ti: ffff88005ede8000 task.ti: ffff88005ede8000
[ 1247.886829] RIP: 0010:[<ffffffffa00ca695>]  [<ffffffffa00ca695>] simplefs_lookup+0xb5/0x180 [simplefs]
[ 1247.886832] RSP: 0018:ffff88005edebc88  EFLAGS: 00010292
[ 1247.886833] RAX: 0000000000000002 RBX: 0000000000000000 RCX: ffff88005f5370a0
[ 1247.886834] RDX: ffff880024c9a108 RSI: ffff880024c9bb60 RDI: ffff880024c9a000
[ 1247.886834] RBP: ffff88005edebcc0 R08: 0000000000000000 R09: 0000000000000001
[ 1247.886835] R10: ffff88005edebab8 R11: 0000000000000000 R12: ffff88005f537000
[ 1247.886836] R13: ffff88005ed68000 R14: 0000000000000000 R15: ffff880024c9a000
[ 1247.886837] FS:  00007ffb35497740(0000) GS:ffff880065c00000(0000) knlGS:0000000000000000
[ 1247.886838] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 1247.886839] CR2: 0000000000000000 CR3: 000000005edfa000 CR4: 00000000000006f0
[ 1247.886843] Stack:
[ 1247.886844]  ffff880024c9bb60 ffff88001d19e180 ffff88001d19e180 0000000000008000
[ 1247.886845]  ffff88005edebde8 ffff88001d159e40 ffff88005edebe40 ffff88005edebce0
[ 1247.886847]  ffffffff811da5ed ffff88001d159e40 ffff88005edebf2c ffff88005edebd88
[ 1247.886848] Call Trace:
[ 1247.886853]  [<ffffffff811da5ed>] lookup_real+0x1d/0x70
[ 1247.886856]  [<ffffffff811df537>] do_last+0x797/0x1270
[ 1247.886860]  [<ffffffff8132c81b>] ? apparmor_file_alloc_security+0x5b/0x180
[ 1247.886862]  [<ffffffff812ed116>] ? security_file_alloc+0x16/0x20
[ 1247.886864]  [<ffffffff811e119b>] path_openat+0xbb/0x6a0
[ 1247.886866]  [<ffffffff811e285a>] do_filp_open+0x3a/0xa0
[ 1247.886868]  [<ffffffff811ef597>] ? __alloc_fd+0xa7/0x130
[ 1247.886871]  [<ffffffff811cff8a>] do_sys_open+0x12a/0x280
[ 1247.886874]  [<ffffffff81020925>] ? syscall_trace_enter+0x165/0x2a0
[ 1247.886876]  [<ffffffff811d00fe>] SyS_open+0x1e/0x20
[ 1247.886879]  [<ffffffff8176e33f>] tracesys+0xe1/0xe6
[ 1247.886880] Code: 01 00 00 4c 89 e7 e8 ab fe ff ff 4c 89 e7 48 89 c3 e8 f0 38 12 e1 49 89 c7 49 8b 85 00 01 00 00 48 8b 34 24 4c 89 ff 49 89 47 40 <0f> b7 13 e8 83 0f 12 e1 41 0f b7 07 4d 89 67 28 49 c7 47 20 40
[ 1247.886894] RIP  [<ffffffffa00ca695>] simplefs_lookup+0xb5/0x180 [simplefs]
[ 1247.886896]  RSP <ffff88005edebc88>
[ 1247.886896] CR2: 0000000000000000
[ 1247.886898] ---[ end trace 89702ff0fda32679 ]---
2014-07-12 22:21:49 +04:00
asfdfdfd
ed7ff8a42d Typo in comment fixed. 2014-03-29 16:08:08 +03:00
Azat Khuzhin
3050cdf2ed Use slab allocator for simplefs_inode
Struct simplefs_inode allocation is quite frequently (for fs), so it
will be better to use slab allocator instead of page allocator.
2013-09-30 22:46:56 +04:00
Azat Khuzhin
031f974c36 fix another inode leaking in simplefs_create_fs_object()
There we iterate over inodes using simplefs_get_inode(), while instead
we already have last inode number, just use it instead, and increment
some paddings to it (start inode, reserved inodes).

And form after this patch kedr shows that there is no leaks.
(but we must recheck it in the future.)
2013-09-30 02:34:05 +04:00
Azat Khuzhin
98bbe99632 Fix leaking of inode memory.
Release bh in simplefs_get_inode() and use kmalloc() instead, and also
add super_operations.destory_inode handler, to free allocated memory.

This is not optimal and it must be replaced by slab allocators.
2013-09-30 02:13:24 +04:00
Azat Khuzhin
7130573869 read: drop static "done" variable, we already have file_size in inode. 2013-09-29 20:22:03 +04:00
Azat Khuzhin
86d7a8ff80 Add new helper - simplefs_inode_save()
And use it next functions:
- simplefs_write()
- simplefs_create_fs_object()
2013-09-29 20:01:35 +04:00
Azat Khuzhin
2d95ccf1a3 Start implementing verbose logging depends on macros. (SIMPLEFS_DEBUG)
In many cases we don't need such verbose loggin, just add macros to
print loggin only if SIMPLEFS_DEBUG isset.
And it will be installed by default. (in Makefile)
2013-09-29 18:09:44 +04:00
Azat Khuzhin
f9aa71628d Add new helper simplefs_inode_search() 2013-09-29 16:41:48 +04:00
Azat Khuzhin
c199cecbce simplefs_create_fs_object(): release mutexes when we can't acquire sb_lock
We need more pretty code for this.
2013-09-25 18:09:01 +04:00
Azat Khuzhin
ee1efa11df sb: use s_maxbytes field instead of hardcoded check in simplefs_write()
generic_write_checks() will do this for us now, using s_maxbytes field
from sb.
2013-09-25 15:41:39 +04:00
Azat Khuzhin
ab68a5176a simplefs_write(): use generic_write_checks() 2013-09-25 15:36:01 +04:00
Azat Khuzhin
274a98ae14 Add TODO about moving version depend code into separate header. 2013-09-25 00:48:31 +04:00
Azat Khuzhin
f72fbd4db6 Add new const SIMPLEFS_START_INO instead of magic number 2013-09-18 23:43:50 +04:00
Azat Khuzhin
82a2041957 simplefs_create_fs_object(): avoid extra allocation of memory
We can just use already existed bh->b_data for this, and copy filename
and inode number directly to it.
2013-09-18 23:17:42 +04:00
Azat Khuzhin
0e14ca0edc simplefs_fill_super() drop deprecated FIXME (see 9aee1ce) 2013-09-18 23:07:11 +04:00
Azat Khuzhin
3cae84d822 Drop explicit cast sb_bread() return value to buffer_head
Since sb_bread() already have such a return value.
2013-09-16 02:31:13 +04:00
Azat Khuzhin
9aee1ce302 Release bh in simplefs_fill_super() 2013-09-16 02:28:46 +04:00
Azat Khuzhin
90ca0e557c Add FS_REQUIRES_DEV to fs_flags 2013-09-16 02:13:52 +04:00
Azat Khuzhin
23d554cda7 Use kill_block_super() in simplefs_kill_superblock() 2013-09-16 02:12:45 +04:00
Azat Khuzhin
8382ab7e81 simple.c: drop trailing whitespace 2013-09-16 02:10:49 +04:00
Azat Khuzhin
6d606a796c simplefs_create_fs_object: fix memory leaking of temporary record 2013-09-14 13:48:15 +04:00
Azat Khuzhin
a315571b05 Use d_alloc_root() instead of d_make_root() in linux kernel < 3.3
d_alloc_root() is gone in 32991ab305ace7017c62f8eecbe5eb36dc32e13b.

Link: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=32991ab305ace7017c62f8eecbe5eb36dc32e13b
2013-09-10 23:45:45 +04:00
Azat Khuzhin
18df3131a2 Don't change filp->f_pos in fops->iterate. (linux kernel >= 3.11)
iterate_dir() already change filp->f_pos (using ctx->f_pos).
Thanks to Ivan.

Discussion: 3f472cec01 (commitcomment-4057234)
2013-09-10 22:21:59 +04:00
Azat Khuzhin
b42b87a9bc Implement file_operations.iterate instead of deprecated readdir
In newer version of kernel, since 3.11, readdir was dropped and the
replacment is iterate.
2013-08-15 01:08:56 +04:00
Sankar சங்கர்
7e6b073449 Update parent directory inode children count on new file/subdir creation. 2013-08-05 22:46:19 +05:30
Sankar சங்கர்
a68d101c93 basic write support 2013-07-28 21:26:46 +05:30
Sankar சங்கர்
22f33bcd32 mkidr support for simplefs 2013-07-27 18:45:38 +05:30
Sankar சங்கர்
6c591e9eb3 create file support 2013-07-27 01:02:11 +05:30
Sankar சங்கர்
356bceb273 read support for existing files 2013-07-24 17:29:50 +05:30
Sankar சங்கர்
3ad58de506 Lindent sources 2013-04-23 14:29:30 +05:30