2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2001-04-10 07:59:06 +00:00
|
|
|
* Copyright (c) 2000-2001 Boris Popov
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Boris Popov.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2003-06-11 05:37:42 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:27:19 +00:00
|
|
|
#include <sys/module.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/fcntl.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/ioccom.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/malloc.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/file.h> /* Must come after sys/malloc.h */
|
2003-01-01 01:56:19 +00:00
|
|
|
#include <sys/filedesc.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/mbuf.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/poll.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/select.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/socket.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/sysctl.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/uio.h>
|
2001-04-10 07:59:06 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netsmb/smb.h>
|
|
|
|
#include <netsmb/smb_conn.h>
|
|
|
|
#include <netsmb/smb_subr.h>
|
|
|
|
#include <netsmb/smb_dev.h>
|
|
|
|
|
|
|
|
#define SMB_GETDEV(dev) ((struct smb_dev*)(dev)->si_drv1)
|
|
|
|
#define SMB_CHECKMINOR(dev) do { \
|
|
|
|
sdp = SMB_GETDEV(dev); \
|
|
|
|
if (sdp == NULL) return ENXIO; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
static d_open_t nsmb_dev_open;
|
|
|
|
static d_close_t nsmb_dev_close;
|
|
|
|
static d_ioctl_t nsmb_dev_ioctl;
|
|
|
|
|
2003-09-26 20:26:25 +00:00
|
|
|
MODULE_DEPEND(netsmb, libiconv, 1, 1, 2);
|
2001-04-10 07:59:06 +00:00
|
|
|
MODULE_VERSION(netsmb, NSMB_VERSION);
|
|
|
|
|
|
|
|
static int smb_version = NSMB_VERSION;
|
|
|
|
|
|
|
|
|
|
|
|
SYSCTL_DECL(_net_smb);
|
|
|
|
SYSCTL_INT(_net_smb, OID_AUTO, version, CTLFLAG_RD, &smb_version, 0, "");
|
|
|
|
|
|
|
|
static MALLOC_DEFINE(M_NSMBDEV, "NETSMBDEV", "NET/SMB device");
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
int smb_dev_queue(struct smb_dev *ndp, struct smb_rq *rqp, int prio);
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct cdevsw nsmb_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2008-11-03 14:23:15 +00:00
|
|
|
.d_flags = D_NEEDGIANT | D_NEEDMINOR,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = nsmb_dev_open,
|
|
|
|
.d_close = nsmb_dev_close,
|
|
|
|
.d_ioctl = nsmb_dev_ioctl,
|
2004-02-11 12:49:49 +00:00
|
|
|
.d_name = NSMB_NAME
|
2001-04-10 07:59:06 +00:00
|
|
|
};
|
|
|
|
|
2008-11-03 14:23:15 +00:00
|
|
|
static eventhandler_tag nsmb_dev_tag;
|
|
|
|
static struct clonedevs *nsmb_clones;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
|
|
|
static void
|
2005-08-08 19:55:32 +00:00
|
|
|
nsmb_dev_clone(void *arg, struct ucred *cred, char *name, int namelen,
|
|
|
|
struct cdev **dev)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
2008-11-03 14:23:15 +00:00
|
|
|
int i, u;
|
2001-04-10 07:59:06 +00:00
|
|
|
|
2004-06-17 17:16:53 +00:00
|
|
|
if (*dev != NULL)
|
2001-04-10 07:59:06 +00:00
|
|
|
return;
|
2008-11-03 14:23:15 +00:00
|
|
|
|
|
|
|
if (strcmp(name, NSMB_NAME) == 0)
|
|
|
|
u = -1;
|
|
|
|
else if (dev_stdclone(name, NULL, NSMB_NAME, &u) != 1)
|
2001-04-10 07:59:06 +00:00
|
|
|
return;
|
2008-11-03 14:23:15 +00:00
|
|
|
i = clone_create(&nsmb_clones, &nsmb_cdevsw, &u, dev, 0);
|
|
|
|
if (i) {
|
|
|
|
*dev = make_dev(&nsmb_cdevsw, u, UID_ROOT, GID_WHEEL, 0600,
|
|
|
|
"%s%d", NSMB_NAME, u);
|
|
|
|
if (*dev != NULL) {
|
|
|
|
dev_ref(*dev);
|
|
|
|
(*dev)->si_flags |= SI_CHEAPCLONE;
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
nsmb_dev_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
|
|
|
struct smb_dev *sdp;
|
2002-02-27 18:32:23 +00:00
|
|
|
struct ucred *cred = td->td_ucred;
|
2001-04-10 07:59:06 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
sdp = SMB_GETDEV(dev);
|
|
|
|
if (sdp && (sdp->sd_flags & NSMBFL_OPEN))
|
|
|
|
return EBUSY;
|
|
|
|
if (sdp == NULL) {
|
2003-02-19 05:47:46 +00:00
|
|
|
sdp = malloc(sizeof(*sdp), M_NSMBDEV, M_WAITOK);
|
2001-04-10 07:59:06 +00:00
|
|
|
dev->si_drv1 = (void*)sdp;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* XXX: this is just crazy - make a device for an already passed device...
|
|
|
|
* someone should take care of it.
|
|
|
|
*/
|
|
|
|
if ((dev->si_flags & SI_NAMED) == 0)
|
2008-09-27 08:51:18 +00:00
|
|
|
make_dev(&nsmb_cdevsw, dev2unit(dev), cred->cr_uid,
|
|
|
|
cred->cr_gid, 0700, NSMB_NAME"%d", dev2unit(dev));
|
2001-04-10 07:59:06 +00:00
|
|
|
bzero(sdp, sizeof(*sdp));
|
|
|
|
/*
|
|
|
|
STAILQ_INIT(&sdp->sd_rqlist);
|
|
|
|
STAILQ_INIT(&sdp->sd_rplist);
|
|
|
|
bzero(&sdp->sd_pollinfo, sizeof(struct selinfo));
|
|
|
|
*/
|
|
|
|
s = splimp();
|
|
|
|
sdp->sd_level = -1;
|
|
|
|
sdp->sd_flags |= NSMBFL_OPEN;
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
nsmb_dev_close(struct cdev *dev, int flag, int fmt, struct thread *td)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
|
|
|
struct smb_dev *sdp;
|
|
|
|
struct smb_vc *vcp;
|
|
|
|
struct smb_share *ssp;
|
|
|
|
struct smb_cred scred;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
SMB_CHECKMINOR(dev);
|
|
|
|
s = splimp();
|
|
|
|
if ((sdp->sd_flags & NSMBFL_OPEN) == 0) {
|
|
|
|
splx(s);
|
|
|
|
return EBADF;
|
|
|
|
}
|
2001-12-02 08:47:29 +00:00
|
|
|
smb_makescred(&scred, td, NULL);
|
2001-04-10 07:59:06 +00:00
|
|
|
ssp = sdp->sd_share;
|
|
|
|
if (ssp != NULL)
|
|
|
|
smb_share_rele(ssp, &scred);
|
|
|
|
vcp = sdp->sd_vc;
|
|
|
|
if (vcp != NULL)
|
|
|
|
smb_vc_rele(vcp, &scred);
|
|
|
|
/*
|
|
|
|
smb_flushq(&sdp->sd_rqlist);
|
|
|
|
smb_flushq(&sdp->sd_rplist);
|
|
|
|
*/
|
|
|
|
dev->si_drv1 = NULL;
|
|
|
|
free(sdp, M_NSMBDEV);
|
2007-07-10 09:23:10 +00:00
|
|
|
destroy_dev_sched(dev);
|
2001-04-10 07:59:06 +00:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
nsmb_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
2001-04-10 07:59:06 +00:00
|
|
|
{
|
|
|
|
struct smb_dev *sdp;
|
|
|
|
struct smb_vc *vcp;
|
|
|
|
struct smb_share *ssp;
|
|
|
|
struct smb_cred scred;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
SMB_CHECKMINOR(dev);
|
|
|
|
if ((sdp->sd_flags & NSMBFL_OPEN) == 0)
|
|
|
|
return EBADF;
|
|
|
|
|
2001-12-02 08:47:29 +00:00
|
|
|
smb_makescred(&scred, td, NULL);
|
2001-04-10 07:59:06 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case SMBIOC_OPENSESSION:
|
|
|
|
if (sdp->sd_vc)
|
|
|
|
return EISCONN;
|
|
|
|
error = smb_usr_opensession((struct smbioc_ossn*)data,
|
|
|
|
&scred, &vcp);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
sdp->sd_vc = vcp;
|
2008-11-02 23:20:27 +00:00
|
|
|
smb_vc_unlock(vcp, 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_VC;
|
|
|
|
break;
|
|
|
|
case SMBIOC_OPENSHARE:
|
|
|
|
if (sdp->sd_share)
|
|
|
|
return EISCONN;
|
|
|
|
if (sdp->sd_vc == NULL)
|
|
|
|
return ENOTCONN;
|
|
|
|
error = smb_usr_openshare(sdp->sd_vc,
|
|
|
|
(struct smbioc_oshare*)data, &scred, &ssp);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
sdp->sd_share = ssp;
|
2008-11-02 23:20:27 +00:00
|
|
|
smb_share_unlock(ssp, 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_SHARE;
|
|
|
|
break;
|
|
|
|
case SMBIOC_REQUEST:
|
|
|
|
if (sdp->sd_share == NULL)
|
|
|
|
return ENOTCONN;
|
|
|
|
error = smb_usr_simplerequest(sdp->sd_share,
|
|
|
|
(struct smbioc_rq*)data, &scred);
|
|
|
|
break;
|
|
|
|
case SMBIOC_T2RQ:
|
|
|
|
if (sdp->sd_share == NULL)
|
|
|
|
return ENOTCONN;
|
|
|
|
error = smb_usr_t2request(sdp->sd_share,
|
|
|
|
(struct smbioc_t2rq*)data, &scred);
|
|
|
|
break;
|
|
|
|
case SMBIOC_SETFLAGS: {
|
|
|
|
struct smbioc_flags *fl = (struct smbioc_flags*)data;
|
|
|
|
int on;
|
|
|
|
|
|
|
|
if (fl->ioc_level == SMBL_VC) {
|
|
|
|
if (fl->ioc_mask & SMBV_PERMANENT) {
|
|
|
|
on = fl->ioc_flags & SMBV_PERMANENT;
|
|
|
|
if ((vcp = sdp->sd_vc) == NULL)
|
|
|
|
return ENOTCONN;
|
|
|
|
error = smb_vc_get(vcp, LK_EXCLUSIVE, &scred);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (on && (vcp->obj.co_flags & SMBV_PERMANENT) == 0) {
|
|
|
|
vcp->obj.co_flags |= SMBV_PERMANENT;
|
2001-12-02 08:47:29 +00:00
|
|
|
smb_vc_ref(vcp);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else if (!on && (vcp->obj.co_flags & SMBV_PERMANENT)) {
|
|
|
|
vcp->obj.co_flags &= ~SMBV_PERMANENT;
|
|
|
|
smb_vc_rele(vcp, &scred);
|
|
|
|
}
|
|
|
|
smb_vc_put(vcp, &scred);
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
} else if (fl->ioc_level == SMBL_SHARE) {
|
|
|
|
if (fl->ioc_mask & SMBS_PERMANENT) {
|
|
|
|
on = fl->ioc_flags & SMBS_PERMANENT;
|
|
|
|
if ((ssp = sdp->sd_share) == NULL)
|
|
|
|
return ENOTCONN;
|
|
|
|
error = smb_share_get(ssp, LK_EXCLUSIVE, &scred);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (on && (ssp->obj.co_flags & SMBS_PERMANENT) == 0) {
|
|
|
|
ssp->obj.co_flags |= SMBS_PERMANENT;
|
2001-12-02 08:47:29 +00:00
|
|
|
smb_share_ref(ssp);
|
2001-04-10 07:59:06 +00:00
|
|
|
} else if (!on && (ssp->obj.co_flags & SMBS_PERMANENT)) {
|
|
|
|
ssp->obj.co_flags &= ~SMBS_PERMANENT;
|
|
|
|
smb_share_rele(ssp, &scred);
|
|
|
|
}
|
|
|
|
smb_share_put(ssp, &scred);
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SMBIOC_LOOKUP:
|
|
|
|
if (sdp->sd_vc || sdp->sd_share)
|
|
|
|
return EISCONN;
|
|
|
|
vcp = NULL;
|
|
|
|
ssp = NULL;
|
|
|
|
error = smb_usr_lookup((struct smbioc_lookup*)data, &scred, &vcp, &ssp);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
if (vcp) {
|
|
|
|
sdp->sd_vc = vcp;
|
2008-11-02 23:20:27 +00:00
|
|
|
smb_vc_unlock(vcp, 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_VC;
|
|
|
|
}
|
|
|
|
if (ssp) {
|
|
|
|
sdp->sd_share = ssp;
|
2008-11-02 23:20:27 +00:00
|
|
|
smb_share_unlock(ssp, 0);
|
2001-04-10 07:59:06 +00:00
|
|
|
sdp->sd_level = SMBL_SHARE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SMBIOC_READ: case SMBIOC_WRITE: {
|
|
|
|
struct smbioc_rw *rwrq = (struct smbioc_rw*)data;
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec iov;
|
|
|
|
|
|
|
|
if ((ssp = sdp->sd_share) == NULL)
|
|
|
|
return ENOTCONN;
|
|
|
|
iov.iov_base = rwrq->ioc_base;
|
|
|
|
iov.iov_len = rwrq->ioc_cnt;
|
|
|
|
auio.uio_iov = &iov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_offset = rwrq->ioc_offset;
|
|
|
|
auio.uio_resid = rwrq->ioc_cnt;
|
|
|
|
auio.uio_segflg = UIO_USERSPACE;
|
|
|
|
auio.uio_rw = (cmd == SMBIOC_READ) ? UIO_READ : UIO_WRITE;
|
2001-12-02 08:47:29 +00:00
|
|
|
auio.uio_td = td;
|
2001-04-10 07:59:06 +00:00
|
|
|
if (cmd == SMBIOC_READ)
|
|
|
|
error = smb_read(ssp, rwrq->ioc_fh, &auio, &scred);
|
|
|
|
else
|
|
|
|
error = smb_write(ssp, rwrq->ioc_fh, &auio, &scred);
|
|
|
|
rwrq->ioc_cnt -= auio.uio_resid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
error = ENODEV;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nsmb_dev_load(module_t mod, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
error = smb_sm_init();
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
error = smb_iod_init();
|
|
|
|
if (error) {
|
|
|
|
smb_sm_done();
|
|
|
|
break;
|
|
|
|
}
|
2008-11-03 14:23:15 +00:00
|
|
|
clone_setup(&nsmb_clones);
|
2001-04-10 07:59:06 +00:00
|
|
|
nsmb_dev_tag = EVENTHANDLER_REGISTER(dev_clone, nsmb_dev_clone, 0, 1000);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
smb_iod_done();
|
|
|
|
error = smb_sm_done();
|
2005-11-22 02:15:46 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
2001-04-10 07:59:06 +00:00
|
|
|
EVENTHANDLER_DEREGISTER(dev_clone, nsmb_dev_tag);
|
2007-07-10 09:23:10 +00:00
|
|
|
drain_dev_clone_events();
|
2008-11-03 14:23:15 +00:00
|
|
|
clone_cleanup(&nsmb_clones);
|
2007-07-10 09:23:10 +00:00
|
|
|
destroy_dev_drain(&nsmb_cdevsw);
|
2001-04-10 07:59:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEV_MODULE (dev_netsmb, nsmb_dev_load, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a file descriptor to appropriate smb_share pointer
|
|
|
|
*/
|
|
|
|
static struct file*
|
|
|
|
nsmb_getfp(struct filedesc* fdp, int fd, int flag)
|
|
|
|
{
|
|
|
|
struct file* fp;
|
|
|
|
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SLOCK(fdp);
|
2001-04-10 07:59:06 +00:00
|
|
|
if (((u_int)fd) >= fdp->fd_nfiles ||
|
|
|
|
(fp = fdp->fd_ofiles[fd]) == NULL ||
|
2002-01-13 11:58:06 +00:00
|
|
|
(fp->f_flag & flag) == 0) {
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SUNLOCK(fdp);
|
2001-04-10 07:59:06 +00:00
|
|
|
return (NULL);
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
|
|
|
fhold(fp);
|
Replace custom file descriptor array sleep lock constructed using a mutex
and flags with an sxlock. This leads to a significant and measurable
performance improvement as a result of access to shared locking for
frequent lookup operations, reduced general overhead, and reduced overhead
in the event of contention. All of these are imported for threaded
applications where simultaneous access to a shared file descriptor array
occurs frequently. Kris has reported 2x-4x transaction rate improvements
on 8-core MySQL benchmarks; smaller improvements can be expected for many
workloads as a result of reduced overhead.
- Generally eliminate the distinction between "fast" and regular
acquisisition of the filedesc lock; the plan is that they will now all
be fast. Change all locking instances to either shared or exclusive
locks.
- Correct a bug (pointed out by kib) in fdfree() where previously msleep()
was called without the mutex held; sx_sleep() is now always called with
the sxlock held exclusively.
- Universally hold the struct file lock over changes to struct file,
rather than the filedesc lock or no lock. Always update the f_ops
field last. A further memory barrier is required here in the future
(discussed with jhb).
- Improve locking and reference management in linux_at(), which fails to
properly acquire vnode references before using vnode pointers. Annotate
improper use of vn_fullpath(), which will be replaced at a future date.
In fcntl(), we conservatively acquire an exclusive lock, even though in
some cases a shared lock may be sufficient, which should be revisited.
The dropping of the filedesc lock in fdgrowtable() is no longer required
as the sxlock can be held over the sleep operation; we should consider
removing that (pointed out by attilio).
Tested by: kris
Discussed with: jhb, kris, attilio, jeff
2007-04-04 09:11:34 +00:00
|
|
|
FILEDESC_SUNLOCK(fdp);
|
2001-04-10 07:59:06 +00:00
|
|
|
return (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
smb_dev2share(int fd, int mode, struct smb_cred *scred,
|
|
|
|
struct smb_share **sspp)
|
|
|
|
{
|
|
|
|
struct file *fp;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct smb_dev *sdp;
|
|
|
|
struct smb_share *ssp;
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *dev;
|
2001-04-10 07:59:06 +00:00
|
|
|
int error;
|
|
|
|
|
2001-12-02 08:47:29 +00:00
|
|
|
fp = nsmb_getfp(scred->scr_td->td_proc->p_fd, fd, FREAD | FWRITE);
|
|
|
|
if (fp == NULL)
|
2001-04-10 07:59:06 +00:00
|
|
|
return EBADF;
|
2003-06-22 08:41:43 +00:00
|
|
|
vp = fp->f_vnode;
|
2002-01-13 11:58:06 +00:00
|
|
|
if (vp == NULL) {
|
|
|
|
fdrop(fp, curthread);
|
2001-04-10 07:59:06 +00:00
|
|
|
return EBADF;
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2004-11-10 07:16:59 +00:00
|
|
|
if (vp->v_type != VCHR) {
|
2002-01-13 11:58:06 +00:00
|
|
|
fdrop(fp, curthread);
|
2001-04-10 07:59:06 +00:00
|
|
|
return EBADF;
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2004-11-10 07:16:59 +00:00
|
|
|
dev = vp->v_rdev;
|
2001-04-10 07:59:06 +00:00
|
|
|
SMB_CHECKMINOR(dev);
|
|
|
|
ssp = sdp->sd_share;
|
2002-01-13 11:58:06 +00:00
|
|
|
if (ssp == NULL) {
|
|
|
|
fdrop(fp, curthread);
|
2001-04-10 07:59:06 +00:00
|
|
|
return ENOTCONN;
|
2002-01-13 11:58:06 +00:00
|
|
|
}
|
2001-04-10 07:59:06 +00:00
|
|
|
error = smb_share_get(ssp, LK_EXCLUSIVE, scred);
|
2002-01-13 11:58:06 +00:00
|
|
|
if (error == 0)
|
|
|
|
*sspp = ssp;
|
|
|
|
fdrop(fp, curthread);
|
|
|
|
return error;
|
2001-04-10 07:59:06 +00:00
|
|
|
}
|
|
|
|
|