How to change the lock protocol in the superblock for a gfs2 filesystem in RHEL 6, 7, 8, 9?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux Server 6, 7, 8, 9 (with the High Availability and Resilient Storage Add Ons)
  • A Global Filesystem 2 (GFS2)

Issue

  • How to change the locking protocol used for a gfs2 filesystem?

Resolution

The default locking protocol (which is contained in the superblock) on a gfs2 filesystem can be checked with the following command:

#  gfs2_edit -p sb /dev/mapper/vg1-lvol1 | grep sb_lockproto
  sb_lockproto          lock_dlm

RHEL 7 can check the superblock with tunegfs2.

# tunegfs2 -l /dev/mapper/vg1-lvol1 | grep protocol
Lock protocol: lock_dlm

Changing the default locking protocol that is set in the superblock of the gfs2 filesystem permanently can be done with one of the commands below. The filesystem will need to be unmounted before editing the superblock.

All versions can use gfs2_edit to change locking protocols. There are some ways that are exclusive to a particular RHEL release.

gfs2_edit -p sb field sb_lockproto "lock_dlm" /dev/mapper/vg1-lvol1 
RHEL 6
# gfs2_tool sb/dev/mapper/vg1-lvol1  proto lock_dlm
current lock protocol name = "lock_nolock"
new lock protocol name = "lock_dlm"
RHEL 7, 8, 9

RHEL 7 can modify the superblock with [`tunegfs2`](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html-single/global_file_system_2/#gfs2toolreplace) as `gfs2_tool` does not exist on RHEL 7 or later.
# tunegfs2 -l /dev/mapper/vg1-lvol1 | grep protocol
Lock protocol: lock_nolock
# tunegfs2 -o lockproto=lock_dlm /dev/mapper/vg1-lvol1
# tunegfs2 -l /dev/mapper/vg1-lvol1 | grep protocol
Lock protocol: lock_dlm

Mounting the gfs2 filesystem with a particular temporary locking protocol.

# mount -o rw,lockproto=lock_nolock,noatime /dev/mapper/vg1-lvol1 /mnt/gfs2lvol1
# mount | grep /mnt/gfs2lvol1
/dev/mapper/vg1-lvol1 on /mnt/gfs2lvol1 type gfs2 (rw,seclabel,noatime,lockproto=lock_nolock,hostdata=jid=0)

When using lock_nolock as the lock protocol make sure that no other cluster node has the gfs2 filesystem mounted and that the gfs2 filesystem is remounted with lock protocol lock_dlm when multiple cluster nodes will mount the filesystem.

Root Cause

The default lock protocol used by a gfs2 filesystem is located in the superblock of the gfs2 filesystem. The only Red Hat supported gfs2 lock protocol is lock_dlm. There exists another unsupported lock protocol called lock_nolock for mounting the filesystem with no locking mechanism enabled. This protocol if used will cause corruption if more than one cluster node mounts the gfs2 filesystem at a time.

See: Support policies - Mounting conditions and procedures for gfs2 filesystems.

There are very few reasons that lock_nolock would be used when mounting a gfs2 filesystem and there is no reason that lock_nolock should be set in the superblock as default lock protocol as this could lead to corruption if multiple cluster node mounted the filesystem at the same time with default locking protocol.

If for some reason the lock protocol needs to changed then the protocol can be changed at the superblock or at the command line. If changing the lock protocol with gfs2_edit then make sure that no cluster node has the filesystem mounted. The filesystem does not have to be unmounted when printing information about the superblock.

SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.