Skip to content

Linux port hdd cp1 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ project.xcworkspace
Build
.build

# build files generated by autotools
Makefile
Makefile.in
config.log
configure
aclocal.m4
autom4te.cache
config.log
config.status
config
configure
libtool

18 changes: 10 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,17 @@ AS_IF([test "x$dispatch_cv_cc_omit_leaf_fp" != "xno"], [
])
AC_SUBST([OMIT_LEAF_FP_FLAGS])

AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
saveLDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
AC_LINK_IFELSE([AC_LANG_PROGRAM([
extern int foo; int foo;], [foo = 0;])],
[dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
LDFLAGS="$saveLDFLAGS"
AS_IF([test "x$have_mach" = "xtrue"], [
AC_CACHE_CHECK([for darwin linker], [dispatch_cv_ld_darwin], [
saveLDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -dynamiclib -compatibility_version 1.2.3 -current_version 4.5.6 -dead_strip"
AC_LINK_IFELSE([AC_LANG_PROGRAM([
extern int foo; int foo;], [foo = 0;])],
[dispatch_cv_ld_darwin="yes"], [dispatch_cv_ld_darwin="no"])
LDFLAGS="$saveLDFLAGS"
])
])
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" != "xno"])
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])

#
# Temporary: some versions of clang do not mark __builtin_trap() as
Expand Down
5 changes: 5 additions & 0 deletions m4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
libtool.m4
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
4 changes: 3 additions & 1 deletion os/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
osdir=$(includedir)/os

os_HEADERS= \
object.h
object.h \
base.h \
linux_base.h

noinst_HEADERS= \
object_private.h
10 changes: 10 additions & 0 deletions os/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Stub out Apple internal header file to redirect to linux_base.h.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is problematic, OSX and iOS already have a public header with this name from a different project and this will conflict

Either we have to conditionalize the install of this header based on platform (and fully replicate its contents from OSX), or we have to conditionalize its inclusion.

an AC_CHECK_HEADERS([os/base.h]) test in configure.ac would be the standard way to do the latter, but since most of the #include <os/base.h> are in API headers, that is not really an option either (since we don't want to install config.h on OSX)

the best option for now may be to move the various #include <os/base.h> into #ifdef __APPLE__ conditionals and in the #else case do the #include <os/linux_base.h> (or possibly include an intermediate header that does non-APPLE platform disambiguation, though based on what ?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about it more, something like this may make the most sense (e.g. in a new os/target.h header ?)

#ifdef __APPLE__
#include <TargetConditionals.h>
#else
#define TARGET_OS_UNIX 1
#endif

and then conditionalize with #if TARGET_OS_MAC resp. #if TARGET_OS_UNIX ?

// Maybe not the best fix in the long run, but avoids having to #ifdef
// the include of <os/base.h> in all of the other files....

#ifndef __OS_BASE__
#define __OS_BASE__

#include <os/linux_base.h>

#endif
147 changes: 147 additions & 0 deletions os/linux_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* @APPLE_APACHE_LICENSE_HEADER_START@
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @APPLE_APACHE_LICENSE_HEADER_END@
*/

#ifndef __OS_LINUX_BASE__
#define __OS_LINUX_BASE__


// marker for hacks we have made to make progress
#define __LINUX_PORT_HDD__ 1

/*
* Stub out defines for some mach types and related macros
*/

typedef uint32_t mach_port_t;

#define MACH_PORT_NULL 0
#define MACH_PORT_DEAD -1

#define EVFILT_MACHPORT -8

typedef uint32_t mach_error_t;

typedef uint32_t mach_vm_size_t;

typedef uint32_t mach_msg_return_t;

typedef uintptr_t mach_vm_address_t;

typedef uint32_t dispatch_mach_msg_t;

typedef uint32_t dispatch_mach_t;

typedef uint32_t dispatch_mach_reason_t;

typedef uint32_t voucher_activity_mode_t;

typedef uint32_t voucher_activity_trace_id_t;

typedef uint32_t voucher_activity_id_t;

typedef uint32_t _voucher_activity_buffer_hook_t;;

typedef uint32_t voucher_activity_flag_t;

typedef struct
{
} mach_msg_header_t;


typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,
dispatch_mach_msg_t, mach_error_t);

typedef void (*dispatch_mach_msg_destructor_t)(void*);

/*
* Stub out defines for other missing types
*/

struct kevent64_s
{
uint64_t ident;
int16_t filter;
uint16_t flags;
uint32_t fflags;
int64_t data;
uint64_t udata;
uint64_t ext[2];
};

typedef uint32_t voucher_activity_mode_t;

struct voucher_offsets_s {
uint32_t vo_version;
};


// bogus...
#define PAGE_SIZE 4096
#define SIZE_T_MAX 0x7fffffff

#define NOTE_VM_PRESSURE 0
#define NOTE_ABSOLUTE 0
#define NOTE_NSECONDS 0
#define NOTE_LEEWAY 0
#define NOTE_CRITICAL 0
#define NOTE_BACKGROUND 0

/*
* Stub out misc linking and compilation attributes
*/

#ifdef OS_EXPORT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to put the OS_* macros from the real os/base.h into the replicated version in the libdispatch repo (if we go that route)

#undef OS_EXPORT
#endif
#define OS_EXPORT

#ifdef DISPATCH_EXPORT
#undef DISPATCH_EXPORT
#endif
#define DISPATCH_EXPORT

#ifdef DISPATCH_NONNULL_ALL
#undef DISPATCH_NONNULL_ALL
#endif
#define DISPATCH_NONNULL_ALL

#ifdef OS_WARN_RESULT_NEEDS_RELEASE
#undef OS_WARN_RESULT_NEEDS_RELEASE
#endif

#ifdef OS_WARN_RESULT
#undef OS_WARN_RESULT
#endif
#define OS_WARN_RESULT

#ifdef OS_NOTHROW
#undef OS_NOTHROW
#endif
#define OS_NOTHROW


// NOTE (Dave), these and similar macros come from Availabity.h on OS X
#define __OSX_AVAILABLE_BUT_DEPRECATED(a,b,c,d) //
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(a,b,c,d,msg) //


// Print a warning when an unported code path executes.
#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); } while (0)


#endif /* __OS_LINUX_BASE__ */
2 changes: 2 additions & 0 deletions private/voucher_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ dispatch_queue_create_with_accounting_override_voucher(const char *label,
* voucher ports directly.
*/

#ifdef HAVE_MACH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot have these types of checks in API headers, they will not pass on OSX (nobody defines HAVE_MACH). I would use either __APPLE__ or the TARGET_OS_MAC macro from TargetConditionals.h (there is also a TARGET_OS_UNIX there that might make sense for the 'linux-specific' checks)

#include <mach/mach.h>
#endif

/*!
* @function voucher_create_with_mach_msg
Expand Down
5 changes: 5 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider.h
.libs
*.lo
*.la

1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libdispatch_la_SOURCES= \
queue.c \
semaphore.c \
source.c \
stubs.c \
time.c \
transform.c \
voucher.c \
Expand Down
7 changes: 6 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ const struct dispatch_tsd_indexes_s dispatch_tsd_indexes = {
.dti_qos_class_index = dispatch_priority_key,
};
#else // DISPATCH_USE_DIRECT_TSD
#ifndef __LINUX_PORT_HDD__
#error Not implemented on this platform
#endif
#endif // DISPATCH_USE_DIRECT_TSD

// 6618342 Contact the team that owns the Instrument DTrace probe before
Expand Down Expand Up @@ -1157,7 +1159,10 @@ const struct dispatch_source_type_s _dispatch_source_type_vnode = {
.flags = EV_CLEAR|EV_UDATA_SPECIFIC,
},
.mask = NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|
NOTE_RENAME|NOTE_REVOKE
NOTE_RENAME
#if HAVE_DECL_NOTE_REVOKE
|NOTE_REVOKE
#endif
#if HAVE_DECL_NOTE_NONE
|NOTE_NONE
#endif
Expand Down
1 change: 1 addition & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@


#include <os/object.h>
#include "stubs_internal.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like the wrong spot for this inclusion, plus we have the shims/ directory for this type of thing already, please use shims.h and add new shims/stubs in there

#include <dispatch/time.h>
#include <dispatch/object.h>
#include <dispatch/queue.h>
Expand Down
43 changes: 41 additions & 2 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,14 @@ dispatch_io_create_with_path(dispatch_io_type_t type, const char *path,
int err = 0;
struct stat st;
_dispatch_io_syscall_switch_noerr(err,
(path_data->oflag & O_NOFOLLOW) == O_NOFOLLOW ||
(path_data->oflag & O_SYMLINK) == O_SYMLINK ?
(path_data->oflag & O_NOFOLLOW) == O_NOFOLLOW
#ifdef __LINUX_PORT_HDD__
?
lstat(path_data->path, &st) : stat(path_data->path, &st),
#else
|| (path_data->oflag & O_SYMLINK) == O_SYMLINK ?
lstat(path_data->path, &st) : stat(path_data->path, &st),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line doesn't seem like it needs to be duplicated ?

#endif
case 0:
err = _dispatch_io_validate_type(channel, st.st_mode);
break;
Expand Down Expand Up @@ -1777,17 +1782,37 @@ _dispatch_stream_cleanup_operations(dispatch_stream_t stream,
dispatch_operation_t op, tmp;
typeof(*stream->operations) *operations;
operations = &stream->operations[DISPATCH_IO_RANDOM];
#ifdef __LINUX_PORT_HDD__
LINUX_PORT_ERROR();
// NOT CORRECT (doesn't support removal during iteration)
TAILQ_FOREACH(op, operations, operation_list) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should add a copy of the bsd sys/queue.h with the safe macros to shims/? (BSD license should be compatible)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at least a header that adds the missing macros, I really don't like the duplication of all of the FOREACH_SAFE blocks, that will be a maintenance and merging headache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This was intended as a really short term stop-gap to get things to build. Not something that should be merged back. We'll at least pull in the missing safe macros to shims.

if (!channel || op->channel == channel) {
_dispatch_stream_complete_operation(stream, op);
}
}
#else
TAILQ_FOREACH_SAFE(op, operations, operation_list, tmp) {
if (!channel || op->channel == channel) {
_dispatch_stream_complete_operation(stream, op);
}
}
#endif
operations = &stream->operations[DISPATCH_IO_STREAM];
#ifdef __LINUX_PORT_HDD__
LINUX_PORT_ERROR();
// NOT CORRECT (doesn't support removal during iteration)
TAILQ_FOREACH(op, operations, operation_list) {
if (!channel || op->channel == channel) {
_dispatch_stream_complete_operation(stream, op);
}
}
#else
TAILQ_FOREACH_SAFE(op, operations, operation_list, tmp) {
if (!channel || op->channel == channel) {
_dispatch_stream_complete_operation(stream, op);
}
}
#endif
if (stream->source_running && !_dispatch_stream_operation_avail(stream)) {
dispatch_suspend(stream->source);
stream->source_running = false;
Expand All @@ -1799,11 +1824,21 @@ _dispatch_disk_cleanup_operations(dispatch_disk_t disk, dispatch_io_t channel)
{
// On pick queue
dispatch_operation_t op, tmp;
#ifdef __LINUX_PORT_HDD__
LINUX_PORT_ERROR();
// NOT CORRECT (doesn't support removal during iteration)
TAILQ_FOREACH(op, &disk->operations, operation_list) {
if (!channel || op->channel == channel) {
_dispatch_disk_complete_operation(disk, op);
}
}
#else
TAILQ_FOREACH_SAFE(op, &disk->operations, operation_list, tmp) {
if (!channel || op->channel == channel) {
_dispatch_disk_complete_operation(disk, op);
}
}
#endif
}

#pragma mark -
Expand Down Expand Up @@ -2064,6 +2099,9 @@ _dispatch_disk_perform(void *ctxt)
static void
_dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
{
#ifdef __LINUX_PORT_HDD__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a configure check for the F_RDADVISE fcntl (or short-term just an #ifdef F_RDADVISE)

LINUX_PORT_ERROR();
#else
int err;
struct radvisory advise;
// No point in issuing a read advise for the next chunk if we are already
Expand All @@ -2090,6 +2128,7 @@ _dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
// TODO: set disk status on error
default: (void)dispatch_assume_zero(err); break;
);
#endif
}

static int
Expand Down
Loading