LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-15-2017, 09:09 AM   #1
ilansch
LQ Newbie
 
Registered: Feb 2017
Posts: 13

Rep: Reputation: Disabled
What is my real device ID on BTRFS ?


Hello,
I am monitoring file operations events (VFS), Its a Debian 7 machine kernel 4.1.21.
I have a problem with BTRFS filesystem, BTRFS is using subvolumes, All highest hierarchy directories in btrfs has the same inode (256/512)

Short story:
When I receive file operation event, I receive the path and then resolve it to inode.
By resolving I mean: given a path, I get its dentry (user_path() call), from dentry i pull: dEntry->d_inode->i_ino
The problem is I receive same inode for different directories on the same Device.
I guess, BTRFS has some sort of abstraction layer, that create a "virtual" inode number (the identical ones are virtual) - there is no way for two identical inodes on same device id.

Proof for device id issue:
From kernel I receive device id 29:
-----------------------------------
Code: device id resolving: for a given path (/home) -> Get the dentry with user_path, then dEntry->d_inode->i_sb->s_dev
OR I run command: "grep btrfs /proc/self/mountinfo | less"
output:
/proc/self/mountinfo return inode 29 also: 34 18 0:29 /home /home rw,noatime,nodiratime shared:19 - btrfs /dev/md127 rw,nospace_cache,subvolid=257,subvol=/home

From user space:
---------------------
root@nas-B9-43-AA:/# stat /home
File: `/home'
Size: 90 Blocks: 0 IO Block: 4096 directory
Device: 21h/33d Inode: 256 Links: 1

root@nas-B9-43-AA:/# mountpoint -d /home
0:33

So I get 29 and 33 as device id.
Lets call device id 29 "actual id"", and 33 is "virtual id".
Is there a way to obtain the actual id from kernel code ? i am looking for replacement to dEntry->d_inode->i_sb->s_dev.. to obtain the same id as we receive from user mode.
 
Old 02-16-2017, 06:58 AM   #2
ilansch
LQ Newbie
 
Registered: Feb 2017
Posts: 13

Original Poster
Rep: Reputation: Disabled
Solution for the problem

Hi,
Instead of going to the dentry - inode - superblock - device id.
I get the device Id using the getattr(..) on the dentry.

My solution is taken from the Suse patch in the subject (after alot of google digging).

https://patchwork.kernel.org/patch/2825842/
 
1 members found this post helpful.
Old 02-16-2017, 07:09 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,792

Rep: Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575Reputation: 3575
Thanks for the post-back. I was going to try some tracing to see if I could see what was happening.
Nice catch.
 
Old 02-16-2017, 07:21 AM   #4
ilansch
LQ Newbie
 
Registered: Feb 2017
Posts: 13

Original Poster
Rep: Reputation: Disabled
next is getting real inode id

the next step and question probably, is getting the true inode number.
all first level directories are inode 256/512 by design (btrfs design).
root@ReadyNAS-DEV:/data# ls -lai
total 48
256 drwxr-xr-x 1 root root 172 Dec 6 03:54 .
256 drwxr-xr-x 1 root root 212 Dec 21 06:29 ..
256 drwxrwxrwx 1 root root 90 Jan 9 07:23 .apps
256 drwxrwxrwx+ 1 guest guest 58 Dec 6 03:55 Documents
256 drwxr-xr-x 1 admin admin 76 Feb 16 04:43 home
257 drwxr-xr-x 1 root root 38 Dec 3 23:41 kernel
256 drwxrwxrwx+ 1 guest guest 20 Nov 20 03:22 Music
256 drwxrwxrwx+ 1 guest guest 244 Dec 21 05:59 nfs
256 drwxrwxrwx+ 1 guest guest 20 Nov 20 03:22 Pictures
256 drwxr-xr-x 1 root root 98 Feb 2 07:09 ._share
256 drwxrwxrwx+ 1 guest guest 44 Jan 22 03:56 smb
256 drwxr-xr-x 1 root root 0 Nov 20 03:22 .timemachine
256 drwxr-xr-x 1 root root 0 Nov 20 03:54 .vault
256 drwxrwxrwx+ 1 guest guest 20 Nov 20 03:22 Videos
root@ReadyNAS-DEV:/data#

256... thats a "virtual node id" and not a real node id. since i proofed the device is the same for all these directories.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mkfs.btrfs not working on an unformatted device mikenash Linux - Enterprise 1 01-25-2017 04:38 PM
btrfs device scan should be performed before fstab mounts saulgoode Slackware 4 10-07-2014 04:43 AM
btrfs filesystem df /mnt/btrfs/ shows bothe data and metdata with raid1 and single. gonus Linux - Software 3 07-17-2014 02:48 PM
LXer: Rollback To A Working State With btrfs + apt-btrfs-snapshot On Ubuntu 12.10 LXer Syndicated Linux News 0 11-25-2012 10:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration