Find out Lock Path in ZFS

Scenario

A linux server that using ZFS storage, exports the directory in the storage using NFS. There is a need to confirm that some files are still locked or not. 

1. Determine Inode

The ls command has -i option to show inode id for each directory/files.

[root@pv1 mysql]# ls -il
total 200867
41506 -rw-rw-r--+ 1 1000070000 nfsnobody         0 Aug 15  2017 debian-5.5.flag
41509 -rw-rw----+ 1 1000070000 nfsnobody 195035136 Apr  5 12:02 ibdata1
41507 -rw-rw----+ 1 1000070000 nfsnobody   5242880 Apr  5 12:02 ib_logfile0
41508 -rw-rw----+ 1 1000070000 nfsnobody   5242880 Mar 26 19:33 ib_logfile1
41376 drwx------+ 2 1000070000 nfsnobody       119 Jul 30  2018 jwdb
41511 drwxr-x---+ 2 1000070000 nfsnobody        74 Aug 15  2017 mysql
41510 -rw-------+ 1 1000070000 nfsnobody         6 Aug 15  2017 mysql_upgrade_info
41487 drwx------+ 2 1000070000 nfsnobody        20 Aug 15  2017 performance_schema

2. Determine Locks

Locks are stored in /proc/locks; the columns are : row number, POSIX/FLOCK, mandatory/advisory, lock mode, process id, major:minor:inode
[root@pv1 ~]# head /proc/locks
1: POSIX  ADVISORY  WRITE 5127 00:27:5841 0 EOF
2: POSIX  ADVISORY  WRITE 5127 00:27:69634 0 EOF
3: POSIX  ADVISORY  WRITE 5127 00:27:35661 0 EOF
4: POSIX  ADVISORY  WRITE 5127 00:27:82713 0 EOF
5: POSIX  ADVISORY  WRITE 5127 00:27:82707 0 EOF
6: POSIX  ADVISORY  WRITE 5127 00:27:28639 0 EOF
7: POSIX  ADVISORY  WRITE 29695 fd:00:17154793 0 EOF
8: POSIX  ADVISORY  WRITE 1417 00:12:18009 0 EOF
9: FLOCK  ADVISORY  WRITE 1416 00:12:18004 0 EOF
10: POSIX  ADVISORY  WRITE 5127 00:27:261122 0 EOF

3. Cross check inode id and locks

[root@pv1 ~]# cat /proc/locks | grep 41509
345: POSIX  ADVISORY  WRITE 5127 00:27:41509 0 EOF

This means the ibdata1 file are still locked.

4. Alternative : Determine Path From Inode ID

[root@pv1 ~]# head /proc/locks
1: POSIX  ADVISORY  WRITE 5127 00:27:5841 0 EOF
2: POSIX  ADVISORY  WRITE 5127 00:27:69634 0 EOF
3: POSIX  ADVISORY  WRITE 5127 00:27:35661 0 EOF
4: POSIX  ADVISORY  WRITE 5127 00:27:82713 0 EOF
5: POSIX  ADVISORY  WRITE 5127 00:27:82707 0 EOF
6: POSIX  ADVISORY  WRITE 5127 00:27:28639 0 EOF
7: POSIX  ADVISORY  WRITE 29695 fd:00:17154793 0 EOF
8: POSIX  ADVISORY  WRITE 1417 00:12:18009 0 EOF
9: FLOCK  ADVISORY  WRITE 1416 00:12:18004 0 EOF
10: POSIX  ADVISORY  WRITE 5127 00:27:261122 0 EOF

Try one of the Inode id shown (5841):

[root@pv1 ~]# zfs list
NAME          USED  AVAIL  REFER  MOUNTPOINT
pool1         426G  43.6G    19K  /pool1
pool1/data1   426G  43.6G   364G  /data
[root@pv1 ~]# zdb -dddd pool1/data1 5841
Dataset pool1/data1 [ZPL], ID 41, cr_txg 28, 364G, 229744 objects, rootbp DVA[0]=<0:f0b562c00:200> DVA[1]=<1:354d34c00:200> [L0 DMU objset] fletcher4 lz4 LE contiguous unique double size=800L/200P birth=12610129L/12610129P fill=229744 cksum=174031e67e:6cd4fa9f9ec:1280395cd1030:253e3b3c546d06

    Object  lvl   iblk   dblk  dsize  lsize   %full  type
      5841    1    16K  96.0K  96.0K  96.0K  100.00  ZFS plain file
                                        292   bonus  System attributes
dnode flags: USED_BYTES USERUSED_ACCOUNTED 
dnode maxblkid: 0
path /exports/pv0000021/mysql/engine_cost.ibd
uid     1000510000
gid     65534
atime Wed Apr 10 14:49:17 2019
mtime Mon Aug 14 18:47:44 2017
ctime Mon Aug 14 18:47:44 2017
crtime Mon Aug 14 18:47:41 2017
gen 1072474
mode 100640
size 98304
parent 5756
links 1
pflags 40800000004
SA xattrs: 116 bytes, 1 entries

system.posix_acl_access = \002\000\000\000\001\000\006\000\377\377\377\377\002\000\007\000\376\377\000\000\004\000\007\000\377\377\377\377\010\000\007\000\376\377\000\000\020\000\004\000\377\377\377\377 \000\000\000\377\377\377\377

[root@pv1 ~]# 



Comments

Popular posts from this blog

Long running process in Linux using PHP

Reverse Engineering Reptile Kernel module to Extract Authentication code

SAP System Copy Lessons Learned