1602
CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
1603
const int netfid, const unsigned int count,
1604
const __u64 offset, unsigned int *nbytes, struct kvec *iov,
1605
int n_vec, const int long_op)
1619
cifs_writedata_release(struct kref *refcount)
1621
struct cifs_writedata *wdata = container_of(refcount,
1622
struct cifs_writedata, refcount);
1625
cifsFileInfo_put(wdata->cfile);
1631
* Write failed with a retryable error. Resend the write request. It's also
1632
* possible that the page was redirtied so re-clean the page.
1635
cifs_writev_requeue(struct cifs_writedata *wdata)
1638
struct inode *inode = wdata->cfile->dentry->d_inode;
1640
for (i = 0; i < wdata->nr_pages; i++) {
1641
lock_page(wdata->pages[i]);
1642
clear_page_dirty_for_io(wdata->pages[i]);
1646
rc = cifs_async_writev(wdata);
1647
} while (rc == -EAGAIN);
1649
for (i = 0; i < wdata->nr_pages; i++) {
1651
SetPageError(wdata->pages[i]);
1652
unlock_page(wdata->pages[i]);
1655
mapping_set_error(inode->i_mapping, rc);
1656
kref_put(&wdata->refcount, cifs_writedata_release);
1660
cifs_writev_complete(struct work_struct *work)
1662
struct cifs_writedata *wdata = container_of(work,
1663
struct cifs_writedata, work);
1664
struct inode *inode = wdata->cfile->dentry->d_inode;
1667
if (wdata->result == 0) {
1668
cifs_update_eof(CIFS_I(inode), wdata->offset, wdata->bytes);
1669
cifs_stats_bytes_written(tlink_tcon(wdata->cfile->tlink),
1671
} else if (wdata->sync_mode == WB_SYNC_ALL && wdata->result == -EAGAIN)
1672
return cifs_writev_requeue(wdata);
1674
for (i = 0; i < wdata->nr_pages; i++) {
1675
struct page *page = wdata->pages[i];
1676
if (wdata->result == -EAGAIN)
1677
__set_page_dirty_nobuffers(page);
1678
else if (wdata->result < 0)
1680
end_page_writeback(page);
1681
page_cache_release(page);
1683
if (wdata->result != -EAGAIN)
1684
mapping_set_error(inode->i_mapping, wdata->result);
1685
kref_put(&wdata->refcount, cifs_writedata_release);
1688
struct cifs_writedata *
1689
cifs_writedata_alloc(unsigned int nr_pages)
1691
struct cifs_writedata *wdata;
1693
/* this would overflow */
1694
if (nr_pages == 0) {
1695
cERROR(1, "%s: called with nr_pages == 0!", __func__);
1699
/* writedata + number of page pointers */
1700
wdata = kzalloc(sizeof(*wdata) +
1701
sizeof(struct page *) * (nr_pages - 1), GFP_NOFS);
1702
if (wdata != NULL) {
1703
INIT_WORK(&wdata->work, cifs_writev_complete);
1704
kref_init(&wdata->refcount);
1710
* Check the midState and signature on received buffer (if any), and queue the
1711
* workqueue completion task.
1714
cifs_writev_callback(struct mid_q_entry *mid)
1716
struct cifs_writedata *wdata = mid->callback_data;
1717
struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
1718
unsigned int written;
1719
WRITE_RSP *smb = (WRITE_RSP *)mid->resp_buf;
1721
switch (mid->midState) {
1722
case MID_RESPONSE_RECEIVED:
1723
wdata->result = cifs_check_receive(mid, tcon->ses->server, 0);
1724
if (wdata->result != 0)
1727
written = le16_to_cpu(smb->CountHigh);
1729
written += le16_to_cpu(smb->Count);
1731
* Mask off high 16 bits when bytes written as returned
1732
* by the server is greater than bytes requested by the
1733
* client. OS/2 servers are known to set incorrect
1736
if (written > wdata->bytes)
1739
if (written < wdata->bytes)
1740
wdata->result = -ENOSPC;
1742
wdata->bytes = written;
1744
case MID_REQUEST_SUBMITTED:
1745
case MID_RETRY_NEEDED:
1746
wdata->result = -EAGAIN;
1749
wdata->result = -EIO;
1753
queue_work(system_nrt_wq, &wdata->work);
1754
DeleteMidQEntry(mid);
1755
atomic_dec(&tcon->ses->server->inFlight);
1756
wake_up(&tcon->ses->server->request_q);
1759
/* cifs_async_writev - send an async write, and set up mid to handle result */
1761
cifs_async_writev(struct cifs_writedata *wdata)
1763
int i, rc = -EACCES;
1764
WRITE_REQ *smb = NULL;
1766
struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
1767
struct inode *inode = wdata->cfile->dentry->d_inode;
1768
struct kvec *iov = NULL;
1770
if (tcon->ses->capabilities & CAP_LARGE_FILES) {
1774
if (wdata->offset >> 32 > 0) {
1775
/* can not handle big offset for old srv */
1780
rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **)&smb);
1782
goto async_writev_out;
1784
/* 1 iov per page + 1 for header */
1785
iov = kzalloc((wdata->nr_pages + 1) * sizeof(*iov), GFP_NOFS);
1788
goto async_writev_out;
1791
smb->hdr.Pid = cpu_to_le16((__u16)wdata->cfile->pid);
1792
smb->hdr.PidHigh = cpu_to_le16((__u16)(wdata->cfile->pid >> 16));
1794
smb->AndXCommand = 0xFF; /* none */
1795
smb->Fid = wdata->cfile->netfid;
1796
smb->OffsetLow = cpu_to_le32(wdata->offset & 0xFFFFFFFF);
1798
smb->OffsetHigh = cpu_to_le32(wdata->offset >> 32);
1799
smb->Reserved = 0xFFFFFFFF;
1804
cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4);
1806
/* 4 for RFC1001 length + 1 for BCC */
1807
iov[0].iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4 + 1;
1808
iov[0].iov_base = smb;
1810
/* marshal up the pages into iov array */
1812
for (i = 0; i < wdata->nr_pages; i++) {
1813
iov[i + 1].iov_len = min(inode->i_size -
1814
page_offset(wdata->pages[i]),
1815
(loff_t)PAGE_CACHE_SIZE);
1816
iov[i + 1].iov_base = kmap(wdata->pages[i]);
1817
wdata->bytes += iov[i + 1].iov_len;
1820
cFYI(1, "async write at %llu %u bytes", wdata->offset, wdata->bytes);
1822
smb->DataLengthLow = cpu_to_le16(wdata->bytes & 0xFFFF);
1823
smb->DataLengthHigh = cpu_to_le16(wdata->bytes >> 16);
1826
inc_rfc1001_len(&smb->hdr, wdata->bytes + 1);
1827
put_bcc(wdata->bytes + 1, &smb->hdr);
1830
struct smb_com_writex_req *smbw =
1831
(struct smb_com_writex_req *)smb;
1832
inc_rfc1001_len(&smbw->hdr, wdata->bytes + 5);
1833
put_bcc(wdata->bytes + 5, &smbw->hdr);
1834
iov[0].iov_len += 4; /* pad bigger by four bytes */
1837
kref_get(&wdata->refcount);
1838
rc = cifs_call_async(tcon->ses->server, iov, wdata->nr_pages + 1,
1839
cifs_writev_callback, wdata, false);
1842
cifs_stats_inc(&tcon->num_writes);
1844
kref_put(&wdata->refcount, cifs_writedata_release);
1846
/* send is done, unmap pages */
1847
for (i = 0; i < wdata->nr_pages; i++)
1848
kunmap(wdata->pages[i]);
1851
cifs_small_buf_release(smb);
1857
CIFSSMBWrite2(const int xid, struct cifs_io_parms *io_parms,
1858
unsigned int *nbytes, struct kvec *iov, int n_vec,
1607
1861
int rc = -EACCES;
1608
1862
WRITE_REQ *pSMB = NULL;
1610
1864
int smb_hdr_len;
1611
1865
int resp_buf_type = 0;
1866
__u32 pid = io_parms->pid;
1867
__u16 netfid = io_parms->netfid;
1868
__u64 offset = io_parms->offset;
1869
struct cifs_tcon *tcon = io_parms->tcon;
1870
unsigned int count = io_parms->length;
5421
int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
5422
const int notify_subdirs, const __u16 netfid,
5423
__u32 filter, struct file *pfile, int multishot,
5424
const struct nls_table *nls_codepage)
5427
struct smb_com_transaction_change_notify_req *pSMB = NULL;
5428
struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL;
5429
struct dir_notify_req *dnotify_req;
5432
cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid);
5433
rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,
5438
pSMB->TotalParameterCount = 0 ;
5439
pSMB->TotalDataCount = 0;
5440
pSMB->MaxParameterCount = cpu_to_le32(2);
5441
/* BB find exact data count max from sess structure BB */
5442
pSMB->MaxDataCount = 0; /* same in little endian or be */
5443
/* BB VERIFY verify which is correct for above BB */
5444
pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
5445
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
5447
pSMB->MaxSetupCount = 4;
5449
pSMB->ParameterOffset = 0;
5450
pSMB->DataCount = 0;
5451
pSMB->DataOffset = 0;
5452
pSMB->SetupCount = 4; /* single byte does not need le conversion */
5453
pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE);
5454
pSMB->ParameterCount = pSMB->TotalParameterCount;
5456
pSMB->WatchTree = 1; /* one byte - no le conversion needed */
5457
pSMB->Reserved2 = 0;
5458
pSMB->CompletionFilter = cpu_to_le32(filter);
5459
pSMB->Fid = netfid; /* file handle always le */
5460
pSMB->ByteCount = 0;
5462
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
5463
(struct smb_hdr *)pSMBr, &bytes_returned,
5466
cFYI(1, "Error in Notify = %d", rc);
5468
/* Add file to outstanding requests */
5469
/* BB change to kmem cache alloc */
5470
dnotify_req = kmalloc(
5471
sizeof(struct dir_notify_req),
5474
dnotify_req->Pid = pSMB->hdr.Pid;
5475
dnotify_req->PidHigh = pSMB->hdr.PidHigh;
5476
dnotify_req->Mid = pSMB->hdr.Mid;
5477
dnotify_req->Tid = pSMB->hdr.Tid;
5478
dnotify_req->Uid = pSMB->hdr.Uid;
5479
dnotify_req->netfid = netfid;
5480
dnotify_req->pfile = pfile;
5481
dnotify_req->filter = filter;
5482
dnotify_req->multishot = multishot;
5483
spin_lock(&GlobalMid_Lock);
5484
list_add_tail(&dnotify_req->lhead,
5485
&GlobalDnotifyReqList);
5486
spin_unlock(&GlobalMid_Lock);
5490
cifs_buf_release(pSMB);
5494
5696
#ifdef CONFIG_CIFS_XATTR
5496
5698
* Do a path-based QUERY_ALL_EAS call and parse the result. This is a common
5994
#ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */
5996
* Years ago the kernel added a "dnotify" function for Samba server,
5997
* to allow network clients (such as Windows) to display updated
5998
* lists of files in directory listings automatically when
5999
* files are added by one user when another user has the
6000
* same directory open on their desktop. The Linux cifs kernel
6001
* client hooked into the kernel side of this interface for
6002
* the same reason, but ironically when the VFS moved from
6003
* "dnotify" to "inotify" it became harder to plug in Linux
6004
* network file system clients (the most obvious use case
6005
* for notify interfaces is when multiple users can update
6006
* the contents of the same directory - exactly what network
6007
* file systems can do) although the server (Samba) could
6008
* still use it. For the short term we leave the worker
6009
* function ifdeffed out (below) until inotify is fixed
6010
* in the VFS to make it easier to plug in network file
6011
* system clients. If inotify turns out to be permanently
6012
* incompatible for network fs clients, we could instead simply
6013
* expose this config flag by adding a future cifs (and smb2) notify ioctl.
6015
int CIFSSMBNotify(const int xid, struct cifs_tcon *tcon,
6016
const int notify_subdirs, const __u16 netfid,
6017
__u32 filter, struct file *pfile, int multishot,
6018
const struct nls_table *nls_codepage)
6021
struct smb_com_transaction_change_notify_req *pSMB = NULL;
6022
struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL;
6023
struct dir_notify_req *dnotify_req;
6026
cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid);
6027
rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,
6032
pSMB->TotalParameterCount = 0 ;
6033
pSMB->TotalDataCount = 0;
6034
pSMB->MaxParameterCount = cpu_to_le32(2);
6035
/* BB find exact data count max from sess structure BB */
6036
pSMB->MaxDataCount = 0; /* same in little endian or be */
6037
/* BB VERIFY verify which is correct for above BB */
6038
pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf -
6039
MAX_CIFS_HDR_SIZE) & 0xFFFFFF00);
6041
pSMB->MaxSetupCount = 4;
6043
pSMB->ParameterOffset = 0;
6044
pSMB->DataCount = 0;
6045
pSMB->DataOffset = 0;
6046
pSMB->SetupCount = 4; /* single byte does not need le conversion */
6047
pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE);
6048
pSMB->ParameterCount = pSMB->TotalParameterCount;
6050
pSMB->WatchTree = 1; /* one byte - no le conversion needed */
6051
pSMB->Reserved2 = 0;
6052
pSMB->CompletionFilter = cpu_to_le32(filter);
6053
pSMB->Fid = netfid; /* file handle always le */
6054
pSMB->ByteCount = 0;
6056
rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
6057
(struct smb_hdr *)pSMBr, &bytes_returned,
6060
cFYI(1, "Error in Notify = %d", rc);
6062
/* Add file to outstanding requests */
6063
/* BB change to kmem cache alloc */
6064
dnotify_req = kmalloc(
6065
sizeof(struct dir_notify_req),
6068
dnotify_req->Pid = pSMB->hdr.Pid;
6069
dnotify_req->PidHigh = pSMB->hdr.PidHigh;
6070
dnotify_req->Mid = pSMB->hdr.Mid;
6071
dnotify_req->Tid = pSMB->hdr.Tid;
6072
dnotify_req->Uid = pSMB->hdr.Uid;
6073
dnotify_req->netfid = netfid;
6074
dnotify_req->pfile = pfile;
6075
dnotify_req->filter = filter;
6076
dnotify_req->multishot = multishot;
6077
spin_lock(&GlobalMid_Lock);
6078
list_add_tail(&dnotify_req->lhead,
6079
&GlobalDnotifyReqList);
6080
spin_unlock(&GlobalMid_Lock);
6084
cifs_buf_release(pSMB);
6087
#endif /* was needed for dnotify, and will be needed for inotify when VFS fix */