Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
beef9999 committed Dec 25, 2023
2 parents 4513104 + 1c0b39a commit 1076fdf
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 80 deletions.
28 changes: 17 additions & 11 deletions CMake/build-from-src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function(build_from_src [dep])
URL_MD5 605237f35de238dfacc83bcae406d95d
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND ""
BUILD_COMMAND make prefix=${BINARY_DIR} install -j
BUILD_COMMAND $(MAKE) prefix=${BINARY_DIR} install
INSTALL_COMMAND ""
)
set(AIO_INCLUDE_DIRS ${BINARY_DIR}/include PARENT_SCOPE)
Expand All @@ -26,8 +26,8 @@ function(build_from_src [dep])
URL_MD5 9b8aa094c4e5765dabf4da391f00d15c
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND CFLAGS=-fPIC ./configure --prefix=${BINARY_DIR} --static
BUILD_COMMAND make -j
INSTALL_COMMAND make install
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND $(MAKE) install
)
set(ZLIB_INCLUDE_DIRS ${BINARY_DIR}/include PARENT_SCOPE)
set(ZLIB_LIBRARIES ${BINARY_DIR}/lib/libz.a PARENT_SCOPE)
Expand All @@ -40,8 +40,8 @@ function(build_from_src [dep])
URL_MD5 2e8c3c23795415475654346484f5c4b8
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND ./configure --prefix=${BINARY_DIR}
BUILD_COMMAND V=1 CFLAGS=-fPIC make -C src
INSTALL_COMMAND make install
BUILD_COMMAND V=1 CFLAGS=-fPIC $(MAKE) -C src
INSTALL_COMMAND $(MAKE) install
)
set(URING_INCLUDE_DIRS ${BINARY_DIR}/include PARENT_SCOPE)
set(URING_LIBRARIES ${BINARY_DIR}/lib/liburing.a PARENT_SCOPE)
Expand Down Expand Up @@ -83,10 +83,12 @@ function(build_from_src [dep])
URL_MD5 bad68bb6bd9908da75e2c8dedc536b29
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND ./config -fPIC --prefix=${BINARY_DIR} --openssldir=${BINARY_DIR} shared
BUILD_COMMAND make -j ${NumCPU}
INSTALL_COMMAND make install
BUILD_COMMAND make -j 1 # https://github.com/openssl/openssl/issues/5762#issuecomment-376622684
INSTALL_COMMAND $(MAKE) install
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_INSTALL ON
)
ExternalProject_Get_Property(openssl SOURCE_DIR)
set(OPENSSL_ROOT_DIR ${BINARY_DIR} PARENT_SCOPE)
set(OPENSSL_INCLUDE_DIRS ${BINARY_DIR}/include PARENT_SCOPE)
set(OPENSSL_LIBRARIES ${BINARY_DIR}/lib/libssl.a ${BINARY_DIR}/lib/libcrypto.a PARENT_SCOPE)
Expand All @@ -101,16 +103,20 @@ function(build_from_src [dep])
URL ${PHOTON_CURL_SOURCE}
URL_MD5 a66270f11e3fbfad709600bbd1686704
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND autoreconf -i && ./configure --with-ssl=${OPENSSL_ROOT_DIR}
CONFIGURE_COMMAND autoreconf -i COMMAND ./configure --with-ssl=${OPENSSL_ROOT_DIR}
--without-libssh2 --enable-static --enable-shared=no --enable-optimize
--disable-manual --without-libidn
--disable-ftp --disable-file --disable-ldap --disable-ldaps
--disable-rtsp --disable-dict --disable-telnet --disable-tftp
--disable-pop3 --disable-imap --disable-smb --disable-smtp
--disable-gopher --without-nghttp2 --enable-http --disable-verbose
--with-pic=PIC --prefix=${BINARY_DIR}
BUILD_COMMAND make -j ${NumCPU}
INSTALL_COMMAND make install
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND $(MAKE) install
DEPENDS openssl
LOG_CONFIGURE ON
LOG_BUILD ON
LOG_INSTALL ON
)
set(CURL_INCLUDE_DIRS ${BINARY_DIR}/include PARENT_SCOPE)
set(CURL_LIBRARIES ${BINARY_DIR}/lib/libcurl.a PARENT_SCOPE)
Expand Down
12 changes: 6 additions & 6 deletions common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ ptr_array_t<T> ptr_array(T* pbegin, size_t n)
return {pbegin, pbegin + n};
}

#define __INLINE__ __attribute__((always_inline))
#define __FORCE_INLINE__ __INLINE__ inline

template<typename T>
class Defer
{
public:
Defer(T fn) : m_func(fn) {}
~Defer() { m_func(); }
Defer(T fn) __INLINE__ : m_func(fn) {}
~Defer() __INLINE__ { m_func(); }
void operator=(const Defer<T>&) = delete;
operator bool () { return true; } // if (DEFER(...)) { ... }

private:
T m_func;
};

template<typename T>
template<typename T> __FORCE_INLINE__
Defer<T> make_defer(T func) { return Defer<T>(func); }

#define __INLINE__ __attribute__((always_inline))
#define __FORCE_INLINE__ __INLINE__ inline

#define _CONCAT_(a, b) a##b
#define _CONCAT(a, b) _CONCAT_(a, b)

Expand Down
20 changes: 16 additions & 4 deletions fs/fuse_adaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ namespace photon {
namespace fs{

static IFileSystem* fs = nullptr;
static uid_t cuid = 0, cgid = 0;

#define CHECK_FS() if (!fs) return -EFAULT;

static void* xmp_init(struct fuse_conn_info *conn)
{
REPORT_PERF(xmp_init, 1)
(void) conn;
cuid = geteuid();
cgid = getegid();
if ((unsigned int)conn->capable & FUSE_CAP_ATOMIC_O_TRUNC) {
conn->want |= FUSE_CAP_ATOMIC_O_TRUNC;
}
if ((unsigned int)conn->capable & FUSE_CAP_BIG_WRITES) {
conn->want |= FUSE_CAP_BIG_WRITES;
}
return NULL;
}

Expand All @@ -102,9 +110,13 @@ static int xmp_getattr(const char *path, struct stat *stbuf)
CHECK_FS();
errno = 0;
int res = fs->lstat(path, stbuf);
if(res) \
LOG_ERROR_RETURN(0, errno ? -errno : res, VALUE(path));
errno = 0;
if(res) return -errno;
stbuf->st_blocks = stbuf->st_size / 512 + 1; // du relies on this
stbuf->st_blksize = 4096;
// use current user/group when backendfs doesn't support uid/gid
if (stbuf->st_uid == 0) stbuf->st_uid = cuid;
if (stbuf->st_gid == 0) stbuf->st_gid = cgid;
if (stbuf->st_nlink == 0) stbuf->st_nlink = 1;
return 0;
}

Expand Down
6 changes: 2 additions & 4 deletions net/http/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ISocketStream* PooledDialer::dial(std::string_view host, uint16_t port, bool sec
if (ipaddr.undefined()) LOG_DEBUG("No connectable resolve result");
// When failed, remove resolved result from dns cache so that following retries can try
// different ips.
resolver->discard_cache(strhost.c_str());
resolver->discard_cache(strhost.c_str(), ipaddr);
return nullptr;
}

Expand Down Expand Up @@ -120,9 +120,7 @@ class ClientImpl : public Client {
CommonHeaders<> m_common_headers;
ICookieJar *m_cookie_jar;
ClientImpl(ICookieJar *cookie_jar, TLSContext *tls_ctx) :
m_cookie_jar(cookie_jar),
m_dialer(tls_ctx) {
}
m_dialer(tls_ctx), m_cookie_jar(cookie_jar) { }

using SocketStream_ptr = std::unique_ptr<ISocketStream>;
int redirect(Operation* op) {
Expand Down
10 changes: 10 additions & 0 deletions net/http/test/client_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,16 @@ TEST(http_client, partial_body) {
EXPECT_EQ(true, buf == "http_clien");
}

TEST(DISABLED_http_client, ipv6) { // make sure runing in a ipv6-ready environment
auto client = new_http_client();
DEFER(delete client);
// here is an ipv6-only website
auto op = client->new_operation(Verb::GET, "http://test6.ustc.edu.cn");
DEFER(delete op);
op->call();
EXPECT_EQ(200, op->resp.status_code());
}

TEST(url, url_escape_unescape) {
EXPECT_EQ(
url_escape("?a=x:b&b=cd&c= feg&d=2/1[+]@alibaba.com&e='!bad';"),
Expand Down
51 changes: 24 additions & 27 deletions net/kernel_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ class KernelSocketStream : public SocketStreamBase {

class KernelSocketClient : public SocketClientBase {
public:
KernelSocketClient(int socket_family, bool nonblocking) :
m_socket_family(socket_family),
m_nonblocking(nonblocking) {}
KernelSocketClient(bool nonblocking) : m_nonblocking(nonblocking) {}

ISocketStream* connect(const char* path, size_t count) override {
struct sockaddr_un addr_un;
Expand All @@ -211,11 +209,10 @@ class KernelSocketClient : public SocketClientBase {
}

protected:
int m_socket_family;
bool m_nonblocking;

virtual KernelSocketStream* create_stream() {
return new KernelSocketStream(m_socket_family, m_nonblocking);
virtual KernelSocketStream* create_stream(int socket_family) {
return new KernelSocketStream(socket_family, m_nonblocking);
}

virtual int fd_connect(int fd, const sockaddr* remote, socklen_t addrlen) {
Expand All @@ -224,7 +221,7 @@ class KernelSocketClient : public SocketClientBase {

ISocketStream* do_connect(const sockaddr* remote, socklen_t len_remote,
const sockaddr* local = nullptr, socklen_t len_local = 0) {
auto stream = create_stream();
auto stream = create_stream(remote->sa_family);
auto deleter = [&](KernelSocketStream*) {
auto errno_backup = errno;
delete stream;
Expand Down Expand Up @@ -504,8 +501,8 @@ class ZeroCopySocketClient : public KernelSocketClient {
public:
using KernelSocketClient::KernelSocketClient;
protected:
KernelSocketStream* create_stream() override {
return new ZeroCopySocketStream(m_socket_family, m_nonblocking);
KernelSocketStream* create_stream(int socket_family) override {
return new ZeroCopySocketStream(socket_family, m_nonblocking);
}
};

Expand Down Expand Up @@ -544,8 +541,8 @@ class IouringSocketClient : public KernelSocketClient {
using KernelSocketClient::KernelSocketClient;

protected:
KernelSocketStream* create_stream() override {
return new IouringSocketStream(m_socket_family, m_nonblocking);
KernelSocketStream* create_stream(int socket_family) override {
return new IouringSocketStream(socket_family, m_nonblocking);
}

int fd_connect(int fd, const sockaddr* remote, socklen_t addrlen) override {
Expand Down Expand Up @@ -614,8 +611,8 @@ class IouringFixedFileSocketClient : public IouringSocketClient {
protected:
using IouringSocketClient::IouringSocketClient;

KernelSocketStream* create_stream() override {
return new IouringFixedFileSocketStream(m_socket_family, m_nonblocking);
KernelSocketStream* create_stream(int socket_family) override {
return new IouringFixedFileSocketStream(socket_family, m_nonblocking);
}
};

Expand Down Expand Up @@ -683,8 +680,8 @@ class FstackDpdkSocketClient : public KernelSocketClient {
protected:
using KernelSocketClient::KernelSocketClient;

KernelSocketStream* create_stream() override {
return new FstackDpdkSocketStream(m_socket_family, m_nonblocking);
KernelSocketStream* create_stream(int socket_family) override {
return new FstackDpdkSocketStream(socket_family, m_nonblocking);
}

int fd_connect(int fd, const sockaddr* remote, socklen_t addrlen) override {
Expand Down Expand Up @@ -939,8 +936,8 @@ class ETKernelSocketClient : public KernelSocketClient {
using KernelSocketClient::KernelSocketClient;

protected:
KernelSocketStream* create_stream() override {
return new ETKernelSocketStream(m_socket_family, m_nonblocking);
KernelSocketStream* create_stream(int socket_family) override {
return new ETKernelSocketStream(socket_family, m_nonblocking);
}
};

Expand Down Expand Up @@ -974,10 +971,10 @@ class ETKernelSocketServer : public KernelSocketServer, public NotifyContext {
/* ET Socket - End */

extern "C" ISocketClient* new_tcp_socket_client() {
return new KernelSocketClient(AF_INET, true);
return new KernelSocketClient(true);
}
extern "C" ISocketClient* new_tcp_socket_client_ipv6() {
return new KernelSocketClient(AF_INET6, true);
return new KernelSocketClient(true);
}
extern "C" ISocketServer* new_tcp_socket_server() {
return NewObj<KernelSocketServer>(AF_INET, false, true)->init();
Expand All @@ -986,7 +983,7 @@ extern "C" ISocketServer* new_tcp_socket_server_ipv6() {
return NewObj<KernelSocketServer>(AF_INET6, false, true)->init();
}
extern "C" ISocketClient* new_uds_client() {
return new KernelSocketClient(AF_UNIX, true);
return new KernelSocketClient(true);
}
extern "C" ISocketServer* new_uds_server(bool autoremove) {
return NewObj<KernelSocketServer>(AF_UNIX, autoremove, true)->init();
Expand All @@ -996,14 +993,14 @@ extern "C" ISocketServer* new_zerocopy_tcp_server() {
return NewObj<ZeroCopySocketServer>(AF_INET, false, true)->init();
}
extern "C" ISocketClient* new_zerocopy_tcp_client() {
return new ZeroCopySocketClient(AF_INET, true);
return new ZeroCopySocketClient(true);
}
#ifdef PHOTON_URING
extern "C" ISocketClient* new_iouring_tcp_client() {
if (photon::iouring_register_files_enabled())
return new IouringFixedFileSocketClient(AF_INET, false);
return new IouringFixedFileSocketClient(false);
else
return new IouringSocketClient(AF_INET, false);
return new IouringSocketClient(false);
}
extern "C" ISocketServer* new_iouring_tcp_server() {
if (photon::iouring_register_files_enabled())
Expand All @@ -1013,23 +1010,23 @@ extern "C" ISocketServer* new_iouring_tcp_server() {
}
#endif // PHOTON_URING
extern "C" ISocketClient* new_et_tcp_socket_client() {
return new ETKernelSocketClient(AF_INET, true);
return new ETKernelSocketClient(true);
}
extern "C" ISocketServer* new_et_tcp_socket_server() {
return NewObj<ETKernelSocketServer>(AF_INET, false, true)->init();
}
extern "C" ISocketClient* new_smc_socket_client() {
return new KernelSocketClient(AF_SMC, true);
return new KernelSocketClient(true);
}
extern "C" ISocketServer* new_smc_socket_server() {
return NewObj<KernelSocketServer>(AF_SMC, false, true)->init();
}
#ifdef ENABLE_FSTACK_DPDK
extern "C" ISocketClient* new_fstack_dpdk_socket_client() {
return new FstackDpdkSocketClient(AF_INET, true);
return new FstackDpdkSocketClient(true);
}
extern "C" ISocketServer* new_fstack_dpdk_socket_server() {
return NewObj<FstackDpdkSocketServer>(AF_INET, false, true)->init();
return NewObj<FstackDpdkSocketServer>(false, true)->init();
}
#endif // ENABLE_FSTACK_DPDK
#endif // __linux__
Expand Down
4 changes: 2 additions & 2 deletions net/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,9 @@ TEST(utils, resolver) {
DEFER(delete resolver);
net::IPAddr localhost("127.0.0.1");
net::IPAddr addr = resolver->resolve("localhost");
EXPECT_EQ(localhost.to_nl(), addr.to_nl());
if (addr.is_ipv4()) EXPECT_EQ(localhost.to_nl(), addr.to_nl());
auto func = [&](net::IPAddr addr_){
EXPECT_EQ(localhost.to_nl(), addr_.to_nl());
if (addr_.is_ipv4()) EXPECT_EQ(localhost.to_nl(), addr_.to_nl());
};
resolver->resolve("localhost", func);
resolver->discard_cache("non-exist-host.com");
Expand Down
Loading

0 comments on commit 1076fdf

Please sign in to comment.