From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:34:19 +0000 (-0700) Subject: HGFS: Clean up and improve Linux client logging X-Git-Tag: 2013.09.16-1328054~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8fe065a8fb1e13ebb2ed980b8460d2d6c4c2ce9;p=thirdparty%2Fopen-vm-tools.git HGFS: Clean up and improve Linux client logging Enhancing existing log statements to be useful, moving open flags utility function into the utility file as in the future it should be used by open and create entry points. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/modules/linux/vmhgfs/file.c b/open-vm-tools/modules/linux/vmhgfs/file.c index 0b69be1a7..3ba58e27e 100644 --- a/open-vm-tools/modules/linux/vmhgfs/file.c +++ b/open-vm-tools/modules/linux/vmhgfs/file.c @@ -56,7 +56,6 @@ static int HgfsUnpackOpenReply(HgfsReq *req, HgfsOp opUsed, HgfsHandle *file, HgfsLockType *lock); -static int HgfsGetOpenFlags(uint32 flags); /* HGFS file operations for files. */ static int HgfsOpen(struct inode *inode, @@ -433,94 +432,6 @@ HgfsUnpackOpenReply(HgfsReq *req, // IN: Packet with reply inside } -/* - *---------------------------------------------------------------------- - * - * HgfsGetOpenFlags -- - * - * Based on the flags requested by the process making the open() - * syscall, determine which flags to send to the server to open the - * file. - * - * Results: - * Returns the correct HgfsOpenFlags enumeration to send to the - * server, or -1 on failure. - * - * Side effects: - * None - * - *---------------------------------------------------------------------- - */ - -static int -HgfsGetOpenFlags(uint32 flags) // IN: Open flags -{ - uint32 mask = O_CREAT | O_TRUNC | O_EXCL; - int result = -1; - - LOG(6, (KERN_DEBUG "VMware hgfs: HgfsGetOpenFlags: entered\n")); - - /* - * Mask the flags to only look at O_CREAT, O_EXCL, and O_TRUNC. - */ - - flags &= mask; - - /* O_EXCL has no meaning if O_CREAT is not set. */ - if (!(flags & O_CREAT)) { - flags &= ~O_EXCL; - } - - /* Pick the right HgfsOpenFlags. */ - switch (flags) { - - case 0: - /* Regular open; fails if file nonexistant. */ - result = HGFS_OPEN; - break; - - case O_CREAT: - /* Create file; if it exists already just open it. */ - result = HGFS_OPEN_CREATE; - break; - - case O_TRUNC: - /* Truncate existing file; fails if nonexistant. */ - result = HGFS_OPEN_EMPTY; - break; - - case (O_CREAT | O_EXCL): - /* Create file; fail if it exists already. */ - result = HGFS_OPEN_CREATE_SAFE; - break; - - case (O_CREAT | O_TRUNC): - /* Create file; if it exists already, truncate it. */ - result = HGFS_OPEN_CREATE_EMPTY; - break; - - default: - /* - * This can only happen if all three flags are set, which - * conceptually makes no sense because O_EXCL and O_TRUNC are - * mutually exclusive if O_CREAT is set. - * - * However, the open(2) man page doesn't say you can't set all - * three flags, and certain apps (*cough* Nautilus *cough*) do - * so. To be friendly to those apps, we just silenty drop the - * O_TRUNC flag on the assumption that it's safer to honor - * O_EXCL. - */ - LOG(4, (KERN_DEBUG "VMware hgfs: HgfsGetOpenFlags: invalid open " - "flags %o. Ignoring the O_TRUNC flag.\n", flags)); - result = HGFS_OPEN_CREATE_SAFE; - break; - } - - return result; -} - - /* * HGFS file operations for files. */ diff --git a/open-vm-tools/modules/linux/vmhgfs/fsutil.c b/open-vm-tools/modules/linux/vmhgfs/fsutil.c index 4ce77ab7c..f298b8d7f 100644 --- a/open-vm-tools/modules/linux/vmhgfs/fsutil.c +++ b/open-vm-tools/modules/linux/vmhgfs/fsutil.c @@ -1313,7 +1313,7 @@ HgfsGetOpenMode(uint32 flags) // IN: Open flags uint32 mask = O_RDONLY|O_WRONLY|O_RDWR; int result = -1; - LOG(6, (KERN_DEBUG "VMware hgfs: HgfsGetOpenMode: entered\n")); + LOG(6, (KERN_DEBUG "VMware hgfs: %s: (%u) entered\n", __func__, flags)); /* @@ -1347,6 +1347,96 @@ HgfsGetOpenMode(uint32 flags) // IN: Open flags break; } + LOG(6, (KERN_DEBUG "VMware hgfs: %s: return %d\n", __func__, result)); + return result; +} + + +/* + *---------------------------------------------------------------------- + * + * HgfsGetOpenFlags -- + * + * Based on the flags requested by the process making the open() + * syscall, determine which flags to send to the server to open the + * file. + * + * Results: + * Returns the correct HgfsOpenFlags enumeration to send to the + * server, or -1 on failure. + * + * Side effects: + * None + * + *---------------------------------------------------------------------- + */ + +int +HgfsGetOpenFlags(uint32 flags) // IN: Open flags +{ + uint32 mask = O_CREAT | O_TRUNC | O_EXCL; + int result = -1; + + LOG(6, (KERN_DEBUG "VMware hgfs: %s: (%u) entered\n", __func__, flags)); + + /* + * Mask the flags to only look at O_CREAT, O_EXCL, and O_TRUNC. + */ + + flags &= mask; + + /* O_EXCL has no meaning if O_CREAT is not set. */ + if (!(flags & O_CREAT)) { + flags &= ~O_EXCL; + } + + /* Pick the right HgfsOpenFlags. */ + switch (flags) { + + case 0: + /* Regular open; fails if file nonexistant. */ + result = HGFS_OPEN; + break; + + case O_CREAT: + /* Create file; if it exists already just open it. */ + result = HGFS_OPEN_CREATE; + break; + + case O_TRUNC: + /* Truncate existing file; fails if nonexistant. */ + result = HGFS_OPEN_EMPTY; + break; + + case (O_CREAT | O_EXCL): + /* Create file; fail if it exists already. */ + result = HGFS_OPEN_CREATE_SAFE; + break; + + case (O_CREAT | O_TRUNC): + /* Create file; if it exists already, truncate it. */ + result = HGFS_OPEN_CREATE_EMPTY; + break; + + default: + /* + * This can only happen if all three flags are set, which + * conceptually makes no sense because O_EXCL and O_TRUNC are + * mutually exclusive if O_CREAT is set. + * + * However, the open(2) man page doesn't say you can't set all + * three flags, and certain apps (*cough* Nautilus *cough*) do + * so. To be friendly to those apps, we just silenty drop the + * O_TRUNC flag on the assumption that it's safer to honor + * O_EXCL. + */ + LOG(4, (KERN_DEBUG "VMware hgfs: HgfsGetOpenFlags: invalid open " + "flags %o. Ignoring the O_TRUNC flag.\n", flags)); + result = HGFS_OPEN_CREATE_SAFE; + break; + } + + LOG(6, (KERN_DEBUG "VMware hgfs: %s: return %d\n", __func__, result)); return result; } diff --git a/open-vm-tools/modules/linux/vmhgfs/fsutil.h b/open-vm-tools/modules/linux/vmhgfs/fsutil.h index da5c5a119..f332fb6d8 100644 --- a/open-vm-tools/modules/linux/vmhgfs/fsutil.h +++ b/open-vm-tools/modules/linux/vmhgfs/fsutil.h @@ -82,6 +82,7 @@ int HgfsBuildPath(char *buffer, void HgfsDentryAgeReset(struct dentry *dentry); void HgfsDentryAgeForce(struct dentry *dentry); int HgfsGetOpenMode(uint32 flags); +int HgfsGetOpenFlags(uint32 flags); int HgfsCreateFileInfo(struct file *file, HgfsHandle handle); void HgfsReleaseFileInfo(struct file *file);