From patchwork Thu Aug 16 19:24:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 1334871 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id BB3A740B17 for ; Thu, 16 Aug 2012 19:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753308Ab2HPTY1 (ORCPT ); Thu, 16 Aug 2012 15:24:27 -0400 Received: from mga09.intel.com ([134.134.136.24]:53317 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753137Ab2HPTYZ convert rfc822-to-8bit (ORCPT ); Thu, 16 Aug 2012 15:24:25 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 16 Aug 2012 12:24:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.77,780,1336374000"; d="scan'208";a="187368124" Received: from orsmsx603.amr.corp.intel.com ([10.22.226.49]) by orsmga002.jf.intel.com with ESMTP; 16 Aug 2012 12:24:24 -0700 Received: from orsmsx104.amr.corp.intel.com (10.22.225.131) by orsmsx603.amr.corp.intel.com (10.22.226.49) with Microsoft SMTP Server (TLS) id 8.2.255.0; Thu, 16 Aug 2012 12:24:24 -0700 Received: from orsmsx101.amr.corp.intel.com ([169.254.8.152]) by ORSMSX104.amr.corp.intel.com ([169.254.3.52]) with mapi id 14.01.0355.002; Thu, 16 Aug 2012 12:24:24 -0700 From: "Hefty, Sean" To: "linux-rdma (linux-rdma@vger.kernel.org)" Subject: [PATCH 6/7] librdmacm/rspreload: Support sendfile Thread-Topic: [PATCH 6/7] librdmacm/rspreload: Support sendfile Thread-Index: Ac175IzhFXiCiW6QSIKA0JKoQWX56Q== Date: Thu, 16 Aug 2012 19:24:23 +0000 Message-ID: <1828884A29C6694DAF28B7E6B8A8237346A89981@ORSMSX101.amr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.22.254.139] MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Handle users calling sendfile with an rsocket. Signed-off-by: Sean Hefty --- src/preload.c | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/preload.c b/src/preload.c index 8b86415..c6cf176 100644 --- a/src/preload.c +++ b/src/preload.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -84,6 +86,7 @@ struct socket_calls { void *optval, socklen_t *optlen); int (*fcntl)(int socket, int cmd, ... /* arg */); int (*dup2)(int oldfd, int newfd); + ssize_t (*sendfile)(int out_fd, int in_fd, off_t *offset, size_t count); }; static struct socket_calls real; @@ -276,6 +279,7 @@ static void init_preload(void) real.getsockopt = dlsym(RTLD_NEXT, "getsockopt"); real.fcntl = dlsym(RTLD_NEXT, "fcntl"); real.dup2 = dlsym(RTLD_NEXT, "dup2"); + real.sendfile = dlsym(RTLD_NEXT, "sendfile"); rs.socket = dlsym(RTLD_DEFAULT, "rsocket"); rs.bind = dlsym(RTLD_DEFAULT, "rbind"); @@ -1009,3 +1013,23 @@ int dup2(int oldfd, int newfd) atomic_inc(&oldfdi->refcnt); return newfd; } + +ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count) +{ + void *file_addr; + int fd; + size_t ret; + + if (fd_get(out_fd, &fd) != fd_rsocket) + return real.sendfile(fd, in_fd, offset, count); + + file_addr = mmap(NULL, count, PROT_READ, 0, in_fd, offset ? *offset : 0); + if (file_addr == (void *) -1) + return -1; + + ret = rwrite(fd, file_addr, count); + if ((ret > 0) && offset) + lseek(in_fd, ret, SEEK_CUR); + munmap(file_addr, count); + return ret; +}