~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools.raring-precise.backport

« back to all changes in this revision

Viewing changes to lib/file/fileIOPosix.c

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-01-23 16:09:45 UTC
  • mfrom: (1.4.6) (2.4.26 sid)
  • Revision ID: package-import@ubuntu.com-20120123160945-b6s0r1vkcovucpf3
Tags: 2011.12.20-562307-0ubuntu1
* Merge latest upstream git tag. Fixes building on Precise
  (LP: #898289, LP: #905612)

* Items merged from Debian unstable:
  - debian/control:
    + open-vm-tools recommends open-vm-dkms. (LP: #598933)
    + open-vm-tools now suggests open-vm-toolbox. (LP: #604998)
  (From 2011.08.21-471295-1 release)
  - Updating maintainer and uploaders fields.
  - Removing vcs fields.
  - Removing references to Daniel's old email address.
  - Updating years in copyright file.
  - Updating to standards version 3.9.2.
  - Updating to debhelper version 8.
  - Switching to source format 3.0 (quilt).
  - Removing manual chrpath setting.
  - Removing exclusion from plugins from debhelper shlibs.
  - Rediffing kvers.patch.
  (From 2011.09.23-491607-1 release)
  - Marking binary architecture-dependend packages as linux and kfreebsd
  only.
  - Removing liburiparser-dev from build-depends as upstream dropped
  unity support.
  - Building with libproc-dev on amd64 again.
  - Dropping disabling of dnet support.
  (From 2011.09.23-491607-2 release)
  - Adding doxygen to build-depends for api documentation.
  - Adding libcunit1-dev to build-depends for test suites.
  - Minimizing rules file.
  - Adding open-vm-tools-dev package, containing only the api
    documentation for now.
  (From 2011.09.23-491607-3 release)
  - Sorting overrides in rules alphabetically.
  - Compacting copyright file.
  - Adding udev rule to set timeout for vmware scsi devices
  (From 2011.12.20-562307-1 release)
  - Adding patch to correct typo in upstreams dkms configuration

* Remaining Changes:
  - Remove Stable part of version numbering.
  - debian folder:
    + Re-added open-vm-dkms.postinst & open-vm-dkms.prerm.
      * Allows dkms modules to compile upon installation.
  - debian/control:
    + Re-add open-vm-source and make into a transitional package
      for open-vm-toolbox.
    + Return dependancies that were moved to open-vm-tools back to
      open-vm-toolbox.
  - debian/rules and debian/open-vm-toolbox.lintian-overrides:
    + Make vmware-user-suid-wrapper suid-root
  - debian/rules:
    + Added CFLAGS field with -Wno-deprecated-declarations
      * Will suppress issues with glib 2.31 or later.
    + Add line to copy vmware-xdg-detect-de into place.
    + Install vmware-user.desktop through toolbox package.
  - debian/open-vm-tools.init:
    + Re-add 'modprobe [-r] vmblock'.
    + Add 'modprobe [-r] vmxnet'.
      * Incase it's not loaded during boot.
    + Remove and re-add pcnet32 module
      * Will be done before (remove) and after (readd) vmxnet module
        is added.
      * If vmxnet doesn't exist (aka modules fail to build), pcnet32 can be
        still used for network connectivity.
      * Workaround until a better fix can be done.
  - Re-add gnome-session to debian/local/xautostart.conf
  - Manpages removed (from debian/manpages):
    + vmmemctl.9
    + vmxnet3.9
    + Remove references to manpages that have been removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
 
25
25
 
26
 
#if !defined(VMX86_TOOLS) && !defined(__APPLE__)
 
26
#if !defined(VMX86_TOOLS) && !defined(__APPLE__) && !defined(sun)
27
27
#define FILEIO_SUPPORT_ODIRECT
28
28
#define _GNU_SOURCE
29
29
#endif
193
193
   unsigned        numBusy;
194
194
} AlignedPool;
195
195
 
 
196
static Atomic_Ptr alignedPoolLockStorage;
196
197
static AlignedPool alignedPool;
197
198
#endif
198
199
 
811
812
   ASSERT(file->lockToken == NULL);
812
813
   ASSERT_ON_COMPILE(FILEIO_ERROR_LAST < 16); /* See comment in fileIO.h */
813
814
 
 
815
   FileIOResolveLockBits(&access);
 
816
   ASSERT((access & FILEIO_OPEN_LOCKED) == 0 &&
 
817
          (access & FILEIO_OPEN_EXCLUSIVE_LOCK) == 0);
 
818
   /* Only ESX implements mandatory locking */
 
819
   ASSERT((access & FILEIO_OPEN_LOCK_MANDATORY) == 0 ||
 
820
          File_SupportsMandatoryLock(pathName));
 
821
 
814
822
#if defined(__APPLE__)
815
823
   if (access & FILEIO_OPEN_EXCLUSIVE_LOCK_MACOS) {
816
824
      flags |= O_EXLOCK;
817
825
   }
818
 
#elif !defined(__FreeBSD__) && !defined(sun)
 
826
#elif defined(__linux__)
 
827
   if (((access & (FILEIO_OPEN_LOCK_MANDATORY |
 
828
                   FILEIO_OPEN_MULTIWRITER_LOCK)) != 0) &&
 
829
       HostType_OSIsVMK()) {
 
830
      /* These flags are only supported on vmkernel */
 
831
      if ((access & FILEIO_OPEN_MULTIWRITER_LOCK) != 0) {
 
832
         flags |= O_MULTIWRITER_LOCK;
 
833
      } else if ((access & FILEIO_OPEN_LOCK_MANDATORY) != 0) {
 
834
         flags |= O_EXCLUSIVE_LOCK;
 
835
      }
 
836
   }
 
837
#endif
 
838
 
819
839
   /*
820
 
    * If FILEIO_OPEN_EXCLUSIVE_LOCK or FILEIO_OPEN_MULTIWRITER_LOCK or
821
 
    * (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_LOCKED) are passed, and we are
822
 
    * on VMFS, then pass in special flags to get exclusive, multiwriter, or
823
 
    * cross-host read-only mode.  The first if statement is to avoid calling
824
 
    * HostType_OSIsVMK() unless really necessary.
825
 
    *
826
 
    * If the above conditions are met FILEIO_OPEN_LOCKED, is filtered out --
827
 
    * vmfs will be handling the locking, so there is no need to create
828
 
    * lockfiles.
 
840
    * Locking implementation note: this can be recursive. On ESX:
 
841
    * FileIOCreateRetry("foo", ...ADVISORY...)
 
842
    *  -> FileIO_Lock("foo", ...ADVISORY...)
 
843
    *     -> FileLock_Lock("foo", ...ADVISORY...)
 
844
    *        -> FileIOCreateRetry("foo.lck", ...MANDATORY...)
 
845
    *           -> open("foo.lck", ...O_EXCLUSIVE_LOCK...)
829
846
    */
830
 
   if ((access & (FILEIO_OPEN_EXCLUSIVE_LOCK |
831
 
                  FILEIO_OPEN_MULTIWRITER_LOCK)) != 0 ||
832
 
       (access & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE |
833
 
                  FILEIO_OPEN_LOCKED)) ==
834
 
       (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_LOCKED)) {
835
 
      if (HostType_OSIsVMK()) {
836
 
         access &= ~FILEIO_OPEN_LOCKED;
837
 
 
838
 
         if ((access & FILEIO_OPEN_MULTIWRITER_LOCK) != 0) {
839
 
            flags |= O_MULTIWRITER_LOCK;
840
 
         } else {
841
 
            flags |= O_EXCLUSIVE_LOCK;
842
 
         }
843
 
      }
844
 
   }
845
 
#endif
846
847
 
847
848
   FileIO_Init(file, pathName);
848
 
   ret = FileIO_Lock(file, access);
849
 
   if (!FileIO_IsSuccess(ret)) {
850
 
      goto error;
 
849
   /* Mandatory file locks are only available at open() itself */
 
850
   if ((access & FILEIO_OPEN_LOCK_ADVISORY) != 0) {
 
851
      ret = FileIO_Lock(file, access);
 
852
      if (!FileIO_IsSuccess(ret)) {
 
853
         goto error;
 
854
      }
851
855
   }
852
856
 
853
857
   if ((access & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE)) ==
1877
1881
#endif /* defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) ||
1878
1882
          defined(sun) */
1879
1883
 
1880
 
/*
1881
 
 *----------------------------------------------------------------------
1882
 
 *
1883
 
 * FileIO_GetSize --
1884
 
 *
1885
 
 *      Get size of file.
1886
 
 *
1887
 
 * Results:
1888
 
 *      Size of file or -1.
1889
 
 *
1890
 
 * Side effects:
1891
 
 *      None
1892
 
 *
1893
 
 *----------------------------------------------------------------------
1894
 
 */
1895
 
 
1896
 
int64
1897
 
FileIO_GetSize(const FileIODescriptor *fd)  // IN:
1898
 
{
1899
 
   struct stat statBuf;
1900
 
 
1901
 
   ASSERT(fd);
1902
 
 
1903
 
   return (fstat(fd->posix, &statBuf) == -1) ? -1 : statBuf.st_size;
1904
 
}
1905
 
 
1906
1884
 
1907
1885
/*
1908
1886
 *----------------------------------------------------------------------
1909
1887
 *
1910
1888
 * FileIO_GetAllocSize --
1911
1889
 *
1912
 
 *      Get allocated size of file.
 
1890
 *      Get logcial and alloced size of a file.
1913
1891
 *
1914
1892
 * Results:
1915
 
 *      Size of file or -1.
 
1893
 *      FileIOResult.
1916
1894
 *
1917
1895
 * Side effects:
1918
1896
 *      None
1920
1898
 *----------------------------------------------------------------------
1921
1899
 */
1922
1900
 
1923
 
int64
1924
 
FileIO_GetAllocSize(const FileIODescriptor *fd)  // IN
 
1901
FileIOResult
 
1902
FileIO_GetAllocSize(const FileIODescriptor *fd,     // IN:
 
1903
                    uint64 *logicalBytes,           // OUT:
 
1904
                    uint64 *allocedBytes)           // OUT:
1925
1905
{
1926
 
   struct stat s;
 
1906
   struct stat statBuf;
1927
1907
 
1928
1908
   ASSERT(fd);
1929
1909
 
1930
 
   /*
1931
 
    * If you don't like the magic number 512, yell at the people
1932
 
    * who wrote sys/stat.h and tell them to add a #define for it.
1933
 
    */
1934
 
 
1935
 
   return (fstat(fd->posix, &s) == -1) ? -1 : s.st_blocks * 512;
 
1910
   if (fstat(fd->posix, &statBuf) == -1) {
 
1911
      return FileIOErrno2Result(errno);
 
1912
   }
 
1913
 
 
1914
   if (logicalBytes) {
 
1915
      *logicalBytes = statBuf.st_size;
 
1916
   }
 
1917
 
 
1918
   if (allocedBytes) {
 
1919
     /*
 
1920
      * If you don't like the magic number 512, yell at the people
 
1921
      * who wrote sys/stat.h and tell them to add a #define for it.
 
1922
      */
 
1923
      *allocedBytes = statBuf.st_blocks * 512;
 
1924
   }
 
1925
 
 
1926
   return FILEIO_SUCCESS;
1936
1927
}
1937
1928
 
1938
1929
 
1959
1950
{
1960
1951
 
1961
1952
#if defined(__APPLE__) || defined(__linux__)
 
1953
   FileIOResult fret;
1962
1954
   uint64 curSize;
1963
1955
   uint64 preallocLen;
1964
1956
#if defined(__APPLE__)
1965
1957
   fstore_t prealloc;
1966
1958
#endif
1967
1959
 
1968
 
   curSize = FileIO_GetAllocSize(fd);
 
1960
   fret = FileIO_GetAllocSize(fd, NULL, &curSize);
 
1961
   if (!FileIO_IsSuccess(fret)) {
 
1962
      return FALSE;
 
1963
   }
 
1964
 
1969
1965
   if (curSize > size) {
1970
1966
      errno = EINVAL;
1971
1967
 
1997
1993
/*
1998
1994
 *----------------------------------------------------------------------
1999
1995
 *
2000
 
 * FileIO_GetSizeByPath --
 
1996
 * FileIO_GetAllocSizeByPath --
2001
1997
 *
2002
 
 *      Get size of a file specified by path. 
 
1998
 *      Get the logcial and alloced size of a file specified by path.
2003
1999
 *
2004
2000
 * Results:
2005
 
 *      Size of file or -1.
 
2001
 *      FileIOResult.
2006
2002
 *
2007
2003
 * Side effects:
2008
2004
 *      errno is set on error
2010
2006
 *----------------------------------------------------------------------
2011
2007
 */
2012
2008
 
2013
 
int64
2014
 
FileIO_GetSizeByPath(ConstUnicode pathName)  // IN:
 
2009
FileIOResult
 
2010
FileIO_GetAllocSizeByPath(ConstUnicode pathName,    // IN:
 
2011
                          uint64 *logicalBytes,     // OUT:
 
2012
                          uint64 *allocedBytes)     // OUT:
2015
2013
{
2016
 
   int err;
2017
 
   struct stat statbuf;
2018
 
 
2019
 
   err = Posix_Stat(pathName, &statbuf);
2020
 
 
2021
 
   return (err == 0) ? statbuf.st_size : -1;
 
2014
   struct stat statBuf;
 
2015
 
 
2016
   if (Posix_Stat(pathName, &statBuf) == -1) {
 
2017
      return FileIOErrno2Result(errno);
 
2018
   }
 
2019
 
 
2020
   if (logicalBytes) {
 
2021
      *logicalBytes = statBuf.st_size;
 
2022
   }
 
2023
 
 
2024
   if (allocedBytes) {
 
2025
#if __linux__ && defined(N_PLAT_NLM)
 
2026
      /* Netware doesn't have st_blocks.  Just fall back to GetSize. */
 
2027
      *allocedBytes = statBuf.st_size;
 
2028
#else
 
2029
     /*
 
2030
      * If you don't like the magic number 512, yell at the people
 
2031
      * who wrote sys/stat.h and tell them to add a #define for it.
 
2032
      */
 
2033
      *allocedBytes = statBuf.st_blocks * 512;
 
2034
#endif
 
2035
   }
 
2036
 
 
2037
   return FILEIO_SUCCESS;
2022
2038
}
2023
2039
 
2024
2040
 
2506
2522
 *
2507
2523
 * FileIOAligned_PoolInit --
2508
2524
 *
2509
 
 *      Initialize alignedPool.  Must be called before FileIOAligned_PoolMalloc.
2510
 
 *      This is not thread-safe and must be protected from multiple entry.
 
2525
 *      Initialize alignedPool. Must be called before FileIOAligned_PoolMalloc.
2511
2526
 *
2512
2527
 * Result:
2513
2528
 *      None.
2521
2536
void
2522
2537
FileIOAligned_PoolInit(void)
2523
2538
{
2524
 
   ASSERT(!alignedPool.lock);
2525
 
   alignedPool.lock = MXUser_CreateExclLock("alignedPoolLock", RANK_LEAF);
 
2539
   alignedPool.lock = MXUser_CreateSingletonExclLock(&alignedPoolLockStorage,
 
2540
                                                     "alignedPoolLock",
 
2541
                                                     RANK_LEAF);
 
2542
   ASSERT_NOT_IMPLEMENTED(alignedPool.lock);
2526
2543
}
2527
2544
 
2528
2545