// Mounted shows any volumes that belong to volplugin on the host, in // their native representation. They yield a *Mount. func (d *Driver) Mounted(timeout time.Duration) ([]*storage.Mount, error) { mounts := []*storage.Mount{} hostMounts, err := mountscan.GetMounts(&mountscan.GetMountsRequest{DriverName: "nfs", FsType: "nfs4"}) if err != nil { if newerr, ok := err.(*errored.Error); ok && newerr.Contains(errors.ErrDevNotFound) { return mounts, nil } return nil, err } for _, hostMount := range hostMounts { rel, err := filepath.Rel(d.mountpath, hostMount.MountPoint) if err != nil { logrus.Errorf("Invalid volume calucated from mountpoint %q with mountpath %q", hostMount.MountPoint, d.mountpath) continue } mounts = append(mounts, &storage.Mount{ DevMajor: hostMount.DeviceNumber.Major, DevMinor: hostMount.DeviceNumber.Minor, Path: hostMount.MountPoint, Volume: storage.Volume{ Name: rel, Params: map[string]string{ "mount": hostMount.MountSource, }, }, }) } return mounts, nil }
func (s *cephSuite) TestMountScan(c *C) { crudDriver, err := NewCRUDDriver() c.Assert(err, IsNil) mountDriver, err := NewMountDriver(myMountpath) c.Assert(err, IsNil) c.Assert(crudDriver.Create(mountscanDriverOpts), IsNil) c.Assert(crudDriver.Format(mountscanDriverOpts), IsNil) _, err = mountDriver.Mount(mountscanDriverOpts) c.Assert(err, IsNil) driver := &Driver{} name, err := driver.internalName(mountscanDriverOpts.Volume.Name) c.Assert(err, IsNil) hostMounts, err := mountscan.GetMounts(&mountscan.GetMountsRequest{DriverName: "ceph", KernelDriver: "rbd"}) c.Assert(err, IsNil) found := false for _, hostMount := range hostMounts { if found = (mountscanDriverOpts.FSOptions.Type == hostMount.FilesystemType && strings.Contains(hostMount.MountPoint, name)); found { break } } c.Assert(mountDriver.Unmount(mountscanDriverOpts), IsNil) c.Assert(crudDriver.Destroy(mountscanDriverOpts), IsNil) c.Assert(found, Equals, true) }
func (s *nfsSuite) TestMountScan(c *C) { resetExports(c) if err := os.RemoveAll(rootPath); !os.IsNotExist(err) { c.Assert(err, IsNil) } makeExport(c, "mountscan", "rw") mountD, err := NewMountDriver(mountPath) c.Assert(err, IsNil) do := storage.DriverOptions{ Source: nfsMount("mountscan"), Volume: storage.Volume{ Name: "test/mountscan", }, } _, err = mountD.Mount(do) c.Assert(err, IsNil) driver := &Driver{} name, err := driver.internalName(do.Volume.Name) c.Assert(err, IsNil) hostMounts, err := mountscan.GetMounts(&mountscan.GetMountsRequest{DriverName: "nfs", FsType: "nfs4"}) c.Assert(err, IsNil) found := false for _, hostMount := range hostMounts { if found = strings.Contains(hostMount.MountPoint, name); found { break } } c.Assert(mountD.Unmount(do), IsNil) c.Assert(found, Equals, true) }
// Mounted describes all the volumes currently mapped on to the host. func (c *Driver) Mounted(timeout time.Duration) ([]*storage.Mount, error) { mounts := []*storage.Mount{} hostMounts, err := mountscan.GetMounts(&mountscan.GetMountsRequest{DriverName: "ceph", KernelDriver: "rbd"}) if err != nil { if newerr, ok := err.(*errored.Error); ok && newerr.Contains(errors.ErrDevNotFound) { return mounts, nil } return nil, err } for _, mount := range hostMounts { logrus.Debugf("Host mounts: %#v", mount) } mapped, err := c.getMapped(timeout) if err != nil { return nil, err } for _, mapd := range mapped { logrus.Debugf("Mapped: %#v", mapd) } for _, hostMount := range hostMounts { for _, mappedMount := range mapped { if hostMount.MountSource == mappedMount.Device { mounts = append(mounts, &storage.Mount{ Device: hostMount.MountSource, DevMajor: hostMount.DeviceNumber.Major, DevMinor: hostMount.DeviceNumber.Minor, Path: hostMount.MountPoint, Volume: mappedMount.Volume, }) break } } } return mounts, nil }
func (s *cephSuite) TestMountSource(c *C) { totalIterations := 5 crudDriver, err := NewCRUDDriver() c.Assert(err, IsNil) mountDriver, err := NewMountDriver(myMountpath) c.Assert(err, IsNil) driver := &Driver{} volname := mountscanDriverOpts.Volume.Name for idx := 0; idx < totalIterations; idx++ { mountscanDriverOpts.Volume.Name = volname + strconv.Itoa(idx) c.Assert(crudDriver.Create(mountscanDriverOpts), IsNil) c.Assert(crudDriver.Format(mountscanDriverOpts), IsNil) _, err = mountDriver.Mount(mountscanDriverOpts) c.Assert(err, IsNil) } hostMounts, err := mountscan.GetMounts(&mountscan.GetMountsRequest{DriverName: "ceph", KernelDriver: "rbd"}) c.Assert(err, IsNil) for idx := 0; idx < totalIterations; idx++ { mountSource := "/dev/rbd" + strconv.Itoa(idx) mountscanDriverOpts.Volume.Name = volname + strconv.Itoa(idx) name, err := driver.internalName(mountscanDriverOpts.Volume.Name) c.Assert(err, IsNil) found := false for _, hostMount := range hostMounts { if found = (mountscanDriverOpts.FSOptions.Type == hostMount.FilesystemType && hostMount.MountSource == mountSource && strings.Contains(hostMount.MountPoint, name)); found { break } } c.Assert(mountDriver.Unmount(mountscanDriverOpts), IsNil) c.Assert(crudDriver.Destroy(mountscanDriverOpts), IsNil) c.Assert(found, Equals, true) } }