文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>NFS mount flags error!

NFS mount flags error!

时间:2006-11-09  来源:hoog

需要写一个用来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 ([email protected])
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: [email protected]: "RE: Memory details not shown for 2.3.26"

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

> >>>>> " " == Olaf Flebbe <[email protected]> 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: [email protected]

      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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/

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

Next message: Riccardo Facchetti: "Bounced e-mails"
Previous message: [email protected]: "RE: Memory details not shown for 2.3.26"
相关阅读 更多 +
排行榜 更多 +
锤击

锤击

休闲益智 下载
穿越时空的猫里奥

穿越时空的猫里奥

动作格斗 下载
麻匪动态壁纸

麻匪动态壁纸

主题美化 下载