免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 971 | 回复: 0
打印 上一主题 下一主题

NFS mount flags error! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-09 22:47 |只看该作者 |倒序浏览
需要写一个用来mount远地nfs server的程序,用户态,由于安全考虑不使用system方式挂载,而直接使用系统api,可是遇到了问题,下面是写的代码?测试结果是,不能每次都mount上磁盘,运气好的话,可以mount上远地的nfs,可是不是每次都成功,而且不成功的次数大多数。非常郁闷,希望大家的帮助。
#include <sys/mount.h>
#include <linux/nfs_mount.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>

#define PBUFSIZE        8192

static char *target="/mnt/gt11server";
static char *source="192.168.0.11:/mnt/ramdisk/";
static char *filesystemtype="nfs";
static unsigned long  mountflags = MS_MGC_VAL ;
static int  nfs_mount_version   = NFS_MOUNT_VERSION;

int main(){
        int ret = 0;
        int sockfd, n ,ksock;
        struct sockaddr_in seradd, cliadd;
        struct nfs_mount_data data;
        struct nfs_fh   *root_fh = (struct nfs_fs *)malloc(sizeof(struct nfs_fh));
        int bufsize = 32*1024;  //32k

        if ( (sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_UDP)) < 0)
                 fprintf(stderr,"socket error");

        setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize));
        bind( sockfd, (struct sockaddr* )& seradd, sizeof(seradd));


        ksock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        bind(ksock, (struct sockaddr*)&cliadd, sizeof(cliadd));


//-------------modifed by
        memset(&data, 0, sizeof(data));
        data.version    = nfs_mount_version;
        data.fd         = ksock;
        data.old_root   = *root_fh;
        data.flags      = NFS_MOUNT_INTR | NFS_MOUNT_NOCTO;
        data.rsize      = PBUFSIZE;
data.timeo      = 600;
        data.retrans    = 10;
        data.acregmin   = 3;
        data.acregmax   = 60;
        data.acdirmin   = 30;
        data.acdirmax   = 60;
        data.addr       = seradd;
        strcpy(data.hostname, "localhost");
        data.namlen     = 256;
        data.bsize      = 256;
        data.root       = *root_fh;

//------------------------


        ret = mount(source, target, filesystemtype, mountflags, &data);
        printf("ret is %d\n", ret);
        if (ret != 0){
                printf("mount error happened!\n");
                return -1;
        }


        printf("mount successfully! \n source: %s\n target: %s\n filesystemtype: %s\n ",
                                                source, target, filesystemtype);
/*      ret = umount (target);
        if (ret != 0){
                fprintf(stderr, "umount error happened!\n");
                return -1;
        }*/
        return 0;
}

本程序的灵感来自:
Re: NFS/RPC 2.2.13 request slot
Olaf Flebbe (O.Flebbe@science-computing.de)
Tue, 9 Nov 1999 22:15:37 +0100 (MET)

Messages sorted by: [ date ][ thread ][ subject ][ author ]
Next message: Riccardo Facchetti: "Bounced e-mails"
Previous message: nathan.zook@amd.com: "RE: Memory details not shown for 2.3.26"

--------------------------------------------------------------------------------
On Tue, 9 Nov 1999, Trond Myklebust wrote:

> >>>>> " " == Olaf Flebbe <o.flebbe@science-computing.de> writes:
>
>
> > But, the client (both plptools and amd) get an error message!
> > This shouldn't be. What can a client to against it?
>
> Which error message do they get, and what are the mount options being
> used?


from an strace of an cp to the mounted dir


write(5, "\310\223\372|7s\356!\215\245e\301o$\rG\356\36\270\230b"..., 4096) = -1 ENOSPC (No space left on device)


(The diagnostic is incorrect)



> Don't forget that if you're specifying the 'soft' mount option, then a
> major timeout will cause the error message -EIO to be sent to the
> application.


It does a hard mount...


nfs_mount_data.version = NFS_MOUNT_VERSION;
nfs_mount_data.fd = ksock;
nfs_mount_data.root = *root_fh; /* structure copy */
nfs_mount_data.flags = NFS_MOUNT_INTR | NFS_MOUNT_NOCTO;
nfs_mount_data.rsize = PBUFSIZE;
nfs_mount_data.wsize = PBUFSIZE;
nfs_mount_data.timeo = 600;
nfs_mount_data.retrans = 10; /* default 3 */
nfs_mount_data.acregmin = 3; /* default 3 seconds */
nfs_mount_data.acregmax = 60; /* default 60 seconds */
nfs_mount_data.acdirmin = 30; /* default 30 seconds */
nfs_mount_data.acdirmax = 60; /* default 60 seconds */
nfs_mount_data.addr = sain; /* structure copy */
strcpy(nfs_mount_data.hostname, PSIONHOSTNAME);


if (connect(ksock, (struct sockaddr *) &nfs_mount_data.addr, sizeof(nfs_mount_data.addr)) < 0) {
errorlog("Cannot connect to plpnfsd: %m\n");
exit(1);
}
mount_flags = MS_MGC_VAL;


if (mount("nfs", dir, "nfs", mount_flags, &nfs_mount_data)){



....
Cheers,


Olaf


---

  Dr. Olaf Flebbe                            Phone +49 (0)7071-9457-32
  science + computing gmbh                     FAX +49 (0)7071-9457-27
  Hagellocher Weg 71
  D-72070 Tuebingen  Email: o.flebbe@science-computing.de

      The amount of work to be done increases in proportion to the
                  amount of work already completed.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/


--------------------------------------------------------------------------------


Next message: Riccardo Facchetti: "Bounced e-mails"
Previous message: nathan.zook@amd.com: "RE: Memory details not shown for 2.3.26"
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP