public PosixJournalWriter(StorageEnvironmentOptions options, string filename, long journalSize)
        {
            _options  = options;
            _filename = filename;


            _fd = Syscall.open(filename, OpenFlags.O_WRONLY | OpenFlags.O_DSYNC | OpenFlags.O_DIRECT | OpenFlags.O_CREAT,
                               FilePermissions.S_IWUSR | FilePermissions.S_IRUSR);

            if (_fd == -1)
            {
                var err = Marshal.GetLastWin32Error();
                PosixHelper.ThrowLastError(err);
            }

            var result = Syscall.posix_fallocate(_fd, 0, (ulong)journalSize);

            if (result != 0)
            {
                PosixHelper.ThrowLastError(result);
            }

            if (PosixHelper.CheckSyncDirectoryAllowed(_filename) && PosixHelper.SyncDirectory(filename) == -1)
            {
                var err = Marshal.GetLastWin32Error();
                PosixHelper.ThrowLastError(err);
            }

            NumberOfAllocatedPages = (int)(journalSize / _options.PageSize);
        }
Exemplo n.º 2
0
        public static void AllocateFileSpace(int fd, ulong size, string file)
        {
            int result;
            int retries = 1024;

            while (true)
            {
                result = Syscall.posix_fallocate(fd, IntPtr.Zero, (UIntPtr)size);
                if (result != (int)Errno.EINTR)
                {
                    break;
                }
                if (retries-- > 0)
                {
                    throw new IOException(
                              "Tried too many times to call posix_fallocate, but always got EINTR, cannot retry again");
                }
            }
            if (result == (int)Errno.ENOSPC)
            {
                foreach (var drive in DriveInfo.GetDrives())
                {
                    if (file.StartsWith(drive.RootDirectory.Name))
                    {
                        throw new DiskFullException(drive, file, (long)size);
                    }
                }
                // shouldn't happen, and we can throw normally here
            }
            if (result != 0)
            {
                ThrowLastError(result, $"posix_fallocate(\"{file}\", {size})");
            }
        }
Exemplo n.º 3
0
        public PosixJournalWriter(string filename, long journalSize)
        {
            _filename = filename;

            _fd = Syscall.open(filename, OpenFlags.O_WRONLY | OpenFlags.O_SYNC | OpenFlags.O_CREAT,
                               FilePermissions.ALLPERMS);
            if (_fd == -1)
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }

            var result = Syscall.posix_fallocate(_fd, 0, (ulong)journalSize);

            if (result != 0)
            {
                PosixHelper.ThrowLastError(result);
            }

            NumberOfAllocatedPages = journalSize / AbstractPager.PageSize;
        }
Exemplo n.º 4
0
        public static void AllocateFileSpace(int fd, ulong size)
        {
            int result;
            int retries = 1024;

            while (true)
            {
                result = Syscall.posix_fallocate(fd, 0, size);
                if (result != (int)Errno.EINTR)
                {
                    break;
                }
                if (retries-- > 0)
                {
                    throw new IOException("Tried too many times to call posix_fallocate, but always got EINTR, cannot retry again");
                }
            }
            if (result != 0)
            {
                ThrowLastError(result);
            }
        }
Exemplo n.º 5
0
        public PosixJournalWriter(StorageEnvironmentOptions options, string filename, long journalSize)
        {
            _options  = options;
            _filename = filename;
            _maxNumberOfPagesPerSingleWrite = int.MaxValue / _options.PageSize;

            _fd = Syscall.open(filename, OpenFlags.O_WRONLY | options.PosixOpenFlags | OpenFlags.O_CREAT,
                               FilePermissions.S_IWUSR | FilePermissions.S_IRUSR);

            if (_fd == -1)
            {
                var err = Marshal.GetLastWin32Error();
                PosixHelper.ThrowLastError(err, "when opening " + filename);
            }

            int result;

            if ((options.SafePosixOpenFlags & PerPlatformValues.OpenFlags.O_DIRECT) == 0)
            {
                // fallocate doesn't supported, we'll use lseek instead
                result = Syscall.AllocateUsingLseek(_fd, journalSize);
            }
            else
            {
                result = Syscall.posix_fallocate(_fd, IntPtr.Zero, (UIntPtr)journalSize);
            }
            if (result != 0)
            {
                PosixHelper.ThrowLastError(result, "when allocating " + filename);
            }

            if (PosixHelper.CheckSyncDirectoryAllowed(_filename) && PosixHelper.SyncDirectory(filename) == -1)
            {
                var err = Marshal.GetLastWin32Error();
                PosixHelper.ThrowLastError(err, "when syncing dir for on " + filename);
            }

            NumberOfAllocatedPages = (int)(journalSize / _options.PageSize);
        }