usr/src/uts/common/fs/nfs/nfs_export.c
changeset 806 849fb015aa25
parent 0 68f95e015346
child 1610 3436e82414c8
equal deleted inserted replaced
805:3946c495718a 806:849fb015aa25
   154 	 */
   154 	 */
   155 	for (i = 0; i < len; i++)
   155 	for (i = 0; i < len; i++)
   156 		h ^= data[i];
   156 		h ^= data[i];
   157 
   157 
   158 	return ((int)h);
   158 	return ((int)h);
   159 }
       
   160 
       
   161 /*
       
   162  * Counted byte string compare routine, optimized for file ids.
       
   163  */
       
   164 int
       
   165 nfs_fhbcmp(char *d1, char *d2, int l)
       
   166 {
       
   167 	int k;
       
   168 
       
   169 	if (l > NFS_FHMAXDATA)
       
   170 		return (1);
       
   171 
       
   172 	/*
       
   173 	 * We are always passed pointers to the data portions of
       
   174 	 * two fids, where pointers are always 2 bytes from 32 bit
       
   175 	 * alignment. If the length is also 2 bytes off word alignment,
       
   176 	 * we can do word compares, because the two bytes before the fid
       
   177 	 * data are always the length packed into a 16 bit short, so we
       
   178 	 * can safely start our comparisons at d1-2 and d2-2.
       
   179 	 * If the length is 2 bytes off word alignment, that probably
       
   180 	 * means that first two bytes are zeroes. This means that
       
   181 	 * first word in each fid, including the length are going to be
       
   182 	 * equal (we wouldn't call fhbcmp if the lengths weren't the
       
   183 	 * same). Thus it makes the most sense to start comparing the
       
   184 	 * last words of each data portion.
       
   185 	 */
       
   186 
       
   187 	if ((l & 0x3) == 2) {
       
   188 		/*
       
   189 		 * We are going move the data pointers to the
       
   190 		 * last word. Adding just the length, puts us to the
       
   191 		 * word past end of the data. So reduce length by one
       
   192 		 * word length.
       
   193 		 */
       
   194 		k = l - 4;
       
   195 		/*
       
   196 		 * Both adjusted length and the data pointer are offset two
       
   197 		 * bytes from word alignment. Adding them together gives
       
   198 		 * us word alignment.
       
   199 		 */
       
   200 		d1 += k;
       
   201 		d2 += k;
       
   202 		l += 2;
       
   203 		while (l -= 4) {
       
   204 			if (*(int *)d1 != *(int *)d2)
       
   205 				return (1);
       
   206 			d1 -= 4;
       
   207 			d2 -= 4;
       
   208 		}
       
   209 	} else {
       
   210 		while (l--) {
       
   211 			if (*d1++ != *d2++)
       
   212 				return (1);
       
   213 		}
       
   214 	}
       
   215 	return (0);
       
   216 }
   159 }
   217 
   160 
   218 /*
   161 /*
   219  * Free the memory allocated within a secinfo entry.
   162  * Free the memory allocated within a secinfo entry.
   220  */
   163  */
  1962 	if (error)
  1905 	if (error)
  1963 		return (error);
  1906 		return (error);
  1964 
  1907 
  1965 	fh->nfs_fh4_len = NFS_FH4_LEN;
  1908 	fh->nfs_fh4_len = NFS_FH4_LEN;
  1966 
  1909 
  1967 	fh_fmtp->fh4_i = exi->exi_fh;	/* copy the fhandle template */
  1910 	fh_fmtp->fh4_i.fhx_fsid = exi->exi_fh.fh_fsid;
       
  1911 	fh_fmtp->fh4_i.fhx_xlen = exi->exi_fh.fh_xlen;
       
  1912 
       
  1913 	bzero(fh_fmtp->fh4_i.fhx_data, sizeof (fh_fmtp->fh4_i.fhx_data));
       
  1914 	bzero(fh_fmtp->fh4_i.fhx_xdata, sizeof (fh_fmtp->fh4_i.fhx_xdata));
       
  1915 	bcopy(exi->exi_fh.fh_xdata, fh_fmtp->fh4_i.fhx_xdata,
       
  1916 		exi->exi_fh.fh_xlen);
       
  1917 
  1968 	fh_fmtp->fh4_len = fid.fid_len;
  1918 	fh_fmtp->fh4_len = fid.fid_len;
  1969 	ASSERT(fid.fid_len <= sizeof (fh_fmtp->fh4_data));
  1919 	ASSERT(fid.fid_len <= sizeof (fh_fmtp->fh4_data));
  1970 	bcopy(fid.fid_data, fh_fmtp->fh4_data, fid.fid_len);
  1920 	bcopy(fid.fid_data, fh_fmtp->fh4_data, fid.fid_len);
  1971 	fh_fmtp->fh4_flag = 0;
  1921 	fh_fmtp->fh4_flag = 0;
  1972 
  1922 
  2405  */
  2355  */
  2406 static struct ex_vol_rename *
  2356 static struct ex_vol_rename *
  2407 find_volrnm_fh(struct exportinfo *exi, nfs_fh4 *fh4p)
  2357 find_volrnm_fh(struct exportinfo *exi, nfs_fh4 *fh4p)
  2408 {
  2358 {
  2409 	struct ex_vol_rename *p = NULL;
  2359 	struct ex_vol_rename *p = NULL;
  2410 	fhandle_t *fhp;
  2360 	fhandle_ext_t *fhp;
  2411 
  2361 
  2412 	/* XXX shouldn't we assert &exported_lock held? */
  2362 	/* XXX shouldn't we assert &exported_lock held? */
  2413 	ASSERT(MUTEX_HELD(&exi->exi_vol_rename_lock));
  2363 	ASSERT(MUTEX_HELD(&exi->exi_vol_rename_lock));
  2414 
  2364 
  2415 	if (fh4p->nfs_fh4_len != NFS_FH4_LEN) {
  2365 	if (fh4p->nfs_fh4_len != NFS_FH4_LEN) {
  2416 		return (NULL);
  2366 		return (NULL);
  2417 	}
  2367 	}
  2418 	fhp = &((struct nfs_fh4_fmt *)fh4p->nfs_fh4_val)->fh4_i;
  2368 	fhp = &((nfs_fh4_fmt_t *)fh4p->nfs_fh4_val)->fh4_i;
  2419 	for (p = exi->exi_vol_rename; p != NULL; p = p->vrn_next) {
  2369 	for (p = exi->exi_vol_rename; p != NULL; p = p->vrn_next) {
  2420 		if (bcmp(fhp, &p->vrn_fh_fmt.fh4_i, sizeof (fhandle_t)) == 0)
  2370 		if (bcmp(fhp, &p->vrn_fh_fmt.fh4_i,
       
  2371 		    sizeof (fhandle_ext_t)) == 0)
  2421 			break;
  2372 			break;
  2422 	}
  2373 	}
  2423 	return (p);
  2374 	return (p);
  2424 }
  2375 }
  2425 
  2376