安装 CIFS 共享失败,并显示:数值结果超出范围

安装 CIFS 共享失败,并显示:数值结果超出范围

在 RHEL7 中挂载 cifs 共享失败,并出现以下错误:“挂载:无法解析挂载选项:数值结果超出范围”

# LIBMOUNT_DEBUG=0xffff mount //fileserver/db-mysql /mnt/mysqlBackups -t cifs -o credentials=/etc/samba/fileserver.password,forceuid,uid=mysql,forcegid,gid=mysql,file_mode=0664,dir_mode=0775 -v

5561: libmount:     INIT: library debug mask: 0xffff
5561: libmount:     INIT: library version: 2.23.0
5561: libmount:     INIT:     feature: selinux
5561: libmount:     INIT:     feature: debug
5561: libmount:     INIT:     feature: assert
5561: libmount:      CXT: [0x7ff506842050]: ----> allocate
5561: libmount:    UTILS: mtab: /etc/mtab
5561: libmount:    UTILS: /etc/mtab: irregular/non-writable
5561: libmount:    UTILS: utab: /run/mount/utab
5561: libmount:      CXT: [0x7ff506842050]: enabling flag 0010
5561: libmount:      CXT: [0x7ff506842050]: mount: preparing
5561: libmount:      CXT: [0x7ff506842050]: use default optmode
5561: libmount:      CXT: [0x7ff506842050]: OPTSMODE: ignore=0, append=0, prepend=1, replace=0, force=0, fstab=1, mtab=1
5561: libmount:      CXT: [0x7ff506842050]: fstab not required -- skip
5561: libmount:      CXT: [0x7ff506842050]: merging mount flags
5561: libmount:      CXT: [0x7ff506842050]: final flags: VFS=00000000 user=00000000
5561: libmount:      CXT: [0x7ff506842050]: mount: evaluating permissions
5561: libmount:      CXT: [0x7ff506842050]: mount: fixing optstr
5561: libmount:      CXT: [0x7ff506842050]: mount: fixing vfs optstr
5561: libmount:      CXT: applying 0x00000000 flags to '(null)'
5561: libmount:      CXT: new optstr 'rw'
5561: libmount:      CXT: [0x7ff506842050]: mount: fixing user optstr
5561: libmount:      CXT: applying 0x00000000 flags to '(null)'
5561: libmount:      CXT: new optstr '(null)'
5561: libmount:      CXT: fixing uid
5561: libmount:      CXT: fixing gid
5561: libmount:    UTILS: cannot convert 'mysql' groupname to GID
5561: libmount:      CXT: [0x7ff506842050]: fixed options [rc=-34]: vfs: 'rw' fs: 'credentials=/etc/samba/fileserver.password,forceuid,uid=27,forcegid,gid=mysql,file_mode=0664,dir_mode=0775' user: '(null)', optstr: 'credentials=/etc/samba/fileserver.password,forceuid,uid=mysql,forcegid,gid=mysql,file_mode=0664,dir_mode=0775'
5561: libmount:      CXT: [0x7ff506842050]: mount: preparing failed
mount: failed to parse mount options: Numerical result out of range
5561: libmount:      CXT: [0x7ff506842050]: <---- reset [status=0] ---->
5561: libmount:      CXT: [0x7ff506842050]: tabfiler disabled
5561: libmount:      CXT: [0x7ff506842050]: <---- free

mysql 组存在:

# getent group mysql
mysql:x:27:
# grep mysql /etc/group
mysql:x:27:
# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
# ls -lZ /etc/group /etc/passwd
-rw-r--r--. root root system_u:object_r:passwd_file_t:s0 /etc/group
-rw-r--r--. root root system_u:object_r:passwd_file_t:s0 /etc/passwd

如果发现有趣的话,直接使用它就mount.cifs可以了:

# mount.cifs //fileserver/db-mysql /mnt/mysqlBackups --verbose -o credentials=/etc/samba/fileserver.password,forceuid,uid=mysql,forcegid,gid=mysql,file_mode=0664,dir_mode=0775
Credential formatted incorrectly: (null)
domain=fileserver
mount.cifs kernel mount options: ip=10.1.2.20,unc=\\fileserver\db-mysql,forceuid,forcegid,file_mode=0664,dir_mode=0775,uid=27,gid=27,user=svc_linux,,domain=fileserver,pass=********

# grep /mnt/mysqlBackups /proc/mounts
//fileserver/db-mysql /mnt/mysqlBackups cifs rw,relatime,vers=1.0,cache=strict,username=svc_linux,domain=fileserver,uid=27,forceuid,gid=27,forcegid,addr=10.1.2.20,file_mode=0664,dir_mode=0775,nounix,serverino,rsize=61440,wsize=65536,actimeo=1 0 0

它发生在:

# uname -rvpio
3.10.0-327.36.1.el7.x86_64 #1 SMP Sun Sep 18 13:04:29 UTC 2016 x86_64 x86_64 GNU/Linux

同样的问题:

# uname -rvpio
3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 x86_64 x86_64 GNU/Linux

mount 和 mount.cifs 是 RHEL7 的最新版本:

# rpm -q util-linux cifs-utils
util-linux-2.23.2-26.el7_2.3.x86_64
cifs-utils-6.2-7.el7.x86_64

看来getgrnam_r(3)呼叫失败了。

编辑1:
我想使用用户名和组名而不是 UID GID。我知道使用数字 ID 可以解决问题。我知道删除gid=mysql它会起作用。为什么对于用户挂载可以找到 UID,但对于组却找不到 GID?

编辑2: 该错误似乎是由以下代码引发的: https://github.com/karelzak/util-linux/blob/master/libmount/src/utils.c#L703

所以我尝试用以下代码进行重现,但调用成功了。这对我来说很奇怪。抱歉,C 代码写得有点粗糙,我不是程序员。

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <grp.h>
#define UL_GETPW_BUFSIZ (16 * 1024)

int main(void)
{
    int rc = -1;
    struct group grp;
    struct group *gr;
    char *buf;
    int _gid=10;
    gid_t *gid = (gid_t *)& _gid;
    char *groupname = "mysql";

    if (!groupname || !gid)
        return -EINVAL;

    buf = malloc(UL_GETPW_BUFSIZ);
    if (!buf)
        return -ENOMEM;

    if (!getgrnam_r(groupname, &grp, buf, UL_GETPW_BUFSIZ, &gr) && gr) {
        *gid= gr->gr_gid;
        printf("gid=%i\n",*gid);
        rc = 0;
    } else {
        printf("cannot convert '%s' groupname to GID\n", groupname);
        rc = errno ? -errno : -EINVAL;
    }

    free(buf);

    return rc;
}
// vim:ts=4:sts=4:sw=4:et:

没有报告错误:

# gcc -Wall -W test.c
# ./a.out
gid=27
#

编辑3: 如果我尝试gid=dbus它起作用:

# egrep 'mysql|dbus' /etc/passwd /etc/shadow /etc/group /etc/gshadow
/etc/passwd:dbus:x:81:81:System message bus:/:/sbin/nologin
/etc/passwd:mysql:x:27:27:Percona Server:/var/lib/mysql:/bin/false
/etc/shadow:dbus:!!:17086::::::
/etc/shadow:mysql:!!:17104::::::
/etc/group:dbus:x:81:
/etc/group:mysql:x:27:
/etc/gshadow:dbus:!::
/etc/gshadow:mysql:!::
# LIBMOUNT_DEBUG=0xffff  mount //fileserver/db-mysql /mnt/mysqlBackups -t cifs -o credentials=/etc/samba/fileserver.password,forceuid,uid=mysql,forcegid,file_mode=0664,dir_mode=0775,gid=dbsu
10777: libmount:     INIT: library debug mask: 0xffff
10777: libmount:     INIT: library version: 2.23.0
10777: libmount:     INIT:     feature: selinux
10777: libmount:     INIT:     feature: debug
10777: libmount:     INIT:     feature: assert
10777: libmount:      CXT: [0x7f687bf74050]: ----> allocate
10777: libmount:    UTILS: mtab: /etc/mtab
10777: libmount:    UTILS: /etc/mtab: irregular/non-writable
10777: libmount:    UTILS: utab: /run/mount/utab
10777: libmount:      CXT: [0x7f687bf74050]: mount: preparing
10777: libmount:      CXT: [0x7f687bf74050]: use default optmode
10777: libmount:      CXT: [0x7f687bf74050]: OPTSMODE: ignore=0, append=0, prepend=1, replace=0, force=0, fstab=1, mtab=1
10777: libmount:      CXT: [0x7f687bf74050]: fstab not required -- skip
10777: libmount:      CXT: [0x7f687bf74050]: merging mount flags
10777: libmount:      CXT: [0x7f687bf74050]: final flags: VFS=00000000 user=00000000
10777: libmount:      CXT: [0x7f687bf74050]: mount: evaluating permissions
10777: libmount:      CXT: [0x7f687bf74050]: mount: fixing optstr
10777: libmount:      CXT: [0x7f687bf74050]: mount: fixing vfs optstr
10777: libmount:      CXT: applying 0x00000000 flags to '(null)'
10777: libmount:      CXT: new optstr 'rw'
10777: libmount:      CXT: [0x7f687bf74050]: mount: fixing user optstr
10777: libmount:      CXT: applying 0x00000000 flags to '(null)'
10777: libmount:      CXT: new optstr '(null)'
10777: libmount:      CXT: fixing uid
10777: libmount:      CXT: fixing gid
10777: libmount:    UTILS: cannot convert 'dbsu' groupname to GID
10777: libmount:      CXT: [0x7f687bf74050]: fixed options [rc=-34]: vfs: 'rw' fs: 'credentials=/etc/samba/fileserver.password,forceuid,uid=27,forcegid,file_mode=0664,dir_mode=0775,gid=dbsu' user: '(null)', optstr: 'credentials=/etc/samba/fileserver.password,forceuid,uid=mysql,forcegid,file_mode=0664,dir_mode=0775,gid=dbsu'
10777: libmount:      CXT: [0x7f687bf74050]: mount: preparing failed
mount: failed to parse mount options: Numerical result out of range
10777: libmount:      CXT: [0x7f687bf74050]: <---- reset [status=0] ---->
10777: libmount:      CXT: [0x7f687bf74050]: tabfiler disabled
10777: libmount:      CXT: [0x7f687bf74050]: <---- free

答案1

您的 CIFS 启用系统无法将组名映射mysql到 GID 27,而是尝试将其解析mysql为数字 GID 值。这显然超出范围,因为它是一个字符串而不是整数。目前我尚不清楚这是主机端还是客户端的故障。

mysql如果两台服务器上没有相同的组名和用户名以及相应的 ID,则可以通过groupmod命令或编辑/etc/group文件来修复。如果两台主机上所需的 GID 和 UID 相同,或固定默认值(例如mysql27是),则通过数字而不是名称指定 GUID 和 UID。这有点不方便,但可能会奏效。

有必要进一步调查为什么无法将名称映射到 ID 的数字。自 mount.cifs 1.10 以来,我们就能够使用修饰用户名和组名。不过,如果您没有在通常的挂载过程中调用 mount.cifs 帮助程序来挂载此卷,那么您可能永远无法使用修饰名,除非它在您使用的任何帮助程序中明确实现。

相关内容