Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

filelock: convert seqfile handling to use file_lock_core

Reduce some pointer manipulation by just using file_lock_core where we
can and only translate to a file_lock when needed.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20240131-flsplit-v3-33-c6129007ee8d@kernel.org
Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Jeff Layton and committed by
Christian Brauner
a1c2af32 ae7eb16e

+36 -36
+36 -36
fs/locks.c
··· 2718 2718 loff_t li_pos; 2719 2719 }; 2720 2720 2721 - static void lock_get_status(struct seq_file *f, struct file_lock *fl, 2721 + static void lock_get_status(struct seq_file *f, struct file_lock_core *flc, 2722 2722 loff_t id, char *pfx, int repeat) 2723 2723 { 2724 2724 struct inode *inode = NULL; 2725 2725 unsigned int pid; 2726 2726 struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb); 2727 - int type = fl->c.flc_type; 2727 + int type = flc->flc_type; 2728 + struct file_lock *fl = file_lock(flc); 2728 2729 2729 - pid = locks_translate_pid(&fl->c, proc_pidns); 2730 + pid = locks_translate_pid(flc, proc_pidns); 2731 + 2730 2732 /* 2731 2733 * If lock owner is dead (and pid is freed) or not visible in current 2732 2734 * pidns, zero is shown as a pid value. Check lock info from 2733 2735 * init_pid_ns to get saved lock pid value. 2734 2736 */ 2735 - 2736 - if (fl->c.flc_file != NULL) 2737 - inode = file_inode(fl->c.flc_file); 2737 + if (flc->flc_file != NULL) 2738 + inode = file_inode(flc->flc_file); 2738 2739 2739 2740 seq_printf(f, "%lld: ", id); 2740 2741 2741 2742 if (repeat) 2742 2743 seq_printf(f, "%*s", repeat - 1 + (int)strlen(pfx), pfx); 2743 2744 2744 - if (fl->c.flc_flags & FL_POSIX) { 2745 - if (fl->c.flc_flags & FL_ACCESS) 2745 + if (flc->flc_flags & FL_POSIX) { 2746 + if (flc->flc_flags & FL_ACCESS) 2746 2747 seq_puts(f, "ACCESS"); 2747 - else if (fl->c.flc_flags & FL_OFDLCK) 2748 + else if (flc->flc_flags & FL_OFDLCK) 2748 2749 seq_puts(f, "OFDLCK"); 2749 2750 else 2750 2751 seq_puts(f, "POSIX "); 2751 2752 2752 2753 seq_printf(f, " %s ", 2753 2754 (inode == NULL) ? "*NOINODE*" : "ADVISORY "); 2754 - } else if (fl->c.flc_flags & FL_FLOCK) { 2755 + } else if (flc->flc_flags & FL_FLOCK) { 2755 2756 seq_puts(f, "FLOCK ADVISORY "); 2756 - } else if (fl->c.flc_flags & (FL_LEASE|FL_DELEG|FL_LAYOUT)) { 2757 + } else if (flc->flc_flags & (FL_LEASE|FL_DELEG|FL_LAYOUT)) { 2757 2758 type = target_leasetype(fl); 2758 2759 2759 - if (fl->c.flc_flags & FL_DELEG) 2760 + if (flc->flc_flags & FL_DELEG) 2760 2761 seq_puts(f, "DELEG "); 2761 2762 else 2762 2763 seq_puts(f, "LEASE "); 2763 2764 2764 2765 if (lease_breaking(fl)) 2765 2766 seq_puts(f, "BREAKING "); 2766 - else if (fl->c.flc_file) 2767 + else if (flc->flc_file) 2767 2768 seq_puts(f, "ACTIVE "); 2768 2769 else 2769 2770 seq_puts(f, "BREAKER "); ··· 2782 2781 } else { 2783 2782 seq_printf(f, "%d <none>:0 ", pid); 2784 2783 } 2785 - if (fl->c.flc_flags & FL_POSIX) { 2784 + if (flc->flc_flags & FL_POSIX) { 2786 2785 if (fl->fl_end == OFFSET_MAX) 2787 2786 seq_printf(f, "%Ld EOF\n", fl->fl_start); 2788 2787 else ··· 2792 2791 } 2793 2792 } 2794 2793 2795 - static struct file_lock *get_next_blocked_member(struct file_lock *node) 2794 + static struct file_lock_core *get_next_blocked_member(struct file_lock_core *node) 2796 2795 { 2797 - struct file_lock *tmp; 2796 + struct file_lock_core *tmp; 2798 2797 2799 2798 /* NULL node or root node */ 2800 - if (node == NULL || node->c.flc_blocker == NULL) 2799 + if (node == NULL || node->flc_blocker == NULL) 2801 2800 return NULL; 2802 2801 2803 2802 /* Next member in the linked list could be itself */ 2804 - tmp = list_next_entry(node, c.flc_blocked_member); 2805 - if (list_entry_is_head(tmp, &node->c.flc_blocker->flc_blocked_requests, 2806 - c.flc_blocked_member) 2803 + tmp = list_next_entry(node, flc_blocked_member); 2804 + if (list_entry_is_head(tmp, &node->flc_blocker->flc_blocked_requests, 2805 + flc_blocked_member) 2807 2806 || tmp == node) { 2808 2807 return NULL; 2809 2808 } ··· 2814 2813 static int locks_show(struct seq_file *f, void *v) 2815 2814 { 2816 2815 struct locks_iterator *iter = f->private; 2817 - struct file_lock *cur, *tmp; 2816 + struct file_lock_core *cur, *tmp; 2818 2817 struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb); 2819 2818 int level = 0; 2820 2819 2821 - cur = hlist_entry(v, struct file_lock, c.flc_link); 2820 + cur = hlist_entry(v, struct file_lock_core, flc_link); 2822 2821 2823 - if (locks_translate_pid(&cur->c, proc_pidns) == 0) 2822 + if (locks_translate_pid(cur, proc_pidns) == 0) 2824 2823 return 0; 2825 2824 2826 - /* View this crossed linked list as a binary tree, the first member of fl_blocked_requests 2825 + /* View this crossed linked list as a binary tree, the first member of flc_blocked_requests 2827 2826 * is the left child of current node, the next silibing in flc_blocked_member is the 2828 - * right child, we can alse get the parent of current node from fl_blocker, so this 2827 + * right child, we can alse get the parent of current node from flc_blocker, so this 2829 2828 * question becomes traversal of a binary tree 2830 2829 */ 2831 2830 while (cur != NULL) { ··· 2834 2833 else 2835 2834 lock_get_status(f, cur, iter->li_pos, "", level); 2836 2835 2837 - if (!list_empty(&cur->c.flc_blocked_requests)) { 2836 + if (!list_empty(&cur->flc_blocked_requests)) { 2838 2837 /* Turn left */ 2839 - cur = list_first_entry_or_null(&cur->c.flc_blocked_requests, 2840 - struct file_lock, 2841 - c.flc_blocked_member); 2838 + cur = list_first_entry_or_null(&cur->flc_blocked_requests, 2839 + struct file_lock_core, 2840 + flc_blocked_member); 2842 2841 level++; 2843 2842 } else { 2844 2843 /* Turn right */ 2845 2844 tmp = get_next_blocked_member(cur); 2846 2845 /* Fall back to parent node */ 2847 - while (tmp == NULL && cur->c.flc_blocker != NULL) { 2848 - cur = file_lock(cur->c.flc_blocker); 2846 + while (tmp == NULL && cur->flc_blocker != NULL) { 2847 + cur = cur->flc_blocker; 2849 2848 level--; 2850 2849 tmp = get_next_blocked_member(cur); 2851 2850 } ··· 2860 2859 struct list_head *head, int *id, 2861 2860 struct file *filp, struct files_struct *files) 2862 2861 { 2863 - struct file_lock *fl; 2862 + struct file_lock_core *fl; 2864 2863 2865 - list_for_each_entry(fl, head, c.flc_list) { 2864 + list_for_each_entry(fl, head, flc_list) { 2866 2865 2867 - if (filp != fl->c.flc_file) 2866 + if (filp != fl->flc_file) 2868 2867 continue; 2869 - if (fl->c.flc_owner != files && 2870 - fl->c.flc_owner != filp) 2868 + if (fl->flc_owner != files && fl->flc_owner != filp) 2871 2869 continue; 2872 2870 2873 2871 (*id)++;