smbfs_client.c revision 28162916a3f5a19f85a16b70e708bbe9235fb7c0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*
* Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
* All rights reserved.
*/
#include <sys/sysmacros.h>
#include <netsmb/smb_conn.h>
#include <netsmb/smb_subr.h>
#include <smbfs/smbfs_node.h>
#include <smbfs/smbfs_subr.h>
/*
* The following code provide zone support in order to perform an action
* for each smbfs mount in a zone. This is also where we would add
* per-zone globals and kernel threads for the smbfs module (since
* they must be terminated by the shutdown callback).
*/
struct smi_globals {
};
typedef struct smi_globals smi_globals_t;
static zone_key_t smi_list_key;
/*
* Attributes caching:
*
* Attributes are cached in the smbnode in struct vattr form.
* There is a time associated with the cached attributes (r_attrtime)
* which tells whether the attributes are valid. The time is initialized
* to the difference between current time and the modify time of the vnode
* when new attributes are cached. This allows the attributes for
* files that have changed recently to be timed out sooner than for files
* that have not changed for a long time. There are minimum and maximum
* timeout values that can be set per mount point.
*/
/*
* Validate caches by checking cached attributes. If they have timed out
* get the attributes from the server and compare mtimes. If mtimes are
* different purge all caches for this vnode.
*/
int
{
}
/*
* Purge all of the various data caches.
*/
/*ARGSUSED*/
void
{
#if 0 /* not yet: mmap support */
/*
* NFS: Purge the DNLC for this vp,
* Clear any readdir state bits,
* the readlink response cache, ...
*/
/*
* Flush the page cache.
*/
if (vn_has_cached_data(vp)) {
}
#endif /* not yet */
}
/*
* Check the attribute cache to see if the new attributes match
* those cached. If they do, the various `data' caches are
* considered to be good. Otherwise, purge the cached data.
*/
void
{
int purge_data = 0;
int purge_acl = 0;
/*
* Compare with NFS macro: CACHE_VALID
* If the mtime or size has changed,
* purge cached data.
*/
purge_data = 1;
purge_data = 1;
purge_acl = 1;
if (purge_acl) {
/* just invalidate r_secattr (XXX: OK?) */
}
if (purge_data)
}
/*
* Set attributes cache for given vnode using vnode attributes.
* From NFS: nfs_attrcache_va
*/
#if 0 /* not yet (not sure if we need this) */
void
{
}
#endif /* not yet */
/*
* Set attributes cache for given vnode using SMB fattr
* and update the attribute cache timeout.
*
* From NFS: nfs_attrcache, nfs_attrcache_va
*/
void
{
/*
* We allow v_type to change, so set that here
* (and the mode, which depends on the type).
*/
} else {
}
/*
* Delta is the number of nanoseconds that we will
* cache the attributes of the file. It is based on
* the number of nanoseconds since the last time that
* we detected a change. The assumption is that files
* that changed recently are likely to change again.
* There is a minimum and a maximum for regular files
* and for directories which is enforced though.
*
* Using the time since last change was detected
* eliminates direct comparison or calculation
* using mixed client and server times. SMBFS
* does not make any assumptions regarding the
* client and server clocks being synchronized.
*/
delta = 0;
else {
} else {
}
}
/*
* Shall we update r_size? (local notion of size)
*
* The real criteria for updating r_size should be:
* if the file has grown on the server, or if
* the client has not modified the file.
*
* Also deal with the fact that SMB presents
* directories as having size=0. Doing that
* here and leaving fa_size as returned OtW
* avoids fixing the size lots of places.
*/
#if 0 /* not yet: mmap support */
if (!vn_has_cached_data(vp) || ...)
/* XXX: See NFS page cache code. */
#endif /* not yet */
/* OK to set the size. */
}
/* NFS: np->r_flags &= ~RWRITEATTR; */
}
}
/*
* Fill in attribute from the cache.
*
* If valid, copy to *fap and return zero,
* otherwise return an error.
*
* From NFS: nfs_getattr_cache()
*/
int
{
int error;
/* cache expired */
} else {
/* cache is valid */
error = 0;
}
return (error);
}
/*
* Get attributes over-the-wire and update attributes cache
* if no error occurred in the over-the-wire operation.
* Return 0 if successful, otherwise error.
* From NFS: nfs_getattr_otw
*/
int
{
int error;
/*
* NFS uses the ACL rpc here (if smi_flags & SMI_ACL)
* With SMB, getting the ACL is a significantly more
* expensive operation, so we do that only when asked
*/
/* Shared lock for (possible) n_fid use. */
return (EINTR);
if (error) {
/* NFS had: PURGE_STALE_FH(error, vp, cr) */
/*
* Getattr failed because the object was
* removed or renamed by another client.
* Remove any cached attributes under it.
*/
}
return (error);
}
/*
* NFS: smbfs_cache_fattr(vap, fa, vap, t, cr);
* which did: fattr_to_vattr, nfs_attr_cache.
* We cache the fattr form, so just do the
* cache check and store the attributes.
*/
return (0);
}
/*
* Return either cached or remote attributes. If get remote attr
* use them to check and invalidate caches, then cache the new attributes.
*
* From NFS: nfsgetattr()
*/
int
{
int error;
/*
* If asked for UID or GID, update n_uid, n_gid.
*/
/* else leave as set in make_smbnode */
} else {
}
/*
* If we've got cached attributes, just use them;
* otherwise go to the server to get attributes,
* which will update the cache in the process.
*/
if (error)
if (error)
return (error);
/*
* Re. client's view of the file size, see:
* smbfs_attrcache_fa, smbfs_getattr_otw
*/
return (0);
}
/*
* Convert SMB over the wire attributes to vnode form.
* Returns 0 for success, error if failed (overflow, etc).
* From NFS: nattr_to_vattr()
*/
void
{
/*
* Take type, mode, uid, gid from the smbfs node,
* which has have been updated by _getattr_otw.
*/
/*
* Difference from NFS here: We cache attributes as
* reported by the server, so r_attr.fa_size is the
* server's idea of the file size. This is called
* for getattr, so we want to return the client's
* idea of the file size. NFS deals with that in
* nfsgetattr(), the equivalent of our caller.
*/
/*
* Times. Note, already converted from NT to
* Unix form (in the unmarshalling code).
*/
/*
* rdev, blksize, seq are made up.
* va_nblocks is 512 byte blocks.
*/
}
/*
* smbfattr_to_xvattr: like smbfattr_to_vattr but for
* Extensible system attributes (PSARC 2007/315)
*/
static void
{
return;
}
xoap->xoa_archive =
}
xoap->xoa_system =
}
xoap->xoa_readonly =
}
xoap->xoa_hidden =
}
}
/*
* SMB Client initialization and cleanup.
* Much of it is per-zone now.
*/
/* ARGSUSED */
static void *
{
return (smg);
}
/*
* Callback routine to tell all SMBFS mounts in the zone to stop creating new
* threads. Existing threads should exit.
*/
/* ARGSUSED */
static void
{
/*
* If we've done the shutdown work for this FS, skip.
* Once we go off the end of the list, we're done.
*/
continue;
/*
* We will do work, so not done. Get a hold on the FS.
*/
/*
* Drop lock and release FS, which may change list, then repeat.
* We're done when every mi has been done or the list is empty.
*/
goto again;
}
}
static void
{
}
/* ARGSUSED */
static void
{
/* Still waiting for VFS_FREEVFS() */
return;
}
}
/*
* Add an SMBFS mount to the per-zone list of SMBFS mounts.
*/
void
{
}
/*
* Remove an SMBFS mount from the per-zone list of SMBFS mounts.
*/
void
{
/*
* We can be called asynchronously by VFS_FREEVFS() after the zone
* smi_globals.
*/
return;
}
}
#ifdef lint
#define NEED_SMBFS_CALLBACKS 1
#endif
#ifdef NEED_SMBFS_CALLBACKS
/*
* Call-back hooks for netsmb, in case we want them.
* Apple's VFS wants them. We may not need them.
*/
/*ARGSUSED*/
{
/*
* Walk the mount list, finding all mounts
* using this share...
*/
}
/*ARGSUSED*/
{
/* no-op */
}
smb_fscb_t smbfs_cb = {
.fscb_up = smbfs_cb_nop };
#endif /* NEED_SMBFS_CALLBACKS */
/*
* SMBFS Client initialization routine. This routine should only be called
* once. It performs the following tasks:
* - Initalize all global locks
* - Call sub-initialization routines (localize access to variables)
*/
int
smbfs_clntinit(void)
{
#ifdef NEED_SMBFS_CALLBACKS
(void) smb_fscb_set(&smbfs_cb);
#endif /* NEED_SMBFS_CALLBACKS */
return (0);
}
/*
* This routine is called when the modunload is called. This will cleanup
* the previously allocated/initialized nodes.
*/
void
smbfs_clntfini(void)
{
#ifdef NEED_SMBFS_CALLBACKS
(void) smb_fscb_set(NULL);
#endif /* NEED_SMBFS_CALLBACKS */
(void) zone_key_delete(smi_list_key);
}