vfs.c (6b93f350e55f3f2ee071dd41109d936abfba8ebf) | vfs.c (bf4e7080aeed29354cb156a8eb5d221ab2b6a8cc) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * File operations used by nfsd. Some of these have been ripped from 4 * other parts of the kernel because they weren't exported, others 5 * are partial duplicates with added or changed functionality. 6 * 7 * Note that several functions dget() the dentry upon which they want 8 * to act, most notably those that create directory entries. Response --- 1025 unchanged lines hidden (view full) --- 1034 .len = 0, 1035 .total_len = *count, 1036 .pos = offset, 1037 .u.data = rqstp, 1038 }; 1039 ssize_t host_err; 1040 1041 trace_nfsd_read_splice(rqstp, fhp, offset, *count); | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * File operations used by nfsd. Some of these have been ripped from 4 * other parts of the kernel because they weren't exported, others 5 * are partial duplicates with added or changed functionality. 6 * 7 * Note that several functions dget() the dentry upon which they want 8 * to act, most notably those that create directory entries. Response --- 1025 unchanged lines hidden (view full) --- 1034 .len = 0, 1035 .total_len = *count, 1036 .pos = offset, 1037 .u.data = rqstp, 1038 }; 1039 ssize_t host_err; 1040 1041 trace_nfsd_read_splice(rqstp, fhp, offset, *count); |
1042 host_err = splice_direct_to_actor(file, &sd, nfsd_direct_splice_actor); | 1042 host_err = rw_verify_area(READ, file, &offset, *count); 1043 if (!host_err) 1044 host_err = splice_direct_to_actor(file, &sd, 1045 nfsd_direct_splice_actor); |
1043 return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err); 1044} 1045 1046/** 1047 * nfsd_iter_read - Perform a VFS read using an iterator 1048 * @rqstp: RPC transaction context 1049 * @fhp: file handle of file to be read 1050 * @file: opened struct file of file to be read --- 120 unchanged lines hidden (view full) --- 1171 1172 if (stable && !use_wgather) 1173 flags |= RWF_SYNC; 1174 1175 iov_iter_kvec(&iter, ITER_SOURCE, vec, vlen, *cnt); 1176 since = READ_ONCE(file->f_wb_err); 1177 if (verf) 1178 nfsd_copy_write_verifier(verf, nn); | 1046 return nfsd_finish_read(rqstp, fhp, file, offset, count, eof, host_err); 1047} 1048 1049/** 1050 * nfsd_iter_read - Perform a VFS read using an iterator 1051 * @rqstp: RPC transaction context 1052 * @fhp: file handle of file to be read 1053 * @file: opened struct file of file to be read --- 120 unchanged lines hidden (view full) --- 1174 1175 if (stable && !use_wgather) 1176 flags |= RWF_SYNC; 1177 1178 iov_iter_kvec(&iter, ITER_SOURCE, vec, vlen, *cnt); 1179 since = READ_ONCE(file->f_wb_err); 1180 if (verf) 1181 nfsd_copy_write_verifier(verf, nn); |
1179 file_start_write(file); | |
1180 host_err = vfs_iter_write(file, &iter, &pos, flags); | 1182 host_err = vfs_iter_write(file, &iter, &pos, flags); |
1181 file_end_write(file); | |
1182 if (host_err < 0) { 1183 commit_reset_write_verifier(nn, rqstp, host_err); 1184 goto out_nfserr; 1185 } 1186 *cnt = host_err; 1187 nfsd_stats_io_write_add(exp, *cnt); 1188 fsnotify_modify(file); 1189 host_err = filemap_check_wb_err(file->f_mapping, since); --- 15 unchanged lines hidden (view full) --- 1205 nfserr = nfserrno(host_err); 1206 } 1207 if (restore_flags) 1208 current_restore_flags(pflags, PF_LOCAL_THROTTLE); 1209 return nfserr; 1210} 1211 1212/** | 1183 if (host_err < 0) { 1184 commit_reset_write_verifier(nn, rqstp, host_err); 1185 goto out_nfserr; 1186 } 1187 *cnt = host_err; 1188 nfsd_stats_io_write_add(exp, *cnt); 1189 fsnotify_modify(file); 1190 host_err = filemap_check_wb_err(file->f_mapping, since); --- 15 unchanged lines hidden (view full) --- 1206 nfserr = nfserrno(host_err); 1207 } 1208 if (restore_flags) 1209 current_restore_flags(pflags, PF_LOCAL_THROTTLE); 1210 return nfserr; 1211} 1212 1213/** |
1214 * nfsd_read_splice_ok - check if spliced reading is supported 1215 * @rqstp: RPC transaction context 1216 * 1217 * Return values: 1218 * %true: nfsd_splice_read() may be used 1219 * %false: nfsd_splice_read() must not be used 1220 * 1221 * NFS READ normally uses splice to send data in-place. However the 1222 * data in cache can change after the reply's MIC is computed but 1223 * before the RPC reply is sent. To prevent the client from 1224 * rejecting the server-computed MIC in this somewhat rare case, do 1225 * not use splice with the GSS integrity and privacy services. 1226 */ 1227bool nfsd_read_splice_ok(struct svc_rqst *rqstp) 1228{ 1229 switch (svc_auth_flavor(rqstp)) { 1230 case RPC_AUTH_GSS_KRB5I: 1231 case RPC_AUTH_GSS_KRB5P: 1232 return false; 1233 } 1234 return true; 1235} 1236 1237/** |
|
1213 * nfsd_read - Read data from a file 1214 * @rqstp: RPC transaction context 1215 * @fhp: file handle of file to be read 1216 * @offset: starting byte offset 1217 * @count: IN: requested number of bytes; OUT: number of bytes read 1218 * @eof: OUT: set non-zero if operation reached the end of the file 1219 * 1220 * The caller must verify that there is enough space in @rqstp.rq_res --- 12 unchanged lines hidden (view full) --- 1233 __be32 err; 1234 1235 trace_nfsd_read_start(rqstp, fhp, offset, *count); 1236 err = nfsd_file_acquire_gc(rqstp, fhp, NFSD_MAY_READ, &nf); 1237 if (err) 1238 return err; 1239 1240 file = nf->nf_file; | 1238 * nfsd_read - Read data from a file 1239 * @rqstp: RPC transaction context 1240 * @fhp: file handle of file to be read 1241 * @offset: starting byte offset 1242 * @count: IN: requested number of bytes; OUT: number of bytes read 1243 * @eof: OUT: set non-zero if operation reached the end of the file 1244 * 1245 * The caller must verify that there is enough space in @rqstp.rq_res --- 12 unchanged lines hidden (view full) --- 1258 __be32 err; 1259 1260 trace_nfsd_read_start(rqstp, fhp, offset, *count); 1261 err = nfsd_file_acquire_gc(rqstp, fhp, NFSD_MAY_READ, &nf); 1262 if (err) 1263 return err; 1264 1265 file = nf->nf_file; |
1241 if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &rqstp->rq_flags)) | 1266 if (file->f_op->splice_read && nfsd_read_splice_ok(rqstp)) |
1242 err = nfsd_splice_read(rqstp, fhp, file, offset, count, eof); 1243 else 1244 err = nfsd_iter_read(rqstp, fhp, file, offset, count, 0, eof); 1245 1246 nfsd_file_put(nf); 1247 trace_nfsd_read_done(rqstp, fhp, offset, *count); 1248 return err; 1249} --- 551 unchanged lines hidden (view full) --- 1801retry: 1802 host_err = fh_want_write(ffhp); 1803 if (host_err) { 1804 err = nfserrno(host_err); 1805 goto out; 1806 } 1807 1808 trap = lock_rename(tdentry, fdentry); | 1267 err = nfsd_splice_read(rqstp, fhp, file, offset, count, eof); 1268 else 1269 err = nfsd_iter_read(rqstp, fhp, file, offset, count, 0, eof); 1270 1271 nfsd_file_put(nf); 1272 trace_nfsd_read_done(rqstp, fhp, offset, *count); 1273 return err; 1274} --- 551 unchanged lines hidden (view full) --- 1826retry: 1827 host_err = fh_want_write(ffhp); 1828 if (host_err) { 1829 err = nfserrno(host_err); 1830 goto out; 1831 } 1832 1833 trap = lock_rename(tdentry, fdentry); |
1834 if (IS_ERR(trap)) { 1835 err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev; 1836 goto out; 1837 } |
|
1809 err = fh_fill_pre_attrs(ffhp); 1810 if (err != nfs_ok) 1811 goto out_unlock; 1812 err = fh_fill_pre_attrs(tfhp); 1813 if (err != nfs_ok) 1814 goto out_unlock; 1815 1816 odentry = lookup_one_len(fname, fdentry, flen); --- 280 unchanged lines hidden (view full) --- 2097 2098 if (host_err) 2099 return nfserrno(host_err); 2100 2101 *offsetp = offset; 2102 return cdp->err; 2103} 2104 | 1838 err = fh_fill_pre_attrs(ffhp); 1839 if (err != nfs_ok) 1840 goto out_unlock; 1841 err = fh_fill_pre_attrs(tfhp); 1842 if (err != nfs_ok) 1843 goto out_unlock; 1844 1845 odentry = lookup_one_len(fname, fdentry, flen); --- 280 unchanged lines hidden (view full) --- 2126 2127 if (host_err) 2128 return nfserrno(host_err); 2129 2130 *offsetp = offset; 2131 return cdp->err; 2132} 2133 |
2105/* 2106 * Read entries from a directory. 2107 * The NFSv3/4 verifier we ignore for now. | 2134/** 2135 * nfsd_readdir - Read entries from a directory 2136 * @rqstp: RPC transaction context 2137 * @fhp: NFS file handle of directory to be read 2138 * @offsetp: OUT: seek offset of final entry that was read 2139 * @cdp: OUT: an eof error value 2140 * @func: entry filler actor 2141 * 2142 * This implementation ignores the NFSv3/4 verifier cookie. 2143 * 2144 * NB: normal system calls hold file->f_pos_lock when calling 2145 * ->iterate_shared and ->llseek, but nfsd_readdir() does not. 2146 * Because the struct file acquired here is not visible to other 2147 * threads, it's internal state does not need mutex protection. 2148 * 2149 * Returns nfs_ok on success, otherwise an nfsstat code is 2150 * returned. |
2108 */ 2109__be32 2110nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp, 2111 struct readdir_cd *cdp, nfsd_filldir_t func) 2112{ 2113 __be32 err; 2114 struct file *file; 2115 loff_t offset = *offsetp; --- 374 unchanged lines hidden --- | 2151 */ 2152__be32 2153nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp, 2154 struct readdir_cd *cdp, nfsd_filldir_t func) 2155{ 2156 __be32 err; 2157 struct file *file; 2158 loff_t offset = *offsetp; --- 374 unchanged lines hidden --- |