[OpenAFS-devel] openafs libuafs for QT File apis
Troy Benjegerdes
hozer@hozed.org
Tue, 29 Dec 2015 21:52:08 -0600
This is a MIME-formatted message. If you see this text it means that your
E-mail software does not support MIME-formatted messages.
--=_nl.grid.coop-22360-1451447528-0001-2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
So I got this crazy idea that I wanted to make
QT apps on android & ios that could access AFS.
Attached is a patch which seems to 'sort of' work
in a few cases, but mostly not. The fact that
it does actually work in a few cases seems to
make it worth the effort to fix the rest.
Any thoughts?
Also what issues does anyone see with linking
libuafs with the GPL QT libraries.. I know we
had a lot of friction with the linux community,
but this is sort of the other way around.
And where are we with working open code for
ipv6? I think half of the "don't work" cases
above are related to the goofy IPv4 network
topology I have my AFS servers on.
--=_nl.grid.coop-22360-1451447528-0001-2
Content-Type: text/x-diff; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="qt-afshacks.diff"
diff -r 6bdfaa31aa37 mkspecs/common/linux.conf
--- a/mkspecs/common/linux.conf Sat Dec 26 20:42:09 2015 -0600
+++ b/mkspecs/common/linux.conf Tue Dec 29 18:40:22 2015 -0600
@@ -53,3 +53,4 @@
QMAKE_STRIPFLAGS_LIB += --strip-unneeded
include(unix.conf)
+include(uafs.conf)
diff -r 6bdfaa31aa37 mkspecs/common/posix/qplatformdefs.h
--- a/mkspecs/common/posix/qplatformdefs.h Sat Dec 26 20:42:09 2015 -0600
+++ b/mkspecs/common/posix/qplatformdefs.h Tue Dec 29 18:40:22 2015 -0600
@@ -41,31 +41,33 @@
# include <sys/socket.h>
#endif
#include <sys/stat.h>
+#include "/scratch/fs/include/afs/sysincludes.h"
+#include "/scratch/fs/include/afs/afs_usrops.h"
#if defined(QT_USE_XOPEN_LFS_EXTENSIONS) && defined(QT_LARGEFILE_SUPPORT)
-#define QT_STATBUF struct stat64
+#define QT_STATBUF struct stat
#define QT_FPOS_T fpos64_t
#define QT_OFF_T off64_t
-#define QT_STAT ::stat64
-#define QT_LSTAT ::lstat64
-#define QT_TRUNCATE ::truncate64
+#define QT_STAT ::uafs_stat
+#define QT_LSTAT ::uafs_lstat
+#define QT_TRUNCATE ::uafs_truncate
// File I/O
-#define QT_OPEN ::open64
-#define QT_LSEEK ::lseek64
-#define QT_FSTAT ::fstat64
-#define QT_FTRUNCATE ::ftruncate64
+#define QT_OPEN ::uafs_open
+#define QT_LSEEK ::uafs_lseek
+#define QT_FSTAT ::uafs_fstat
+#define QT_FTRUNCATE ::uafs_ftruncate
// Standard C89
-#define QT_FOPEN ::fopen64
-#define QT_FSEEK ::fseeko64
-#define QT_FTELL ::ftello64
-#define QT_FGETPOS ::fgetpos64
-#define QT_FSETPOS ::fsetpos64
+#define QT_FOPEN ::fopen
+#define QT_FSEEK ::fseeko
+#define QT_FTELL ::ftello
+#define QT_FGETPOS ::fgetpos
+#define QT_FSETPOS ::fsetpos
-#define QT_MMAP ::mmap64
+#define QT_MMAP ::uafs_mmap
#else // !defined(QT_USE_XOPEN_LFS_EXTENSIONS) || !defined(QT_LARGEFILE_SUPPORT)
@@ -73,15 +75,15 @@
#define QT_STATBUF struct stat
-#define QT_STAT ::stat
-#define QT_LSTAT ::lstat
-#define QT_TRUNCATE ::truncate
+#define QT_STAT ::uafs_stat
+#define QT_LSTAT ::uafs_lstat
+#define QT_TRUNCATE ::uafs_truncate
// File I/O
-#define QT_OPEN ::open
-#define QT_LSEEK ::lseek
-#define QT_FSTAT ::fstat
-#define QT_FTRUNCATE ::ftruncate
+#define QT_OPEN ::uafs_open
+#define QT_LSEEK ::uafs_lseek
+#define QT_FSTAT ::uafs_fstat
+#define QT_FTRUNCATE ::uafs_ftruncate
// Posix extensions to C89
#if !defined(QT_USE_XOPEN_LFS_EXTENSIONS) && !defined(QT_NO_USE_FSEEKO)
@@ -91,11 +93,11 @@
#define QT_OFF_T off_t
-#define QT_FSEEK ::fseeko
-#define QT_FTELL ::ftello
+#define QT_FSEEK ::uafs_fseeko
+#define QT_FTELL ::uafs_ftello
#endif
-#define QT_MMAP ::mmap
+#define QT_MMAP ::uafs_mmap
#endif // !defined (QT_USE_XOPEN_LFS_EXTENSIONS) || !defined(QT_LARGEFILE_SUPPORT)
@@ -104,16 +106,17 @@
#define QT_STAT_DIR S_IFDIR
#define QT_STAT_LNK S_IFLNK
-#define QT_ACCESS ::access
-#define QT_GETCWD ::getcwd
-#define QT_CHDIR ::chdir
-#define QT_MKDIR ::mkdir
-#define QT_RMDIR ::rmdir
+#define QT_ACCESS ::uafs_access
+#define QT_GETCWD ::uafs_getcwd
+#define QT_CHDIR ::uafs_chdir
+#define QT_MKDIR ::uafs_mkdir
+#define QT_RMDIR ::uafs_rmdir
// File I/O
-#define QT_CLOSE ::close
-#define QT_READ ::read
-#define QT_WRITE ::write
+#define QT_CLOSE ::uafs_close
+//#define QT_READ (int (*)(int, void*, int))::uafs_read
+#define QT_READ ::uafs_read
+#define QT_WRITE ::uafs_write
#define QT_OPEN_LARGEFILE O_LARGEFILE
#define QT_OPEN_RDONLY O_RDONLY
@@ -127,27 +130,27 @@
#define QT_FILENO fileno
// Directory iteration
-#define QT_DIR DIR
+#define QT_DIR usr_DIR
-#define QT_OPENDIR ::opendir
-#define QT_CLOSEDIR ::closedir
+#define QT_OPENDIR ::uafs_opendir
+#define QT_CLOSEDIR ::uafs_closedir
#if defined(QT_LARGEFILE_SUPPORT) \
&& defined(QT_USE_XOPEN_LFS_EXTENSIONS) \
&& !defined(QT_NO_READDIR64)
-#define QT_DIRENT struct dirent64
-#define QT_READDIR ::readdir64
-#define QT_READDIR_R ::readdir64_r
+#define QT_DIRENT struct usr_dirent
+#define QT_READDIR ::uafs_readdir
+#define QT_READDIR_R ::uafs_readdir_r
#else
#define QT_DIRENT struct dirent
-#define QT_READDIR ::readdir
-#define QT_READDIR_R ::readdir_r
+#define QT_READDIR ::uafs_readdir
+#define QT_READDIR_R ::uafs_readdir_r
#endif
#define QT_SOCKLEN_T socklen_t
-#define QT_SOCKET_CONNECT ::connect
-#define QT_SOCKET_BIND ::bind
+#define QT_SOCKET_CONNECT ::uafs_connect
+#define QT_SOCKET_BIND ::uafs_bind
#define QT_SIGNAL_RETTYPE void
#define QT_SIGNAL_ARGS int
diff -r 6bdfaa31aa37 src/corelib/io/qfile.cpp
--- a/src/corelib/io/qfile.cpp Sat Dec 26 20:42:09 2015 -0600
+++ b/src/corelib/io/qfile.cpp Tue Dec 29 18:40:22 2015 -0600
@@ -951,13 +951,13 @@
}
if (d->openExternalFile(mode, fh, handleFlags)) {
QIODevice::open(mode);
- if (!(mode & Append) && !isSequential()) {
+ /* if (!(mode & Append) && !isSequential()) {
qint64 pos = (qint64)QT_FTELL(fh);
if (pos != -1) {
// Skip redundant checks in QFileDevice::seek().
QIODevice::seek(pos);
}
- }
+ }*/
return true;
}
return false;
diff -r 6bdfaa31aa37 src/corelib/io/qfiledevice.cpp
--- a/src/corelib/io/qfiledevice.cpp Sat Dec 26 20:42:09 2015 -0600
+++ b/src/corelib/io/qfiledevice.cpp Tue Dec 29 18:40:22 2015 -0600
@@ -44,15 +44,32 @@
static const int QFILE_WRITEBUFFER_SIZE = 16384;
+static int QFILE_uafs_runcount = 0;
+
QFileDevicePrivate::QFileDevicePrivate()
: fileEngine(0),
writeBuffer(QFILE_WRITEBUFFER_SIZE), cachedSize(0),
error(QFile::NoError), lastWasWrite(false)
{
+ if (QFILE_uafs_runcount++ < 1){
+ qWarning("Starting uafs");
+ char *uafs_argv[] = {"my_prog", "-afsdb", "-dynroot", "-fakestat-all", NULL};
+ int code;
+ code = uafs_Setup("/afs");
+ assert(!code);
+ code = uafs_ParseArgs(3, uafs_argv);
+ assert(!code);
+ code = uafs_Run();
+ assert(!code);
+ }
}
QFileDevicePrivate::~QFileDevicePrivate()
{
+ qWarning("~QFileDevicePrivate: uafs_runcount %d", QFILE_uafs_runcount);
+ if(--QFILE_uafs_runcount < 1){
+ uafs_Shutdown();
+ }
delete fileEngine;
fileEngine = 0;
}
diff -r 6bdfaa31aa37 src/corelib/io/qfilesystemengine.cpp
--- a/src/corelib/io/qfilesystemengine.cpp Sat Dec 26 20:42:09 2015 -0600
+++ b/src/corelib/io/qfilesystemengine.cpp Tue Dec 29 18:40:22 2015 -0600
@@ -322,7 +322,7 @@
}
}
}
-#elif defined(_DIRENT_HAVE_D_TYPE) || defined(Q_OS_BSD4)
+#elif 0 // afs hack .. no d_type .. defined(_DIRENT_HAVE_D_TYPE) || defined(Q_OS_BSD4)
// BSD4 includes OS X and iOS
// ### This will clear all entry flags and knownFlagsMask
diff -r 6bdfaa31aa37 src/corelib/io/qfilesystemiterator_unix.cpp
--- a/src/corelib/io/qfilesystemiterator_unix.cpp Sat Dec 26 20:42:09 2015 -0600
+++ b/src/corelib/io/qfilesystemiterator_unix.cpp Tue Dec 29 18:40:22 2015 -0600
@@ -102,6 +102,8 @@
lastError = QT_EXT_QNX_READDIR_R(dir, mt_file.data(), &dirEntry, direntSize);
if (lastError)
return false;
+#elif 1 // defined(UAFS_HACKS)
+ dirEntry = QT_READDIR(dir);
#elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN)
lastError = QT_READDIR_R(dir, mt_file.data(), &dirEntry);
if (lastError)
diff -r 6bdfaa31aa37 src/corelib/io/qfsfileengine_unix.cpp
--- a/src/corelib/io/qfsfileengine_unix.cpp Sat Dec 26 20:42:09 2015 -0600
+++ b/src/corelib/io/qfsfileengine_unix.cpp Tue Dec 29 18:40:22 2015 -0600
@@ -195,10 +195,20 @@
fh = 0;
} else {
QByteArray fopenMode = openModeToFopenMode(openMode, fileEntry, metaData);
+ int flags = openModeToOpenFlags(openMode);
+ static constexpr cookie_io_functions_t cookie_io_funcs = {
+ //(__ssize_t (*)(void*, char*, size_t)) &uafs_read,
+ (__ssize_t (*)(void*, char*, size_t))&uafs_read,
+ (__ssize_t (*)(void*, const char*, size_t))&uafs_write,
+ (int (*)(void*, __off64_t*, int))uafs_lseek,
+ (int (*)(void *))uafs_close
+ };
// Try to open the file in buffered mode.
do {
- fh = QT_FOPEN(fileEntry.nativeFilePath().constData(), fopenMode.constData());
+ //fh = QT_FOPEN(fileEntry.nativeFilePath().constData(), fopenMode.constData());
+ fd = QT_OPEN(fileEntry.nativeFilePath().constData(), flags, 0666);
+ fh = fopencookie(&fd, fopenMode.constData(), cookie_io_funcs);
} while (!fh && errno == EINTR);
// On failure, return and report the error.
@@ -727,8 +737,14 @@
QT_OFF_T realOffset = QT_OFF_T(offset);
realOffset &= ~(QT_OFF_T(pageSize - 1));
+#if 1 /* AFS HACK */
+
+ qWarning("QFSFileEngine::map: Mapping not implemented with uAFS");
+ q->setError(QFile::UnspecifiedError, qt_error_string(int(ENOMEM)));
+ return 0;
+#else
void *mapAddress = QT_MMAP((void*)0, realSize,
- access, sharemode, nativeHandle(), realOffset);
+ accePss, sharemode, nativeHandle(), realOffset);
if (MAP_FAILED != mapAddress) {
uchar *address = extra + static_cast<uchar*>(mapAddress);
maps[address] = QPair<int,size_t>(extra, realSize);
@@ -750,6 +766,7 @@
break;
}
return 0;
+#endif
}
bool QFSFileEnginePrivate::unmap(uchar *ptr)
--=_nl.grid.coop-22360-1451447528-0001-2--